Page 1 of 1

SQL syntax 'Resource id #2'

Posted: Thu Jul 31, 2003 3:40 am
by Nunners
I've never seen this one before, and can't work out what is wrong with my code:

Code: Select all

<?php
$company_sql="SELECT * FROM `Company`";
$company_result=mysql_query($company_sql,$connect);
echo($company_sql);
?>
<table width="80%" align="center">
	<tr>
		<th>Name</th>
		<th>Town/City</th>
		<th>Venue Host</th>
	</tr>
<?php
while ($company=mysql_query($company_result)) {
?>
	<tr>
		<td><?php echo($company["Name"]); ?></td>
		<td><?php echo($company["City"]); ?></td>
		<td><input type="checkbox" <?php if ($company["Course_Location"]==1) { echo("CHECKED"); } ?>></td>
	</tr>
<?php
}
?>
It's really simple. I just want to list the Companies. However it comes back with the following MySQL Error:

Code: Select all

You have an error in your SQL syntax near 'Resource id #2' at line 1
Any ideas anyone?

Please!!!!

Posted: Thu Jul 31, 2003 3:45 am
by Nunners
PS: I have checked the SQL directly on the MySQL Database, and it works fine....

Posted: Thu Jul 31, 2003 6:39 am
by twigletmac
Instead of:

Code: Select all

while ($company=mysql_query($company_result)) {
try

Code: Select all

while ($company = mysql_fetch_assoc($company_result)) {
You were trying to query the result of the previous query which is what was giving you the error.

Mac

Posted: Thu Jul 31, 2003 7:19 am
by Nunners
Cheers guys... I've been sat looking at that for 2 hours and just couldn't see the error....
And it's simple!

I need more sleep I think!

Thanks