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

text box alphanumeric caracters only
hi all!

I have search on google on how to enter in a test box only caracters A-Z,a-z,0-9 usi

PHP/Database issue
My friend is helping me make a database where you go to a certain webpage of my site and the page wi

Making multiple rows with one query
I have a table called efed_handler_characters with two fields handler_id and bio_id. What query 2 is

Not Inserting into DB
I can't get my Add new Division form to submit to the database. Anyone see my issue?

Code: &a

Displaying Multidimensional Arrays...about to put my head in a vice, PLEASE HELP
I am fairly new to PHP and MySQL and I have a problem which I have been trying to resolve for days.

PHP Include w/If IE Condition Statement?
I was having a problem with Internet Exploder (big surprise, right?) displaying my drop down menus i

C++ Http request?
Code: string Response = "LOGIN_UNSUCCESSFUL"; System.Net.WebRequest request = Sy

Module pool selction screen parameters combination logic
Hi floks,
Am new to the module pool development ,Recently i have created one program based on

Staff Induction System - No idea where to go from here!!!
Hi there, I'm pretty new to PHP and Mysql so could really do with being pointed in the right directi

Logging and nologging bulk insert
Hi,

oracle version: 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production

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