Code error with 'select' and 'where'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simon_porter00
Forum Newbie
Posts: 13
Joined: Thu Feb 25, 2010 1:25 pm

Code error with 'select' and 'where'

Post by simon_porter00 »

This is probably something really easy that I'm missing.
here's the code:

Code: Select all

require_once("Dbconn");
list($kto,$gdzie)=explode('_',key($_POST));

if($kto=='schools'){
$query = "select schools.ID,schools.Name,schools_location.district,schools_location.town
from schools left join schools_location on schools.ID=schools_location.school_id where schools_location.county='$gdzie' group by schools.ID";
}
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
?>

<?php if($kto=='schools'):?>
<h2>Schools - <?php echo '$gdzie';?></h2>
<table class="sortable" width="100%">
<tr><th align="left">Name:</th><th align="left">Town:</th><th  align="left" class="unsortable">District:</th><th  align="left" class="unsortable">Details:</th></tr>
<tr><td><?php echo $row['Name']?></td>
<td><?php echo $row['town']?></td>
<td><?php echo $row['district']?></td>
<td><a href="schoolsprofile.php?ID=<?php echo $row['ID']?>">School's profile</a></td></tr>
The error message I'm getting is:

Code: Select all

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'left join schools_location on schools.ID=schools_location.school_id where school' at line 1
Any ideas what I'm missing?
Many TIA
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Code error with 'select' and 'where'

Post by oscardog »

As a starting point, try echoing $query and see what comes up. I imagine you'll be able to spot the problem from what is output.
simon_porter00
Forum Newbie
Posts: 13
Joined: Thu Feb 25, 2010 1:25 pm

Re: Code error with 'select' and 'where'

Post by simon_porter00 »

This problem's been resolved now - thanks for the help. Got another problem now, but I'll start another thread for that.
Post Reply