Jump to content

Archived

This topic is now archived and is closed to further replies.

corillo181

php and mysql

Recommended Posts

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..

Share this post


Link to post
Share on other sites
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

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

that is to insert the name into db

[code]

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

[/code]
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

Share this post


Link to post
Share on other sites
[!--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?

Share this post


Link to post
Share on other sites
ok i got it to wotk but now i can't display the picture using it like this
[code]<?php
include 'config/db.php';

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

Share this post


Link to post
Share on other sites
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:
[code]<?php echo '<img src="/xml/' . $row['name'] . '">'; ?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.