while statment with 2 different db query's

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
funsutton
Forum Newbie
Posts: 9
Joined: Sun Jan 18, 2004 12:02 pm

while statment with 2 different db query's

Post by funsutton »

I can only generate the $datarow['c'] and not the $row['Files']; Isn't there a way to do 2 while conditions at the same time? I need the result to be formatted in 2 separate columns. Thanks!

Code: Select all

<?
	include "dbconnect.php";
	$query = "SELECT * FROM Briansutton_Files";
	$result = mysql_query($query) or die(mysql_error());
	$dataquery = "SELECT *, COUNT(*) AS c FROM Briansutton_Log GROUP BY Page";
	$dataresult = mysql_query($dataquery) or die(mysql_error());
	echo "<table border=1>";

	while($row = mysql_fetch_assoc($result) && $datarow = mysql_fetch_assoc($dataresult))
	{ 
    echo "<td nowrap><font size=1 face=arial>".$row['Files']."</td>";
    echo "<td nowrap><font size=1 face=arial>".$datarow['c']."</td></tr>";
	}
	echo "</table>";
?>
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

Code: Select all

$query = "SELECT * FROM Briansutton_Files";
If "Files" is the name of database field the instead of this query use this one

Code: Select all

$query = "SELECT Files FROM Briansutton_Files";
funsutton
Forum Newbie
Posts: 9
Joined: Sun Jan 18, 2004 12:02 pm

Post by funsutton »

Each query will work on their own. I did as you suggested, but it still only outputs the $datarow...

perhaps it isn't possible to do 2 while statements at the same time.
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

try to execute result of queries separtely

Code: Select all

while($row = mysql_fetch_assoc($result) )
&#123;
your codr 
&#125;
while(datarow = mysql_fetch_assoc($dataresult)) )
&#123;
your code 

&#125;
check u r getting any result from both queries .
funsutton
Forum Newbie
Posts: 9
Joined: Sun Jan 18, 2004 12:02 pm

Post by funsutton »

Yeah, that doesnt work either...a nested while statement will complete the inner one first and then do the outter one.
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

Then i think u r not getting data from database in $row['Files']. just apply this query directly on ur table thro phpMyadmin then c what happen i think u r not getting data from this table.
Post Reply