Displaying Images from a DB

connect_error) { echo "

Well, this stinks

"; die($conn->connect_error); } $myQuery = "SELECT * FROM images"; $result = $conn->query($myQuery); if (!$result) { echo "

Error in reading database!

"; die($conn->error); } else { for ($i = 0; $i < $result->num_rows; ++$i) { /* get image */ $result->data_seek($i); $row = $result->fetch_array (MYSQLI_ASSOC); echo "
"; echo 'Img name: ' , $row['name'] , '
'; echo ""; /* make buttons */ echo "
"; echo '
'; echo ''; echo ''; echo '
'; echo "
"; echo "
"; } /* Go through all of the possibilities for the buttons; * if one matches, then display that image. */ for ($j = 0; $j < $result->num_rows; ++$j) if (array_key_exists($j, $_POST)) { image ($j); } /* If desired, refresh the screen if button is pressed. * In this one, all of the buttons are named "reset", so don't need to loop. if (array_key_exists('reset', $_POST)) { funReset(); } */ } /* Functions used by above */ /* Function to display image at full size depending on which button was pressed. * id : the value of the button which corresponds to the index into the DB. */ function image ($id) { echo "
"; require 'login.php'; $conn = new mysqli($hostname, $username, $password, "myDatabase"); if ($conn->connect_error) { echo "

Error connecting in image() function

"; die($conn->connect_error); } else { $myQuery = "SELECT * FROM images"; $result = $conn->query($myQuery); if (!$result) { echo "

Error in reading database!

"; die($conn->error); } $result->data_seek($id); $row = $result->fetch_array (MYSQLI_ASSOC); echo ""; echo "
"; } } /* Refresh the screen */ function funReset() { header("refresh: 1"); } ?>