Jump to content


Photo

php and mysql


  • Please log in to reply
5 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 03:33 AM

what i'm looking for is how i can put some images in a directory and have their name in mysql to pull it from mysql, if that makes sense..

i'm lost my self..

but i been looking for putting pictures in mysql and everywhere it say is a bad idea and i'm looking for a way to put them in a folder but still work with them threw mysql..

#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 03 May 2006 - 05:29 AM

you can run your uploadfile and at the bottom of the same page have a mysql query insert just the name into you bd and just call the name up later when you want to display the pic like so

<?
your upload code here....
$pic=$_POST['pic_name'];
mysql_query("insert into your_table(pic_name)values('$pic')");
?>

that is to insert the name into db


<?
$getpic=mysql_query("select * from your_table");
while($getpic2=mysql_fetch_array($getpic)){
echo "<img src=../your_pic_directory/$getpic2[pic_name]>";
}
?>

and that is to pull the pic name up from the db
and where pic_name is replace that with the colmn name where your pics names are stored
The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#3 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 05:56 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]:S

what i dont get is.. how i'ma put the picture in the directory and the name in the database and when i call it from the data base how is it going to know where to look for the picture.[/quote]

ok i think i know the src gets the directory and the $pic is the fecth name form my sql..

but can this be done..

make a upload bottom to make the picture go to the directory and mysql?

#4 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 06:50 AM

ok i got it to wotk but now i can't display the picture using it like this
<?php
include 'config/db.php';

$getpic=mysql_query("SELECT name FROM upload2");
while($row=mysql_fetch_array($getpic))
{
echo '<img src="/xml/$row">';
}
?>


#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 02:34 PM

Variables inside single quotes are not expanded. Also the variable $row is an array. The index "name" of that array should contain the picture's filename. Try this:
<?php echo '<img src="/xml/' . $row['name'] . '">'; ?>

Ken

#6 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 07:06 PM

yeah that worked :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users