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.
@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]";
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
@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?
@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());
@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";
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)
@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.