Jump to content
Updating IPB tonight Read more... ×

Archived

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

supanoob

querys

Recommended Posts

$query2="select blah, blah, blah from news where player_id='$playerid'";
$result2=mysql_query($query2);
if (!$result2)
{
die (mysql_error());
}

well i have that, and i want it to look where player_id=$playerid and where what_news='Battle'

but i cant remember how to do it, i know you cant use && in querys

Share this post


Link to post
Share on other sites
[!--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--]

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
get rid of the first one. only do the fetch array inside your while ($blah = fetch_array) { .. }

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.