Reputation: 783
im very new to this and have a very basic knowledge php and SQL this is my first website, please could some one help.
I currently have information being pulled from my database to my website, which is good.
however i want to run another couple of queries on the same html page one that will display a list of the latest 5 entries in the database and sort them by 'location_id' descending, the other will display a list of 5 entries and display them random every time the page refreshes. see my code below:
?php
require "connect.php";
$query = "select * from location";
$result = @mysql_query($query, $connection)
or die ("Unable to perform query<br>$query");
?>
<?php
while($row= mysql_fetch_array($result))
{
?>
<?php echo $row['location_id'] ?>
?php } ?>
Also when i was experimenting trying to solve this myself, i duplicated the loop shown above in a different location, and it would not display anything, can sone one explain why?
Thanks Guys
Upvotes: 2
Views: 1036
Reputation: 1562
You could reset the query to do this or
create a new query and result with different names and then when the page runs have it select one of the queries to run.
$query1 = "select * from location";
$result1 = @mysql_query($query1, $connection);
or die ("Unable to perform query<br>$query1");
resetting might be easier but this is an option too
Upvotes: 0
Reputation: 1279
i have just seen the syntax.
i guess ";" is missing in
should be
<?php echo $row['location_id'] ; ?>
Upvotes: 0