Pulling results from a database

have a Pic field in a Members tale.

Is this an ok select statement to retrieve the last row in the table and get the Pic record. Then im trying to place that Pic (which is a URL of an image) in an <img> tag to display it.


<?php
...
$query = "SELECT Pic FROM Members ORDER BY id DESC LIMIT 1";

$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_row($result);
?>
            <h1>Members</h1> 
<div class="shadow1"> 
<img src="<? echo $row['Pic']; ?>" alt="New Memeber" />
$query = "SELECT Pic FROM Members ORDER BY id DESC LIMIT 1";
//echo $query;

$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_row($result);
?>
            <h1>Members</h1> 
<img src="<? echo $row['Pic']; ?>" alt="New Memeber" />

you’re going to get the same row for both queries

Rudy, what’s your thoughts on the OPs query vs:

SELECT
    Pic
FROM
    Members
WHERE
    id = (
            SELECT
                MAX(id)
            FROM
                Members
        ) AS highest_id

I know that the above goes on the assumption that the id field is an auto-number field. I think I remember reading somewhere limit isn’t available on all servers.

opps, why did that duplicate?
Heres the html/php


<?php...
$query = "SELECT Pic FROM Members ORDER BY id DESC LIMIT 1";

$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_row($result);
?>

Then output it


            <h1>Members</h1> 
<div class="shadow1"> 
<img src="<? echo $row["Pic"]; ?>" alt="New Memeber" />\\

the results should be the same, and that’s as far as i’m willing to go :wink:

okay, well, yours is actually standard SQL, even if auto_increments aren’t :slight_smile:

edit: the AS clause is wrong

so does the other solution

and i wouldn’t use either of them :wink:

it’s been supported since forever

k, thanks…