Jump to content


Photo

querys


  • Please log in to reply
7 replies to this topic

#1 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 24 June 2006 - 05:50 PM

$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

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 June 2006 - 05:55 PM

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']select[/span] blah, blah, blah from news where player_id='$playerid' and what_news='Battle'
[!--sql2--][/div][!--sql3--]

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 24 June 2006 - 07:24 PM

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

<?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>
      "; 
  } ?>

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.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 07:08 AM

first off, it would be cleaner if you did your code like this:
<?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>";
} 
?>
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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 25 June 2006 - 04:02 PM

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

loop:
<?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>";
} 
?>

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

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 06:07 PM

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?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 supanoob

supanoob
  • Members
  • PipPipPip
  • Advanced Member
  • 342 posts

Posted 26 June 2006 - 10:01 AM

i think so :s so i need to get rid of one of the fetch arrays?

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 June 2006 - 10:02 AM

get rid of the first one. only do the fetch array inside your while ($blah = fetch_array) { .. }
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users