DEVILofDARKNESS Posted August 13, 2009 Share Posted August 13, 2009 In the following code only one row is showen, although I know their are at least 2 rows that should be displayed. this is the database: region_id nation_id ammount 1--------------17----------5 2--------------18----------2 3--------------17----------2 (Like you can see If I run the code with nation_id 17 I should receive 2 outputs...) $query = "SELECT * FROM regions WHERE nation_id='$nationid'"; $result = mysql_query($query); $numrows = mysql_num_rows($result); if($numrows > 0){ while($region = mysql_fetch_array($result)){ $query2 = "SELECT * FROM region_weapons INNER JOIN weapons ON region_weapons.weapon_id = weapons.weapon_id WHERE region_id = '" . $region['region_id'] . "'"; $result2 = mysql_query($query2); $YW = mysql_fetch_assoc($result2); echo "<div id='attack_left'>" . $YW['weapon_name'] . "</div><div id='attack_right'>" . $YW['ammount'] . "</div>"; } }else{ echo "<div id='attack_center'>This nation doesn't have any weapons...</div>"; } Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 There is nothing wrong in the code above. Are you sure you have the data in db you say you have? Maybe you have two records in the main table but not any results for the another region in the weapons table? Since the only thing you are outputting is the results from weapons table. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted August 13, 2009 Author Share Posted August 13, 2009 Sorry the databases are this: region_weapons region_id weapon_id ammount 1-------------1-------------5 2-------------1-------------0 1-------------2-------------2 weapons Attachment. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 Oh yeas.. now I know it, inside the while loop you do this: <?php $YW = mysql_fetch_assoc($result2); This gets only one row from $result2, and thats it. you should do another while loop inside the first while loop and loop there through the results in $result2. And also echo the results in $result2 also inside the second while loop. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted August 13, 2009 Author Share Posted August 13, 2009 It's solved Thanks 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.