overlordofevil Posted December 17, 2009 Share Posted December 17, 2009 Hello All, So I am a bit confused about something and cant figure out how to fix it.. I am working with a db of user data. What I am trying to do is pull up the info and collecting data from other tables as well. The issue I am having is when I get the info based on the group id all the basic info will come up and the entire list of user data I want to get comes up no problem. When I try to add in the other code to get the info from other tables that i want it just stops at the first record. So when I do the first step of gathering the data i want and displaying it on the screen, here is the code. <html> <body> <?php include ("misc.inc"); include ("functions.inc"); include ("charfun.inc"); $query = "SELECT * FROM characters INNER JOIN id ON characters.id = id.id where id.chid='$chid'"; echo "<table>"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<tr><td>"; extract($row); $cname = "$firstname $lastname"; $uid = $id; $classid=$clas; $armor = getarmor($cid, $classid); $gobbies = getgoblinpoints($uid); $racename = getracename($race); $classname = getclassname($clas); $pname= getplayersname($uid); $chname = getchaptername($uid); $notes=getnotes($cid); $email = getemail($uid); echo "<table width=100% border='1'> <tr><td align ='center'> <table><tr><td><big><big><big><b>NERO $chname Character Sheet</b></big></big></big></td></tr></table> </td></tr> <tr><td align ='center'> <table><tr> <TD ALIGN='right'><small><b>Player's Name: </b></td> <TD ALIGN='left'><small>$pname</td> <TD ALIGN='right'><small><b>Member's ID: </b></td> <TD ALIGN='left'><small>$uid</td> <TD ALIGN='right'><small><b>E-Mail Address: </b></td> <TD ALIGN='left'><small>$email</td> <TD ALIGN='right'><small><b>Goblin Points: </b></td> <TD ALIGN='left'><small>$gobbies</td> <TD ALIGN='right'><small><b></b></td> <TD ALIGN='left'><small></td> </tr></table> </td></tr> <tr><td align ='center'> <table><tr> <TD ALIGN='right'><small><b>Character's Name: </b></small></td><TD ALIGN='left'><small><b>$cname</b></small></td> <TD ALIGN='right'><small><b></b></td> <TD ALIGN='left'><small></td> <TD ALIGN='right'><small><b></b></td> <TD ALIGN='left'><small></td> </tr><tr> <TD ALIGN='right'><small><b>Race: </td><TD ALIGN='left'><small>$racename, $subrace</td> <TD ALIGN='right'><small><b>Build: </td><TD ALIGN='left'><small>$build</td> <TD ALIGN='right'><b><small>Body: </td><TD ALIGN='left'><small>$body</td> </tr><tr> <TD ALIGN='right'><b><small>Class: </td><TD ALIGN='left'><small>$classname</td> <TD ALIGN='right'><b><small>Free Build: </td><TD ALIGN='left'><small>$freebuild</td> <TD ALIGN='right'><b><small>XP: </td><TD ALIGN='left'><small>$xp</td> </tr><tr> <TD ALIGN='right'><small><b>Level: </td> <TD ALIGN='left'><small>$level</td> <TD ALIGN='right'><b><small>Max Armor: </td> <TD ALIGN='left'><small>$armor</td> <TD ALIGN='right'><b><small>Deaths: </td> <TD ALIGN='left'><small>$deaths</td> <td></td> </tr></table>"; //Place holder for other code. echo" </td></tr> </table> </td></tr>"; } echo "</table>"; ?> </body> </html> So with the above code it does the loop and pulls all the info as needed. Now If I add the following in to the code it just stops on the first record. <?php // code goes where the place holder line is at. <tr><td align ='center'> <table><tr> <td align='center'> <table width=100% align='center'><tr><td align = 'center'><big><b>Fight/Weapon Skills</b></big></td></tr></table> </td> </tr><tr> <td> <table width=100% align='center'><tr><td align = 'center'>"; echo "<table><tr><td align = 'center'><small><b>Weapons and Armor</b></small></td></tr></table>"; $query = "SELECT * FROM skill1 where cid = '$cid' and type = '3' ORDER BY skillID"; $result = mysql_query($query) or die (" Line 1 Query failed due to: ".mysql_error()); echo "<table>"; while ($row = mysql_fetch_array($result)) { extract($row); echo "<tr> <td align = 'center'><small>$skillName</small></td> </tr>"; } echo"</table>"; echo"</td></tr></table> </td> </tr></table> </td></tr> I have more code but the loop stops at anyone them so i just included this one to see if someone could explain why it would happen and what i am doing wrong with the scripts to pull the info. I know the layout might look off but this is not complete code I am just cutting and pasting what works and what happens when I add in the new code. Any suggestions would be appreciated. Thanks Bill Quote Link to comment https://forums.phpfreaks.com/topic/185508-pulling-a-list-of-data-and-it-stops-on-first-record/ Share on other sites More sharing options...
overlordofevil Posted December 18, 2009 Author Share Posted December 18, 2009 Ok figured it out.. seemed that because the query variables were the same ($query, $result, $row) it would knock out my initial request now it works with no problems... Quote Link to comment https://forums.phpfreaks.com/topic/185508-pulling-a-list-of-data-and-it-stops-on-first-record/#findComment-980172 Share on other sites More sharing options...
PFMaBiSmAd Posted December 18, 2009 Share Posted December 18, 2009 You are re-using the $result variable inside the loop and when the code goes back to the first while() loop, the result resource in $result is that of the inner loop, not that of the outer loop. Be careful when re-using variables. Quote Link to comment https://forums.phpfreaks.com/topic/185508-pulling-a-list-of-data-and-it-stops-on-first-record/#findComment-980181 Share on other sites More sharing options...
monkeytooth Posted December 18, 2009 Share Posted December 18, 2009 In short.. you have a loop in a loop.. One is breaking the other. Since you already have a cycle running in a loop why not match the second query to pull row specific data out from the other table based on the variable its using to pull the data already. It will do that on a row to row basis with each cycle of the loop. To break down what I am saying.. Run each loop independantly in a seperate file, notice there outputs. What your doing with your code currently it trying is tell the first one to do what its going to display running it alone, then while thats going on tell it to do the samething the second one does alone within it. Fix: your going to have to restyle your second query to work with the results of the first one. Pull the data on a row to row basis. Then display it the way you want based on that. Quote Link to comment https://forums.phpfreaks.com/topic/185508-pulling-a-list-of-data-and-it-stops-on-first-record/#findComment-980190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.