Jump to content

Recommended Posts

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']select[/span] blah, blah, blah [color=green]from[/color] [color=orange]news[/color] [color=green]where[/color] player_id[color=orange]=[/color][color=red]'$playerid'[/color] [color=blue]and[/color] what_news[color=orange]=[/color][color=red]'Battle'[/color]
[!--sql2--][/div][!--sql3--]
Link to comment
https://forums.phpfreaks.com/topic/12816-querys/#findComment-49136
Share on other sites

ok, so i did that any ideawhy this for loop:

[code]
<?php
// for loop starts here
$num_rows=mysql_num_rows($result2);
for ($i=0;$i<$num_rows;$i++)
{
$row=mysql_fetch_array($result2);
$fight_id=($row['fight_id']);
$fight_name=($row['fight_name']);


echo "$fight_name($fight_id) Defeated You HAHA<br>
      ";
  } ?>[/code]

looks like this:

[img src=\"http://img230.imageshack.us/img230/9756/meh0ws.jpg\" border=\"0\" alt=\"IPB Image\" /]

yeah its messed up, i have at least 2 things in my db that are meant to be echoes yet only one is and the other is like there but not if you know what i mean, and then at the bottom it echos another row of anything that doesnt have <> round it or $ infront of it.
Link to comment
https://forums.phpfreaks.com/topic/12816-querys/#findComment-49153
Share on other sites

first off, it would be cleaner if you did your code like this:
[code]
<?php
while ($row = mysql_fetch_array($result2)) {
   $fight_id = $row['fight_id'];
   $fight_name = $row['fight_name'];

   echo "$fight_name($fight_id) Defeated You HAHA<br>";
}
?>
[/code]
2nd, since the fight_id seems to show up on one iteration, but not the 2nd, all i can really think of is that your database does not have a value stored in fight_id on that row. and as far as $fight_name not echoing, all i can really think of is that when you assign $row['fight_name'] to it, fight_name either does not have info in the row, or else you typoed fight_name.

or, perhaps your query is fragged. maybe you did not select the proper columns? like when i showed you select blah,blah,blah, was fight_name in that list? show your actual query string, please.

and on that note, a great debugging method is to echo your query string out on your screen, and copy/paste it in phpmyadmin and see if it gives you the desired results.
Link to comment
https://forums.phpfreaks.com/topic/12816-querys/#findComment-49307
Share on other sites

thank you so much, it no longer echos an extra row :D although it still only shows 1 of the 2 rows with that query... this is the code


query:
[code]$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());
}
$row=mysql_fetch_array($result2);
$fight_id=($row['fight_id']);
$fight_name=($row['fight_name']);[/code]

loop:
[code]<?php
while ($row = mysql_fetch_array($result2)) {
   $fight_id = $row['fight_id'];
   $fight_name = $row['fight_name'];

   echo "$fight_name($fight_id) Defeated You HAHA<br>";
}
?>[/code]

now in my db i have 2 rows that match the query, i know because i put them there myself :D i dont know why it only echos 1 though :S
Link to comment
https://forums.phpfreaks.com/topic/12816-querys/#findComment-49398
Share on other sites

are both those codes combined? cuz in your first code block you do a fetch_array and then you turn around and do the while loop. each time you fetch_array it moves to the next row, so when you start the while loop, it has already cycled through 1 row, but you haven't echoed that first row, get it?
Link to comment
https://forums.phpfreaks.com/topic/12816-querys/#findComment-49421
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.