Jump to content

Repeating problem....


Custer

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/61290-repeating-problem/
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/61290-repeating-problem/#findComment-304969
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/61290-repeating-problem/#findComment-305115
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.