Custer Posted July 22, 2007 Share Posted July 22, 2007 Yep, I'm back with another slight problem, data's showing up and everything perfectly (been able to use my last help topic to really get a lot of coding done). But my problem is, it's displaying the data in the table correctly, but it's making extra rows. I'm displaying the amount and name of buildings that a person has. Right now, there is only one building/user and that's not a problem, it says "1 Papermill" or 1 Lumbercamp or 1 whatever they have. But then it's making extra rows with 1 for the amount and just nothing in the name. //Begin Buildings Table $ubuildings = ("SELECT * FROM user_buildings WHERE user_id = $userid "); $resultb = mysql_query( $ubuildings ) or die(mysql_error()); $infob = mysql_fetch_assoc( $resultb ); $buildingid = $infob['building_id']; $buildings = ("SELECT * FROM buildings WHERE building_id = $buildingid "); $resultc = mysql_query( $buildings ) or die(mysql_error()); echo ("<center><h1 style='font-size:150%'>Buildings</h1><table border='1' bordercolor='black'></center>"); while($infoc = mysql_fetch_assoc( $resultc )) { echo "<tr>"; echo "<td>".$infob['amount'] . " ".$infoc['name'] . " </td> "; } echo "</font>"; echo "</table>"; I checked the database, and every user (only 3 test accounts) have but one building, so I don't understand why I'm getting these extra rows with 1. Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 22, 2007 Share Posted July 22, 2007 <?php while($infoc = mysql_fetch_assoc( $resultc )) { if(($infob['amount'] != '') && ($infoc['name'] != '')) { echo "<tr>"; echo "<td>".$infob['amount'] . " ".$infoc['name'] . " </td> "; } } echo "</font>"; echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 22, 2007 Share Posted July 22, 2007 Is there only one entry for each building_id? That is actually the query which you are displaying information from, so i would suggest the problem lies there. Quote Link to comment Share on other sites More sharing options...
Custer Posted July 22, 2007 Author Share Posted July 22, 2007 No, it's not that. In my user_buildings, I have id, user_id, building_id, and amount. So I'm matching up my user_id to the person who's logged in, and matching up that building_id with that in the buildings table so I can access the name, and then printing the amount. So there is one entry per building_id per user, and I shouldn't be getting repeats... Quote Link to comment Share on other sites More sharing options...
Custer Posted July 23, 2007 Author Share Posted July 23, 2007 Anybody have any suggesions? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 23, 2007 Share Posted July 23, 2007 give us the fields of that table??? Quote Link to comment Share on other sites More sharing options...
Custer Posted July 23, 2007 Author Share Posted July 23, 2007 Okay, on my user_buildings: user_id, building_id, and amount For buildings: building_id, name, (the rest is not needed) cost_type, cost_restype, and cost_amount. I performed a print_r on my selection on the user_buildings and everything was fine..so I just can't understand why it's printing multiple rows. Quote Link to comment 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.