"How to Generate PHP files Dynamically"
Hi,
Can ne one tell me how to generate PHP files dynamically. |
What do you mean, create new php files on the disk automatically ?
|
No,
I have doubt in this code... <?php session_start(); if($_SESSION['flag']=='0') /* Previously I have set $_SESSION['flag']as 0 in some file and I am calling this file from that file*/ { $i='0'; $assno=$_POST['assignno']; $totques=$_POST["totques"]; session_register("assno"); session_register("totques"); session_register("i"); $_SESSION["i"]=$i; $_SESSION["assno"]=$assno; $_SESSION["totques"]=$totques; $qno=$_POST["qno"]; $link=mysql_connect('localhost')or die("unable to connect"); $db=mysql_select_db("test",$link)or die("Unable to Select"); $ass="assignment".$assno; $query1="CREATE TABLE assignments(assignno VARCHAR(20) NOT NULL,qno VARCHAR(20) NOT NULL,subqno VARCHAR(20) NOT NULL,qtext VARCHAR(200),startdate date,start time,enddate date,endtime time,timeinterval time,maxsub int(4),nooverwrites int(2),ncurrsub int(3),ntestcases int(2),marks int(3) ,PRIMARY KEY(assignno,qno,subqno));"; mysql_query($query1); $query2="INSERT INTO assignments(assignno) VALUES('$ass')"; $resource=mysql_query($query2); $_SESSION['flag']='1'; } else { /* I have to store the values entered by the user into some database */ } ?> <?php for(;$_SESSION["i"]<$_SESSION['totques'];$_SESSION["i"]=$_SESSION["i"]+1) /* Can I give like this */ /*Actually I want to generate the pages the $_SESSION["totques"] no;of times */ { ?> <html> <body bgcolor=lightgrey> <br> <br> <br> <form action='configure.php' method='post'> Section Number <input type='text' name='secno'> <br> Question Number <input type='text' name='quesno'> <br> Question <br><textarea cols=30 rows=10 wrap="soft"></textarea> <br> Marks <input type='text' name='Marks'> <br> Start Time <input type='textarea' name='st_time'> <br> End Time <input type='textarea' name='end_time'> <br> Sample Input <br><textarea name=samin cols=30 rows=10 wrap="soft"></textarea> <br> Sample Output <br><textarea name='samout' cols=30 rows=10 wrap="soft"></textarea> <br> Number of OverWrites <input type='text' name='overwrites'> <br> <center><input type='submit' value='Submit'> <input type='reset' value='Reset'></center> </form> </body> </html> <?php } ?> |
You could replace :
<?php for(;$_SESSION["i"]<$_SESSION['totques'];$_SESSION["i"]=$_SESSION["i"]+1) { ?> <!-- html code --> <?php } ?> with : <?php for($i = $_SESSION["i"]; $i < $_SESSION['totques']; $i++) : ?> <!-- html code --> <?php endfor; ?> That won't fix anything, but it is more readable to me. Also I don't get what you expect by looping the html part... As the result will be in one page, so why open and close <html> markup in each loop iteration ? |
Hi Cedrik,
My $_SESSION['totques'] is the number of questions.... For each question I want a fresh page. For the first time the html page is displayed .. and if I click the submit button I should get the second page and like so on until we get $_SESSION['totques'] question pages.... |
try :
PHP Code:
|
All times are GMT -5. The time now is 11:32 AM. |