Jump to content

Archived

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

supanoob

For Loops

Recommended Posts

ok so i have this code for my [b]for[/b] loop. now what i need to do is insert another 2 queries, one to select 2 things from the per who made the post, this will be done using the Poster_id, and another to select something from another table using Legion_id found within the query selected from the player.

[code]$query3="select poster_name, poster_id, board, post_date, reply_to, reply_body, reply_subject, post_id from forum where reply_to='$post'";
$result3=mysql_query($query3);
if (!$result3)
{
die (mysql_error());
}

$num_rows=mysql_num_rows($result3);
for ($i=0;$i<$num_rows;$i++)
{
$row=mysql_fetch_array($result3);
$poster_name2=($row['poster_name']);
$poster_id2=($row['poster_id']);
$board2=($row['board']);
$post_date2=($row['post_date']);
$reply_to=($row['reply_to']);
$reply_body=($row['reply_body']);
$reply_subject=($row['reply_subject']);
$post_id2=($row['post_id']);[/code]

so i have the 2 queries:

[b]Query 1 using the poster_id[/b]
[code]$query4="select name, postcount, legion_id from players where playerid='$poster_id2'";
$result4=mysql_query($query4);
if (!$result4)
{
die (mysql_error());
}

$num_rows=mysql_num_rows($result4);
$row=mysql_fetch_array($result4);
$name3=($row['name']);
$postcount3=($row['postcount']);
$legion_id3=($row['legion_id']);[/code]

[b]Query 2 using the legion_id[/b]
[code]$query5="select legion_name from legions where legion_id='$legion_id3'";
$result5=mysql_query($query5);
if (!$result5)
{
die (mysql_error());
}

$num_rows=mysql_num_rows($result5);
$row=mysql_fetch_array($result5);
$legion_name2=($row['legion_name']);[/code]

all i need to know is where to place them in the loop. since when i put them in it only echos one result then kills the loop.

Share this post


Link to post
Share on other sites
the problem is that your second and third queries are using the same variables, $num_rows, $row, to go through the results.  Use $num_rows3, $row3, etc. and it should work.

Share this post


Link to post
Share on other sites

×

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.