Reply
Using php to load dynamic content into html table
Old 07-01-2004, 07:31 PM Using php to load dynamic content into html table
Novice Talker

Posts: 5
Truly a PHP novice but I was told this could be done. I have an HTML page with a table, say 2 rows by 2 columns. For the content of the cell at row 2 column 2, I want this to be dynamic data ("quote of the day") which is randomly selected each time the page is accessed.

What seems like it *should* work (but does not) is something like:

<table> etc
<tr>
<php
$quotenum = rand(1,31);
$fil = "quote" + $quotenum + ".txt";
include $fil;
<?>
</tr>

I think I'm on the right track (I hope). This is the ONLY part of this page that requires any type of PHP. Does the page need to be index.php to make it work? My web host does support PHP they tell me.

Any light you can shed would be greatly appreciated!
Jon
jarnold is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-01-2004, 08:36 PM
dbzguy's Avatar
Ultra Talker

Posts: 345
Location: Artic
<table>
<tr>
<?php
$quotenum = rand(1,31);
$fil = "quote".$quotenum.".txt";
include $fil;
?>
</tr>

that should work
__________________
W3 Dynamic Webhosting-Great Hosting, great service, GREAT PRICES!

PHP Code:
<?PHP if(ping == true) { attackuserip(); } ?>
dbzguy is offline
Reply With Quote
View Public Profile Visit dbzguy's homepage!
 
Old 07-01-2004, 09:01 PM not there yet - nothing shows up
Novice Talker

Posts: 5
The entire html code between the table tags is shown below:

<table width="80%" border="1">
<tr>
<td>row 1</td>
</tr>
<tr>
<td>row 2
<?php
$quotenum = rand(1,31);
$fil = "quote".$quotenum.".txt";
include $fil;
?>
</td>
</tr>
<tr>
<td>row 3</td>
</tr>
</table>

It simply shows 3 rows with the text "row 1" (2 & 3) in each row. Interestingly enough, with the "row 2" text in the second row, the second row doesn't even display at all!

Any other things that need to be there? This is an *.htm file. Modify something in that htaccess file? Something else? Yes, I have verified and double verified that the quote1.txt through quote31.txt files exist in the root directory of the htm file.

Jon
jarnold is offline
Reply With Quote
View Public Profile
 
Old 07-02-2004, 05:56 AM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Hi there,

The php code being used should work okay. I think you have identified the problem in that the page is saved as a .htm file.

Any pages containing php code MUST be saved with the .php extension otherwise the php code will not be parsed correctly and will therefore not show up.

Try saving the page as index.php and see if that works.

Ian.
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 07-05-2004, 05:07 PM still not working
Novice Talker

Posts: 5
Still not working. Saved file as a php file, the cell that should include the external txt file is still blank.

Might be another type of problem. I tried replacing the code so that within the php code, it simply says:

$fil = "quote1.txt";
include $fil;

and it still comes out blank. (Was trying to eliminate possible problems with spaces around the random number generated, etc. Yes, verified that the quote1.txt file does exist in the root directory.

Thoughts?
Jon
jarnold is offline
Reply With Quote
View Public Profile
 
Old 07-05-2004, 05:22 PM duh....
Novice Talker

Posts: 5
jarnold is offline
Reply With Quote
View Public Profile
 
Old 07-05-2004, 05:22 PM duh...
Novice Talker

Posts: 5
The web host I was using did NOT support PHP, I tried the same code on a different host that I have an account with, after double checking that they DO support PHP, and it worked just fine.

Thanks for the help!
Jon
jarnold is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Using php to load dynamic content into html table
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13255 seconds with 12 queries