Jump to content

mysql outpt problem


willwill100

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

[!--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 :D

Notice 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.