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!
I don't suppose anyone can tell me where I've gone wrong with my code to display the cheapest hotel rooms in various towns. At the top of my page I've got this:
//Select cheapest room price from each town
$query = "SELECT GeoTown, (MIN(RoomsFrom) AS RoomsFrom) FROM hotel";
$result = mysql_query($query)
or die ("Couldn't execute query");
$row = mysql_fetch_array($result);
.... and then to call it up further down in my page I've got this (Bath is just the first town - I will need to do this for lots of towns):
<?php
//Select cheapest room price from each town
$query = "SELECT GeoTown, ROUND(MIN(RoomsFrom)) AS RoomsFrom FROM hotel WHERE GeoTown='bath'";
$result = mysql_query($query) or die ("Couldn't execute query");
$row = mysql_fetch_array($result);
?>
//And at the bottom:
<td align="right"> £<?php echo $row['RoomsFrom']; ?></td>
Thanks very much for replying - I kind of thought I was mixing my mysql with my php - i've completely forgotten the very limited knowledge I ever had. oh dear... my next question though is:
do i have to call the database each time I want to display the result for a different town?
i only ask because I have about 150 towns that I want to display the prices for and I'd just end up with reams of code....
thanks feyd, but i don't just want the first 150 towns - i want a specific selection.
i don't suppose there's any way i could SELECT the prices WHERE GeoTown=some variable which i could then change later in the page to be Bath, London, Paris etc or whatever?...
or does the variable have to be set before i include the SELECT statement?
the variable must exist when you create the string or you will get a blank value. You can use the IN() syntax to get a set of specific towns, or you can perform seperate queries for each town. Your choice.
I'm still having problems with this and can't find anything here or on the net that's helping. I've used the IN fucntion as feyd suggests, but have no idea how to echo the results i need from it. So far i'm using this: