Hi there!
I have a script (which works), for obtaining the first (or any id number submitted) image from a database.
But recently, I asked on here how to obtain the LAST id from this database ie most recent image.
I was given a very good solution, but I'm not 100% sure how to correctly add this to my current script,
and then using the result in a URL I am using within an Android app I've developed.
Can anyone give me the full, altered script from my original, and solution below, and also what I should then add to the end
of the URL (in place of ?id=1..
Many thanks in advance!!
ORIGINAL PHP SCRIPT:
<?php include "file_constants.php"; // just so we know it is broken error_reporting(E_ALL); // some basic sanity checks if(isset($_GET['id']) && is_numeric($_GET['id'])) { //connect to the db $link = mysql_connect("$host", "$user", "$pass") or die("Could not connect: " . mysql_error()); // select our database mysql_select_db("$db") or die(mysql_error()); // get the image from the db $sql = "SELECT image FROM test_image WHERE id=" .$_GET['id'] . ";"; // the result of the query $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); // set the header for the image header("Content-type: image/jpeg"); echo mysql_result($result, 0); // close the db link mysql_close($link); } else { echo 'Please use a real id number'; } ?>
SOLUTION:
<?php $sql = "SELECT image FROM test_image ORDER BY id DESC LIMIT 1"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_row($result); ?>
CURRENT URL:
"http://padihamcars.com/file_display.php?id=1"