Jump to content

[SOLVED] Only one row is showed


DEVILofDARKNESS

Recommended Posts

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>";
			}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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