display image using filepath from database
I have a database table called 'uploads' that has filepaths to uploaded images in a 'filepath' column.
i want to be able to display these images, 1 at a time( with some kind of 'next' and 'previous' button to come at a later date) on a page.
so i know i need to connect to the database as usual and then query it, and then display the result of this query within an img tag, but besides from this i dont know the exact method and what ive got so far doesnt work. database connection has happened further up the script..
can somebody give me some help with this please,
$result=mysql_query("SELECT 'filepath' FROM 'uploads'");
<img src="<?php echo($result)?>" />
What you are looking for to get the next/prev working is called Pagination, search for it on google or on these forums there's TONS of discussions on it.
As far as the snippet you showed, you are trying to echo a resource. You need to fetch the rows you just queried for (in this case with mysql_fetch_array) then output from there.
Also note the entire mysql_* library has been deprecated in favor of MySQL[i] (the i stands for improved) or PDO. See http://php.net/manual/en/mysqlinfo.api.choosing.php for more info.
Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
I'd rather be a comma, then a full stop.
User Authentication in PHP with MySQLi
- Don't forget to mark threads resolved - MySQL(i) warning
Just to quickly touch on the pagination, you're probably going to use the MySQL limit clause. Click here to read more about it (you'll have to scroll down a bit to find it, or use ctrl-f).
MOD EDIT: Anchor added to URL so that no scrolling is needed.
Last edited by bradgrafelman; 04-10-2012 at 11:26 AM.
Er.. are you sure about that? The code snippet you posted only has two statements but contains 3-4 errors (depending upon what you call an error as opposed to just bad practice).
Originally Posted by rpsep2
I only ask because it's rather pointless for us to try to direct you to resources about pagination (which has been discussed many times here at PHPBuilder - you might try doing a search for 'mysql pagination') if you're still having problems with sending queries and retrieving results.
Originally Posted by bradgrafelman
i meant that i know i need to... just not 100% sure how hence the post
looked at the mysql_fetch_array and it now works! thank you. now gunna go try and figure out pagination
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)