Jump to content


Photo

while loops


  • Please log in to reply
2 replies to this topic

#1 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 09 July 2006 - 08:18 PM

$query2="select player_id, news_msg, news_date, what_news, fight_name, fight_id, win_lose from news where player_id='$playerid' and win_lose='Lost'";
$result2=mysql_query($query2);
if (!$result2)
{
die (mysql_error());
}
while ($row = mysql_fetch_array($result2)) 
{ 
$row=mysql_fetch_array($result2);
$fight_id=($row['fight_id']);
$fight_name=($row['fight_name']);
$win_lose=($row['win_lose']);
echo "$fight_name($fight_id) Has Defeated You HAHA.<br>";
}

well ok so i have that and it is meant to echo "$fight_name($fight_id) Has Defeated You HAHA." that like so:

Stefan(1) Has Defeated you HAHA.
Stefan(1) Has Defeated you HAHA.


but instead it does this:


Stefan(1) Has Defeated you HAHA.
Stefan(1) Has Defeated you HAHA.
() Has Defeated you HAHA.


now i have checked and double checked my DB and i have no black fields. and i have checked and triple checked my code and i have not repeated the query anywhere else. i just cant see anything wrong with that code ^^

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 09 July 2006 - 08:22 PM

Get rid of this line inside the while loop:

$row=mysql_fetch_array($result2);

while ($row = mysql_fetch_array($result2))
  echo "{$row['fight_name']}({$row['fight_id']}) Has Defeated You HAHA.<br>";



#3 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 09 July 2006 - 08:22 PM

You have the "$row=mysql_fetch_array($result2);" part twice. This may be why. You only need it inside the while() loop.
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users