/    Sign up×
Community /Pin to ProfileBookmark

displaying uploaded pics

when a user uploads a picture to my website, values like the filename, filesize go into a upload table and the pictures are stored in a uploads folder. now how do i get these uploaded pics to display? i have more then one picture to display by the way.

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuySep 03.2006 — I did something like this:

[code=php]$gimg = "SELECT * FROM images WHERE userid='$row[userid]'";
$gimgquery = mysql_query($gimg);
$gimgnumrows = mysql_num_rows($gimgquery);
$q = 1;
if($gimgnumrows == 0){
echo'<h2>You have no uploaded images</h2>';
}else{
while($eimg = mysql_fetch_array($gimgquery)){
$image = "images/graphics/$eimg[filename]";
<img alt="'.$eimg[filename].'" src="images/graphics/thumbs/'.$eimg[filename].'">
}
}[/code]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYSep 03.2006 — TLG, can't you change the content of your homepage?

i know your server has been hacked, but do you still have no access to it?
Copy linkTweet thisAlerts:
@matty_y2002authorSep 03.2006 — Hey, i have used your code to display my uploaded 'The little guy' and i have a parse error on the line that has ** in it. Obviously in the real code the ** isnt there, its just there to show what line has a error in it. can anyone help, because i cant see the error.
[code=php]
$query = "SELECT * FROM uploads LIMIT $start, $display";
$gimgquery = mysql_query($query);
$gimgnumrows = mysql_num_rows($gimgquery);
if($gimgnumrows == 0){
echo'<h2>You have no uploaded images</h2>';
}else{
while($eimg = mysql_fetch_array($gimgquery)){
$image = "account/uploads/$eimg[filename]";

** <img alt="'.$eimg[filename].'" src="./account/uploads/'.$eimg[filename].'">**

}

}[/code]
Copy linkTweet thisAlerts:
@DJsACSep 03.2006 — [code=php] $query = "SELECT * FROM uploads LIMIT $start, $display";
$gimgquery = mysql_query($query);
$gimgnumrows = mysql_num_rows($gimgquery);
if($gimgnumrows == 0){
echo'<h2>You have no uploaded images</h2>';
}else{
while($eimg = mysql_fetch_array($gimgquery)){
$image = "account/uploads/$eimg[filename]";

echo '<img alt="'.$eimg[filename].'" src="./account/uploads/'.$eimg[filename].'">';
//the above code was html, and it was in a php codefragment.
//echo the entire thing to 'print' the html on the page and not get a parse error

}

} [/code]
Copy linkTweet thisAlerts:
@The_Little_GuySep 03.2006 — Opps, I forgot to add the echo.

I was just copy and pasting from one of my files.

Well... Does it work?

P.S. LCF... I changed the homepage.
Copy linkTweet thisAlerts:
@matty_y2002authorSep 04.2006 — hey, i have a this error [B]Warning: Supplied argument is not a valid MySQL result resource on line 133[/B] where line 133 has the ** around it. I think the reason is because i am currently running apache 1.3 and not my files via a server. does anybody know another way how i can display my uploaded pics?

[code=php]$query = "SELECT * FROM uploads LIMIT $start, $display";
$gimgquery = mysql_query($query);
** $gimgnumrows = mysql_num_rows($gimgquery); **
if($gimgnumrows == 0){
echo'<h2>You have no uploaded images</h2>
}else{
while($eimg = mysql_fetch_array($gimgquery)){
$image = "account/uploads/$eimg[filename]";
echo '<img alt="'.$eimg[filename].'" src="./account/uploads/'.$eimg[filename].'" width="200px" height="200px">';
}
}[/code]
Copy linkTweet thisAlerts:
@DJsACSep 04.2006 — hey, i have a this error [B]Warning: Supplied argument is not a valid MySQL result resource on line 133[/B] where line 133 has the ** around it. I think the reason is because i am currently running apache 1.3 and not my files via a server. does anybody know another way how i can display my uploaded pics?

[code=php]$query = "SELECT * FROM uploads LIMIT $start, $display";
$gimgquery = mysql_query($query);
** $gimgnumrows = mysql_num_rows($gimgquery); **
if($gimgnumrows == 0){
echo'<h2>You have no uploaded images</h2>
}else{
while($eimg = mysql_fetch_array($gimgquery)){
$image = "account/uploads/$eimg[filename]";
echo '<img alt="'.$eimg[filename].'" src="./account/uploads/'.$eimg[filename].'" width="200px" height="200px">';
}
}[/code]
[/QUOTE]

you missed a ' after <h2>You have no uploaded images</h2> as wel ?

Are you connected to the database, and is the query returning something? if gimgquery is false, that would probably throw the resource error.

change:

$gimgquery = mysql_query($query);

to

$gimgquery = mysql_query($query) or die(mysql_error());

and see what that does ?
Copy linkTweet thisAlerts:
@matty_y2002authorSep 04.2006 — yeah, after editing the code to make it look presentable in the post i accidently deleted the '; after the end of the </h2> tag. i have changed my code to what you have said and now have another error message saying :

[B]You have an error in your SQL syntax near ' ' at line 1[/B], i am connected to the database after checking. i have however tried using the mysql_num_rows in another script and have the exact same error as last time so im thinking that could be the problem.

however i have included my new code
[code=php]$query = "SELECT * FROM uploads LIMIT $start, $display";

$gimgquery = mysql_query($query) or die(mysql_error());
$gimgnumrows = mysql_num_rows($gimgquery);
if($gimgnumrows == 0){

echo'<h2>You have no uploaded images</h2>';
}else{
while($eimg = mysql_fetch_array($gimgquery)){

$image = "account/uploads/$eimg[filename]";
echo '<img alt="'.$eimg[filename].'" src="./account/uploads/'.$eimg[filename].'" width="200px" height="200px">';
}
}[/code]


p.s i have checked that i have data in the table aswell and i have 3 entry's, and i have the field filename that stores the whole filename e.g (hello.gif)
Copy linkTweet thisAlerts:
@The_Little_GuySep 04.2006 — what is the name of the column that you are saving the file name of the image in the database?
Copy linkTweet thisAlerts:
@DJsACSep 04.2006 — $query = "SELECT * FROM uploads LIMIT $start, $display";

should probably be:

$query = "SELECT *
FROM uploads LIMIT ".$start.", ".$display;
Copy linkTweet thisAlerts:
@The_Little_GuySep 04.2006 — $query = "SELECT * FROM uploads LIMIT $start, $display";

should probably be:

$query = "SELECT *
FROM uploads LIMIT ".$start.", ".$display;[/QUOTE]

I don't believe you have to do that.
Copy linkTweet thisAlerts:
@matty_y2002authorSep 04.2006 — what is the name of the column that you are saving the file name of the image in the database?[/QUOTE]

the name of the colum that i am saving the file name is filename, see below that is what my uploads table looks like.

uploadid mediumint(8) not null unique

fishery varchar(40) not null

fishid varchar(15) Not null

weigh varchar(9) Not null


first_name varchar(15) Not null


last_name varchar(30) Not null


date_entered datetime Not null


filename varchar(15) Not null


filesize mediumint(7) Not null
Copy linkTweet thisAlerts:
@matty_y2002authorSep 04.2006 — hey, ive just used a completely different code and it works, thanks for all your help, much appreciated ?
[code=php]$query = "SELECT filename FROM uploads";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "{$row['filename']}";
echo "<img src="./account/uploads/{$row['filename']}" width="200px" height="200px" >";
echo '<br/>';
}[/code]


This is my finished code by the way, if anyone else wants to know how to do it.
×

Success!

Help @matty_y2002 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...