I've got a database that contains info on some images. The columns are id, name, description, location and visible.
I'm trying to have PHP read in the location column as an array WHERE visible=1, but it's not working. Can anyone see where I'm going wrong?
I know I should be using mysqli, before anyone points this out to me. I will do, once I've got this array syntax sorted out.
My code is below:
<?php
$con = mysql_connect("localhost", "root", "mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("shibby",$con);
$sql = "SELECT location from gallery WHERE visible=1";
$photos= mysql_query($sql,$con);
print_r(mysql_fetch_array($result));
mysql_close($con);
$i = 0;
foreach ($photos as $photo) {
$i = 0;
if ($i < 3) {
echo '<td><center><img src="'.$photo.'.jpg"></td>';
$i++;
} elseif ($i == 3) {
echo '</tr><tr>';
$i = 0;
}
}
$resultis not defined. Change$photos= mysql_query($sql,$con);to$result= mysql_query($sql,$con);and set the fetch method to$photosmysql_*functions have been deprecated. You should transition to mysqli or PDO.mysql_fetch_arrayin the manual - it just fetches a row, not the whole resultset. Look at the examples on that page to see how to retrieve all results.