Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
Nunners
- Forum Commoner
- Posts: 89
- Joined: Tue Jan 28, 2003 7:52 am
- Location: Worcester, UK
-
Contact:
Post
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!!!!
-
Nunners
- Forum Commoner
- Posts: 89
- Joined: Tue Jan 28, 2003 7:52 am
- Location: Worcester, UK
-
Contact:
Post
by Nunners »
PS: I have checked the SQL directly on the MySQL Database, and it works fine....
-
twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Post
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
-
Nunners
- Forum Commoner
- Posts: 89
- Joined: Tue Jan 28, 2003 7:52 am
- Location: Worcester, UK
-
Contact:
Post
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