Jump to content


Photo

mysql outpt problem


  • Please log in to reply
4 replies to this topic

#1 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 March 2006 - 05:25 PM

Evening guys, I have a problem with my code: no values from the db are outputted. Heres the 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> ");

}

output:

Races: Number to qualify: Discards: Type:

Any ideas?? Thanx

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 March 2006 - 06:05 PM

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:
<?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>";
}
?>

Ken

#3 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 March 2006 - 06:55 PM

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?


#4 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 08 March 2006 - 08:23 PM

[!--quoteo(post=352935:date=Mar 8 2006, 06:55 PM:name=WillWill)--][div class=\'quotetop\']QUOTE(WillWill @ Mar 8 2006, 06:55 PM) View Post[/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 :D

Notice how the debug information has "[ Name ] => Topper Main Points" yo're referring to it as

$name=$row['name'];

when it should be

$name=$row['Name'];

yes, case does matter. I hope this helped!



Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#5 willwill100

willwill100
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 08 March 2006 - 10:49 PM

thanx thats solved the problem!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users