Guest Posted April 24, 2007 Share Posted April 24, 2007 I'm currently writing a php script which gets the a list of articles with certain properties, and places them in a table. It also can order them by those properties. All is good except for the fact that it there seems to be something wrong with my $row when about to extract. No information was coming up in the table, and I thought maybe it was because I didn't write the variable properly or something, but after testing it I found out that it was something with the $row. Here is the code: $query = "SELECT * FROM Quests ORDER BY $listingDisplay"; $result = mysql_query($query) or die (mysql_error () . " The query was:" . $query); $row = mysql_fetch_assoc($result); And: while ($row = mysql_fetch_assoc($result)) { extract($row); echo "<tr>\n <td><a style=font-weight: bold; href='node/\$ID'>$questName</a href></td>\n <td>$members</td>\n <td>$questDifficulty</td>\n <td>$questLength</td></tr>\n"; } echo "</table></center> \n"; It seems to be that the while ($row = mysql_fetch_assoc($result)) doesn't ever run, meaning that for some reason my $row doesn't equal what I already defined it as =S. The fields in the table are questName, members, questDifficulty and questLength. I'm only a novice at PHP, but I'm pretty sure its right, and I'm stumped at the moment. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/48428-extraction-problems/ Share on other sites More sharing options...
dsaba Posted April 24, 2007 Share Posted April 24, 2007 <?php $query = "SELECT * FROM Quests ORDER BY $listingDisplay"; $result = mysql_query($query) or die (mysql_error () . " The query was:" . $query); while ($row = mysql_fetch_assoc($result)) { extract($row); echo "<tr>\n <td><a style=font-weight: bold; href='node/\$ID'>$questName</a href></td>\n <td>$members</td>\n <td>$questDifficulty</td>\n <td>$questLength</td></tr>\n"; } echo "</table></center> \n"; ?> that should work Link to comment https://forums.phpfreaks.com/topic/48428-extraction-problems/#findComment-236808 Share on other sites More sharing options...
Guest Posted April 24, 2007 Share Posted April 24, 2007 http://sickmate.110mb.com/quests.php ^^ Thats the webserver I'm using to test it, but as you can see nothing comes up =S. And I have added some data into the tables, so if its connecting to the database and executing the query, I dont see why it doesn't come up =\. If need be I can provide the whole PHP file. Link to comment https://forums.phpfreaks.com/topic/48428-extraction-problems/#findComment-236838 Share on other sites More sharing options...
dsaba Posted April 24, 2007 Share Posted April 24, 2007 before you had: $query = "SELECT * FROM Quests ORDER BY $listingDisplay"; $result = mysql_query($query) or die (mysql_error () . " The query was:" . $query); $row = mysql_fetch_assoc($result); while ($row = mysql_fetch_assoc($result)) I took out the $row variable before the while statement begins, you do not need it, and it has causes problems I hope you noticed that, try this new code: <?php $query = "SELECT * FROM Quests ORDER BY $listingDisplay"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { $questName = $row['questName']; $members = $row['members']; $questDifficulty = $row['questDifficulty']; $questLength = $row['questLength']; echo "<tr>\n <td><a style=font-weight: bold; href='node/\$ID'>".$questName."</a href></td>\n <td>".$members."</td>\n <td>".$questDifficulty."</td>\n <td>".$questLength."</td></tr>\n"; } echo "</table></center> \n"; ?> make note that I am referencing the values of each field like this: $questName = $row['questName']; // your fieldname is questName here, i guessed the fieldname In your link you have Labels at the top of your table, those do not loop, I did not see those here in the code you posted, my code that I supplied will not show any labels at the top of the table, only the looping TR part -hope that helps Link to comment https://forums.phpfreaks.com/topic/48428-extraction-problems/#findComment-237467 Share on other sites More sharing options...
Guest Posted April 25, 2007 Share Posted April 25, 2007 Ah I see. It works now, thank you very much . Link to comment https://forums.phpfreaks.com/topic/48428-extraction-problems/#findComment-237676 Share on other sites More sharing options...
dsaba Posted April 25, 2007 Share Posted April 25, 2007 no problem, I have received a lot of help here from this commmunity so I try to give back when I can use the "Topic Solved" if the topic is solved Link to comment https://forums.phpfreaks.com/topic/48428-extraction-problems/#findComment-238152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.