Multiple while loops


Posted on 16th Feb 2014 07:03 pm by admin

I have several DB queries that I know should be returning results and aren't. I have a feeling it has to do with the several while loops that should be outputting the data.
One more issue is that when I echo the num_rows they are all 0 except the first one.
BTW I checked that all variables were being populated and they were.

Here is my code:

Code: $sql1 = "SELECT * FROM player1 where player = '$username'";
$sql2 = "SELECT * FROM player2 where player = '$username'";
$sql3 = "SELECT * FROM player3 where player = '$username'";
$sql4 = "SELECT * FROM player4 where player = '$username'";
$sql5 = "SELECT * FROM player5 where player = '$username'";
$sql6 = "SELECT * FROM player6 where player = '$username'";

$result1 = mysql_query($sql1);
$result2 = mysql_query($sql2);
$result3 = mysql_query($sql3);
$result4 = mysql_query($sql4);
$result5 = mysql_query($sql5);
$result6 = mysql_query($sql6);

$num1 = mysql_num_rows($result1);
$num2 = mysql_num_rows($result2);
$num3 = mysql_num_rows($result3);
$num4 = mysql_num_rows($result4);
$num5 = mysql_num_rows($result5);
$num6 = mysql_num_rows($result6);


Code: while ($b < $num1){
$game=mysql_result($result1,$b,chatId);
$g="SELECT * from chats where name = '$game'";
$gResult= mysql_query($g);
$info=mysql_fetch_assoc($gResult);
echo "
<tr>
<td>" . $info['realName'] . "</td>
<td>" . $info['dm'] . "</td>
</tr>
";
$b++;
}
while ($b < $num2){
$game=mysql_result($result2,$b,chatId);
$g="SELECT * from chats where name = '$game'";
$gResult= mysql_query($g);
$info=mysql_fetch_assoc($gResult);
echo "
<tr>
<td>" . $info['realName'] . "</td>
<td>" . $info['dm'] . "</td>
</tr>
";
$b++;
}

while ($b < $num3){
$game=mysql_result($result3,$b,chatId);
$g="SELECT * from chats where name = '$game'";
$gResult= mysql_query($g);
$info=mysql_fetch_assoc($gResult);
echo "
<tr>
<td>" . $info['realName'] . "</td>
<td>" . $info['dm'] . "</td>
</tr>
";
$b++;
}

while ($b < $num4){
$game=mysql_result($result4,$b,chatId);
$g="SELECT * from chats where name = '$game'";
$gResult= mysql_query($g);
$info=mysql_fetch_assoc($gResult);
echo "
<tr>
<td>" . $info['realName'] . "</td>
<td>" . $info['dm'] . "</td>
</tr>
";
$b++;
}

while ($b < $num5){
$game=mysql_result($result5,$b,chatId);
$g="SELECT * from chats where name = '$game'";
$gResult= mysql_query($g);
$info=mysql_fetch_assoc($gResult);
echo "
<tr>
<td>" . $info['realName'] . "</td>
<td>" . $info['dm'] . "</td>
</tr>
";
$b++;
}

while ($b < $num6){
$game=mysql_result($result6,$b,chatId);
$g="SELECT * from chats where name = '$game'";
$gResult= mysql_query($g);
$info=mysql_fetch_assoc($gResult);
echo "
<tr>
<td>" . $info['realName'] . "</td>
<td>" . $info['dm'] . "</td>
</tr>
";
$b++;
}
I have tried changing the variable $b to something else in each loop but that didnt work either.

No comments posted yet

Your Answer:

Login to answer
101 Like 34 Dislike
Previous forums Next forums
Other forums

BB_Code error
I'm having a problem with a custom built function and keep getting this error:


Warning: M

php - xml what is the best way to do this.
IN essence I want to have a script calling the info from the database.. I have no problem thus far,

Checking if variable is 0 as opposed to NULL/Empty...
I'm trying to write some code that will retrieve a user's access level from my database and if it do

This must be easy , pulling the last record of the day, every day, from a txt
I have a txt file logging weather data every minutes (so 1 record per minute). I want to extract the

Syntax Help
I'm trying to make a form that edits a php file which contains config settings. I'm using strings t

Dynamically set AccordianPane Header
I have an accordian on my master page. I'd like to be able to dynamically change the header on diff

Echo-ing MySQL content and Keep Formatting?
I have data in my MySQL such as:

QuoteBlah blah

Blah blah

etc
but when i ech

DOMDocument parsing
Hello, I am parsing an xml file from an API which I have converted into a DOMDocument in php. This i

User feedback after MySQL query has been executed
Hi all, I've just registered on PHPFreaks because I've got a question that I simply can't work out b

disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash