LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-25-2004, 05:04 AM   #1
manikantha
Member
 
Registered: Sep 2004
Location: Guntur,India
Distribution: FC3 - 64-Bit
Posts: 56

Rep: Reputation: 21
"How to Generate PHP files Dynamically"


Hi,

Can ne one tell me how to generate PHP files dynamically.
 
Old 09-25-2004, 05:16 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
What do you mean, create new php files on the disk automatically ?
 
Old 09-25-2004, 05:23 AM   #3
manikantha
Member
 
Registered: Sep 2004
Location: Guntur,India
Distribution: FC3 - 64-Bit
Posts: 56

Original Poster
Rep: Reputation: 21
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
}
?>
 
Old 09-25-2004, 07:56 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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 ?
 
Old 09-26-2004, 10:00 AM   #5
manikantha
Member
 
Registered: Sep 2004
Location: Guntur,India
Distribution: FC3 - 64-Bit
Posts: 56

Original Poster
Rep: Reputation: 21
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....
 
Old 09-26-2004, 01:00 PM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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>
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
add "Artist" and "Album Title" to mp3 files powah Linux - Software 2 04-05-2005 04:04 AM
why iam getting problems like "...too many files opened" or "segmentation fault" naren_0101bits Linux - Newbie 2 07-19-2004 01:20 PM
"X-MS" cant open because "x-Multimedia System" cant access files at "smb&qu ponchy5 Linux - Networking 0 03-30-2004 12:18 AM
"ifcfg-ethx" and "network-functions" files peok Linux - Networking 12 08-13-2003 07:06 PM
php ide with "break" and "trace" Kayaker Programming 3 04-25-2003 03:52 PM


All times are GMT -5. The time now is 07:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration