willwill100 Posted March 8, 2006 Share Posted March 8, 2006 Evening guys, I have a problem with my code: no values from the db are outputted. Heres the code:[code]$result = mysql_query ("SELECT * FROM `competitions`") or die(mysql_error);while ($row = mysql_fetch_array($result)){$id=$row['ID'];$name=$row['name'];$races=$row['races'];$qualify=$row['qualify'];$discards=$row['discards'];$type=$row['type'];echo ("<p><b> " . $name . "</b>" . "<br><i>Races: <b>" . $races . "</b> Number to qualify: <b>" . $qualify . "</b> Discards: <b>" . $discards . "</b> Type: <b>" . $type . "</p></i>");echo (" <a href='$PHP_SELF?deleteme=$id'>Delete Competition</b></a></p> ");}[/code]output:Races: Number to qualify: Discards: Type:Any ideas?? Thanx Link to comment https://forums.phpfreaks.com/topic/4454-mysql-outpt-problem/ Share on other sites More sharing options...
kenrbnsn Posted March 8, 2006 Share Posted March 8, 2006 The code looks fine (almost*), although I would use "mysql_fetch_assoc" instead of "mysql_fetch_array".(*) In the "or die" clause, you have mysql_error, it should be mysql_error().Dumb question ... is there any data in the database?You can put a debug print statement in to see what data the script is finding:[code]<?php$q = "SELECT * FROM `competitions`";$result = mysql_query ($q) or die('Problem with query: ' . $q . '<br />' . mysql_error());while ($row = mysql_fetch_assoc($result)){ echo '<pre>' . print_r($row, true) . '</pre>'; // debug statement $id=$row['ID']; $name=$row['name']; $races=$row['races']; $qualify=$row['qualify']; $discards=$row['discards']; $type=$row['type']; echo "<p><b> " . $name . "</b>" . "<br><i>Races: <b>" . $races . "</b> Number to qualify: <b>" . $qualify . "</b> Discards: <b>" . $discards . "</b> Type: <b>" . $type . "</p></i>";echo " <a href='$PHP_SELF?deleteme=$id'>Delete Competition</b></a></p>";}?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/4454-mysql-outpt-problem/#findComment-15464 Share on other sites More sharing options...
willwill100 Posted March 8, 2006 Author Share Posted March 8, 2006 i did what you suggested to no avail (yes there is something in the database lol!)But then i used the code you gave me and i got this result (it's the top half you're interessted in):[img src=\"http://i7.photobucket.com/albums/y254/willwill100/comp.gif\" border=\"0\" alt=\"IPB Image\" /]where do i go from here? Link to comment https://forums.phpfreaks.com/topic/4454-mysql-outpt-problem/#findComment-15476 Share on other sites More sharing options...
keeB Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352935:date=Mar 8 2006, 06:55 PM:name=WillWill)--][div class=\'quotetop\']QUOTE(WillWill @ Mar 8 2006, 06:55 PM) [snapback]352935[/snapback][/div][div class=\'quotemain\'][!--quotec--]where do i go from here?[/quote]Looks like your data is getting associaed incorrectly, which means what you have in quotes is wrong :DNotice how the debug information has "[ Name ] => Topper Main Points" yo're referring to it as[code]$name=$row['name'];[/code]when it should be[code]$name=$row['Name'];[/code]yes, case does matter. I hope this helped! Link to comment https://forums.phpfreaks.com/topic/4454-mysql-outpt-problem/#findComment-15504 Share on other sites More sharing options...
willwill100 Posted March 8, 2006 Author Share Posted March 8, 2006 thanx thats solved the problem! Link to comment https://forums.phpfreaks.com/topic/4454-mysql-outpt-problem/#findComment-15585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.