Jump to content


Photo

For Loops


  • Please log in to reply
3 replies to this topic

#1 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 10 August 2006 - 12:30 PM

ok so i have this code for my for 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.

$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']);

so i have the 2 queries:

Query 1 using the poster_id
$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']);

Query 2 using the legion_id
$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']);

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.

#2 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 10 August 2006 - 03:12 PM

help ?

#3 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 10 August 2006 - 03:22 PM

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.

#4 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 10 August 2006 - 03:34 PM

ok thanks :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users