Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

need your help to retrieve images

images php coding issues or problems here.

Moderators: macek, egami, gesf

need your help to retrieve images

Postby mostafa581 » Sat Jul 21, 2012 11:24 am

friends
i,m making a page that retieve data from database and show them and these data include a picture for each one of them i could upload this pic with the data by a page in which i can insert data and this pic into database but when it is time to retrieve these data to be shown into this page i could show these data but each pic related to it,s specific topic was not retrieved to be shown beside it i can see a red ( X ) instead of the speific pic
so i need you to guide me to a tutorial by which i can follow to show mulitple pics retrieved from database
a snap shot of the page is included to see how do each pic look like
Thank you



here is the code


$get=mysql_query ("SELECT * FROM tourism_news order by id desc LIMIT $start , $per_page");

echo "<table border='1' width='100%' bordercolor='red'> ";
while ($row = mysql_fetch_assoc($get))
{
$lastid=mysql_insert_id();

echo "<table border='1' width='100%' bordercolor='red'> ";
echo" <tr align='right'>";
echo"
<td align='right' height='22' width='50%' ></td>
<td align='right' height='22' width='60%' background='titlebar.jpg' ><font color='white'><b> " .$row['topic']. " </b></font></td>
";
echo" </tr>";
echo "<table border='1' width='100%' bordercolor='green'> ";
echo"<tr><td align='right' width='70%' ><font color='black'> ".$row['summary']." <a href='show_this_news.php?id=".$row['id']."' title='".$row['topic']."'>التفاصيل</a>
</font></td><td align='right' rowspan='2' width='30%' >"; echo"<image src=getimage.php?id=$lastid >";
echo"</td>";
echo" </tr>";
echo"<tr><td align='left' width='70%' ><font color='black'>".$row['date']." مضاف بتاريخ</font></td>";
echo" </tr>";
}
?>
mostafa581
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jul 10, 2012 3:53 pm

Re: need your help to retrieve images

Postby kyle04 » Wed Jul 25, 2012 1:45 am

echo"<image src=getimage.php?id=$lastid >";


is not a valid file path to display an image.

AndyP
kyle04
New php-forum User
New php-forum User
 
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: need your help to retrieve images

Postby mostafa581 » Wed Jul 25, 2012 3:07 pm

can you tell me what is the right path to display an image.

remember it is not only one page it is a pic for each topic
mostafa581
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jul 10, 2012 3:53 pm

Re: need your help to retrieve images

Postby kyle04 » Thu Jul 26, 2012 2:26 pm

It depends how the image information is stored.
the most efficient would be to have the image path stored as a field in you db table, say "topic_image" , in the format topicimage.jpg .
If the images are stored in the directory www.domain.com/images :

so the retrieve the image for that page :

$img = "images/".$row['topic_image'];

echo "<img src=\"$img\">";

which would translate to : <img src="images/topicimage.jpg">
kyle04
New php-forum User
New php-forum User
 
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: need your help to retrieve images

Postby mostafa581 » Fri Jul 27, 2012 5:16 pm

i tried it but it did not work too

i made a page called getimage.php with the following code

<body>
<?php
include ("config.php");
$id=addslashes(@$_REQUEST['id']);
$image= mysql_query ("SELECT photo FROM tourisn_news Where id=$id");
$image = mysql_fetch_assoc($image);
$image= $image22['photo'];
header("content-type:image/jpeg");
echo $image;
?>
</body>

how can this help ?
mostafa581
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jul 10, 2012 3:53 pm

Re: need your help to retrieve images

Postby kyle04 » Sat Jul 28, 2012 2:09 pm

Same variable name being used for different variables :

$image= mysql_query ("SELECT photo FROM tourisn_news Where id=$id");
$image = mysql_fetch_assoc($image);
$image= $image22['photo'];
header("content-type:image/jpeg");
echo $image;


1) $image= mysql_query ("SELECT ......
You've chosen "$image" as your query name

2 $image = mysql_fetch_assoc($image);
should be like :
$row = mysql_fetch_assoc($image);

3) $image= $image22['photo'];
should be :
$this_image= $row['photo'];


echo <img src=\"$this_image\">;
kyle04
New php-forum User
New php-forum User
 
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: need your help to retrieve images

Postby abubacker » Wed Aug 01, 2012 10:18 pm

gud
abubacker
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Aug 01, 2012 9:43 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.