LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   "How to Generate PHP files Dynamically" (https://www.linuxquestions.org/questions/programming-9/how-to-generate-php-files-dynamically-235015/)

manikantha 09-25-2004 04:04 AM

"How to Generate PHP files Dynamically"
 
Hi,

Can ne one tell me how to generate PHP files dynamically.

Cedrik 09-25-2004 04:16 AM

What do you mean, create new php files on the disk automatically ?

manikantha 09-25-2004 04:23 AM

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&nbsp;<input type='text' name='secno'>
<br>
Question Number&nbsp;<input type='text' name='quesno'>
<br>
Question&nbsp;<br><textarea cols=30 rows=10 wrap="soft"></textarea>
<br>
Marks&nbsp;<input type='text' name='Marks'>
<br>
Start Time&nbsp;<input type='textarea' name='st_time'>
<br>
End Time&nbsp;<input type='textarea' name='end_time'>
<br>
Sample Input&nbsp;<br><textarea name=samin cols=30 rows=10 wrap="soft"></textarea>
<br>
Sample Output&nbsp;<br><textarea name='samout' cols=30 rows=10 wrap="soft"></textarea>
<br>
Number of OverWrites&nbsp;&nbsp;<input type='text' name='overwrites'>
<br>
<center><input type='submit' value='Submit'>
<input type='reset' value='Reset'></center>
</form>
</body>
</html>
<?php
}
?>

Cedrik 09-25-2004 06:56 AM

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 ?

manikantha 09-26-2004 09:00 AM

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....

Cedrik 09-26-2004 12:00 PM

try :
PHP Code:

<?php
session_start
();
// init counter
if(! session_is_registered("count") ) {
    
session_register"count" );
    
$_SESSION["count"] = 0;
}
...
...
...
if( 
$_SESSION["count"] == $_SESSION["totques"] ) {
    echo 
"last page";

} else {
    
$_SESSION["count"] ++;
}
?>
<html>
...
</html>



All times are GMT -5. The time now is 11:32 AM.