supanoob Posted June 24, 2006 Share Posted June 24, 2006 $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 Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/ Share on other sites More sharing options...
.josh Posted June 24, 2006 Share Posted June 24, 2006 [!--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--] Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/#findComment-49136 Share on other sites More sharing options...
supanoob Posted June 24, 2006 Author Share Posted June 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/#findComment-49153 Share on other sites More sharing options...
.josh Posted June 25, 2006 Share Posted June 25, 2006 first off, it would be cleaner if you did your code like this:[code]<?phpwhile ($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. Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/#findComment-49307 Share on other sites More sharing options...
supanoob Posted June 25, 2006 Author Share Posted June 25, 2006 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 codequery:[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 Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/#findComment-49398 Share on other sites More sharing options...
.josh Posted June 25, 2006 Share Posted June 25, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/#findComment-49421 Share on other sites More sharing options...
supanoob Posted June 26, 2006 Author Share Posted June 26, 2006 i think so :s so i need to get rid of one of the fetch arrays? Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/#findComment-49600 Share on other sites More sharing options...
.josh Posted June 26, 2006 Share Posted June 26, 2006 get rid of the first one. only do the fetch array inside your while ($blah = fetch_array) { .. } Quote Link to comment https://forums.phpfreaks.com/topic/12816-querys/#findComment-49602 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.