I have the following code. What I have labelled block 1
and block 2
don't seem to work together but one does if i get rid of the other; when checking using print_r.
I am fairly new to php and was wondering if somebody could point out where I went wrong. I had it working somewhere else before but lost the file. Many thanks in advance.
P.S: I am aware it is a good idea to get into PDO and mysqli sooner rather than later. But I just want to get to grips with the basics first.
<?php
//Connect to database
$connect = mysql_connect ("localhost","root","password");
$db = mysql_select_db("project");
//Find top 100 most popular images
$pop = mysql_query("
SELECT * FROM users ORDER BY pop DESC LIMIT 2
");
//Define local variables for images to show
//block 1//
$images = array();
while ($row = mysql_fetch_array($pop)) {
$images[] = $row['image'];
}
//block2//
$links = array ();
while ($row = mysql_fetch_array($pop)){
$links[] = $row['username'];
}
?>