BPWheeler Posted May 19, 2007 Share Posted May 19, 2007 I don't know what i'm asking for so i haven't searched the forumns - appologies! I have the following: <table width="100%"> <tr align="center" bgcolor="#c0c0c0"> <td width="10%">Request Number</td> <td width="20%">Product</td> <td width="50%">Title</td> <td width="10%">Created Date</td> <td width="10%">View?</td> </tr> <?PHP for($i = 1; $i < 11; ++$i) { echo('<tr>'); echo('<td align="center">Number $i</td>'); echo('<td>Product $i</td>'); echo('<td>Title $i</td>'); echo('<td align="center">Date $i</td>'); echo('<td align="center"><input type="submit" value="View" /></td>'); echo('</tr>'); } ?> </table> Now if i put that into a .php file and look at it through internet explorer it works fine. But if i put it into a database along with the rest of the content of my website, the website code picks up the page id, hits the db and echo's it out - this seems to work for html tags, but not php? i get this instead: ); echo(' Number $i '); echo(' Product $i '); echo(' Title $i '); echo(' Date $i '); echo(' '); echo(' '); } ?> I guess at the point i echo out the content the processing of php has already been done - what can i do? Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/ Share on other sites More sharing options...
zack45668 Posted May 19, 2007 Share Posted May 19, 2007 Ok... try this... <table width="100%"> <tr align="center" bgcolor="#c0c0c0"> <td width="10%">Request Number</td> <td width="20%">Product</td> <td width="50%">Title</td> <td width="10%">Created Date</td> <td width="10%">View?</td> </tr> <?php for($i = 1; $i < 11; ++$i) { echo '<tr>'; echo '<td align="center">Number $i</td>'; echo '<td>Product $i</td>'; echo '<td>Title $i</td>'; echo '<td align="center">Date $i</td>'; echo '<td align="center"><input type="submit" value="View" /></td>'; echo '</tr>'; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257175 Share on other sites More sharing options...
BPWheeler Posted May 19, 2007 Author Share Posted May 19, 2007 Thanks - Thats corrected the output so the table is drawn correctly but the 10 rows of example data havent been drawn. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257189 Share on other sites More sharing options...
dark22horse Posted May 19, 2007 Share Posted May 19, 2007 Have you connected to the database before you are trying to call data from it. I can not see that you have done that. Also you dont actually have any variable defined apart from $i, which is just counting. Connect.php <? //config for mysql $database_dbname = "Put your database name here"; $database_server = "localhost"; $database_username = "root"; $database_password = ""; $dbconn = mysql_connect($database_server, $database_username, $database_password); if($table = mysql_select_db($database_dbname, $dbconn)) { echo "<H2>select table ok!</H2>"; } else { echo "<h2>error selecting</h2>"; } ?> Then you need to call it in your function <table width="100%"> <tr align="center" bgcolor="#c0c0c0"> <td width="10%">Request Number</td> <td width="20%">Product</td> <td width="50%">Title</td> <td width="10%">Created Date</td> <td width="10%">View?</td> </tr> <?php require_once("connect.php"); for($i = 1; $i < 11; ++$i) { echo '<tr>'; echo '<td align="center">Number $i</td>'; echo '<td>Product $i</td>'; echo '<td>Title $i</td>'; echo '<td align="center">Date $i</td>'; echo '<td align="center"><input type="submit" value="View" /></td>'; echo '</tr>'; } ?> </table> That will get you connecting to the database. Now you need to fetch the information. Can you post the table structure? Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257195 Share on other sites More sharing options...
BPWheeler Posted May 19, 2007 Author Share Posted May 19, 2007 The whole of the website is working and pulling data from the database for html tags (i.e. basic content) theres no problem with that at all. The bit i'm doing at the moment is just popping in placeholders so i can then go and have a look at the layout. Then once happy i'm going to go and hit the database and pull the real data back. But at the moment the table won't draw corretcly with the dummy 10 rows. Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257197 Share on other sites More sharing options...
BPWheeler Posted May 19, 2007 Author Share Posted May 19, 2007 The source of the website is <table width="100%"> <tr align="center" bgcolor="#c0c0c0"> <td width="10%">Request Number</td> <td width="20%">Product</td> <td width="50%">Title</td> <td width="10%">Created Date</td> <td width="10%">View?</td> </tr> <?php for($i = 1; $i < 11; $i++) { echo '<tr>'; echo '<td align="center">Number $i</td>'; echo '<td>Product $i</td>'; echo '<td>Title $i</td>'; echo '<td align="center">Date $i</td>'; echo '<td align="center"><input type="submit" value="View" /></td>'; echo '</tr>'; } ?> </table> after being sent to the client. so why is the output of the script not being processed? Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257214 Share on other sites More sharing options...
dark22horse Posted May 19, 2007 Share Posted May 19, 2007 Im not sure I get what you mean. I have run this code on my server and it comes out fine, check below. Im unsure what you are doing, or are trying to do. Are you running a server on your computer? because if you are running a php script without a server it will not run! hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257260 Share on other sites More sharing options...
BPWheeler Posted May 20, 2007 Author Share Posted May 20, 2007 I'm now pretty sure of my problem: What i'm trying to echo is PHP (<?PHP ..... ?>) which you can't do. I have other code that hits the db and echo's content. If the content i'm trying to echo is: <table width="100%"> <tr align="center" bgcolor="#c0c0c0"> <td width="10%">Request Number</td> <td width="20%">Product</td> <td width="50%">Title</td> <td width="10%">Created Date</td> <td width="10%">View?</td> </tr> <?php for($i = 1; $i < 11; $i++) { echo '<tr>'; echo '<td align="center">Number $i</td>'; echo '<td>Product $i</td>'; echo '<td>Title $i</td>'; echo '<td align="center">Date $i</td>'; echo '<td align="center"><input type="submit" value="View" /></td>'; echo '</tr>'; } ?> </table> then the bits within the <?PHP ?> tags won't work. So how do i get around that? having content in the db which is PHP and processing that to include in the echo. Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257376 Share on other sites More sharing options...
chigley Posted May 20, 2007 Share Posted May 20, 2007 If you're trying to select the information for the table from a mySQL database, you need to tell us what the fields/tables are called. I'd scrap the for() and use a while() loop to display the table; but we can't help without database information! Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257393 Share on other sites More sharing options...
BPWheeler Posted May 20, 2007 Author Share Posted May 20, 2007 http://www.zimmertech.com/tutorials/php/51/evaluate-php-code-from-mysql.php Taken me all this time to find a nice concise answer. The answer is: eval('?>' . $content . '<?php '); Quote Link to comment https://forums.phpfreaks.com/topic/52138-help-with-php-output-from-database-please/#findComment-257399 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.