bluethundr Posted October 31, 2009 Share Posted October 31, 2009 Hi guys, I am writing a simple php script to access a MySQL database to retrieve info from some tables and format them with html. Simple right? Well for some reason there is a bug in the code where all it does is print '<r>' over and over again in an infinite loop. I have stared at this code till my eyes bled. Can I get some assistance? <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html"; charset=iso-8859-1"> <title>Wines</title> </head> <body> <?php require 'db.inc'; // Show the wines in the HTML <table> function displayWines($result) { print "<h1>Our Wines</h1>\n"; // Start a table, with column header print "\n<table>\n<tr>\n" . "\n\t<th>Wine ID</th>" . "\n\t<th>Wine Name</th>" . "\n\t<th>Type</th>" . "\n\t<th>Year</th>" . "\n\t<th>Winery ID</th>" . "\n\t<th>Description</th>" . "\n</tr>"; // Until there are no rows in the result set, fetch a row into // the $row array and ... while ($row = @ mysql_fetch_row($result)) { while ($row = @ mysql_fetch_row($result)) { // ... start a TABLE row ... print "\n<tr>"; // ... and print out each of the attributes in that row as a // separate TD (Table Data). foreach($row as $data) print "\n\t<td> {$data} </td>"; // Finish the row print "\n<\tr>"; } // Then, finish the table print "\n</table>\n"; } } $query = "SELECT * FROM wine"; // Connect to the MySQL server if (!($connection = @ mysql_connect($hostname, $username, $password))) die("Cannot connect"); if (!(mysql_select_db($databaseName, $connection))) showerror(); // Run the query on the connection if (!($result = @ mysql_query ($query, $connection))) showerror(); // Display the results displayWines($result); ?> </body> </html> There is an .inc file that has all the login information for the db that appears to be working. Thanks! Link to comment https://forums.phpfreaks.com/topic/179750-solved-elusive-bug-in-code/ Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 while ($row = @ mysql_fetch_row($result)) { while ($row = @ mysql_fetch_row($result)) { Ouch! Why are you doing this? Link to comment https://forums.phpfreaks.com/topic/179750-solved-elusive-bug-in-code/#findComment-948364 Share on other sites More sharing options...
bluethundr Posted October 31, 2009 Author Share Posted October 31, 2009 while ($row = @ mysql_fetch_row($result)) { while ($row = @ mysql_fetch_row($result)) { Ouch! Why are you doing this? Cool! thanks! That was it. Just a simple script to access a MySQL db and generate html based on output to html. Unless I am misunderstanding your question. So the real "why" is that I am just wrapping my head around this stuff. Cheers! Link to comment https://forums.phpfreaks.com/topic/179750-solved-elusive-bug-in-code/#findComment-948365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.