Jump to content


Photo

Having troubles - image does not show up.


  • Please log in to reply
2 replies to this topic

#1 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 07 March 2006 - 10:33 PM

Hello, I am trying to write a script that will allow the user to view vendors, select their name, hit the view button and see their image. I have everything done accept the image does'nt show up in the browser.

[a href=\"http://www.uswebproducts.com/country_savings/view_coupon.php\" target=\"_blank\"]Click here to view[/a]

The script is below, If someone can tell me where I went wrong, I would appreciate it.

<?php
echo "Testing the view_coupon.php page!";
include ('connections/mysql_connect.php');
if (!isset($_POST['submit'])) {
echo "<form method='post' action='view_coupon.php'>
<select name='vendor_id'>
<option>- Please select one -</option>\n";
$qry = mysql_query("SELECT * FROM vendors;");
while($rows = mysql_fetch_assoc($qry)) {
echo "<option value='".$rows['vendor_id']."'>".$rows['vendor_name']."</option>\n";
}
echo "</select>
<input name='submit' type='submit' value='View'>
</form>";
}else{

if (isset($_POST['submit'])) {
$image_query ="SELECT file_name FROM uploads
WHERE uploads.vendor_id = ('".$_POST['vendor_id']."');";
$result = mysql_query($image_query);
$record = mysql_fetch_row($result);
echo "<table align='center' width='90%'>
<tr>
<td><img src='http://uswebproducts.com/country_savings/uploads/$record'>
</td>
</tr>
</table>";
}
}

?>


#2 dcro2

dcro2
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts

Posted 07 March 2006 - 10:53 PM

[!--quoteo(post=352656:date=Mar 7 2006, 05:33 PM:name=sjones)--][div class=\'quotetop\']QUOTE(sjones @ Mar 7 2006, 05:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$record = mysql_fetch_row($result);
//...
<td><img src='http://uswebproducts.com/country_savings/uploads/$record'>
[/quote]
mysql_fetch_row returns an array, that's why the image displayed is:
"http://uswebproducts.com/country_savings/uploads/Array"
Use $record[0...1...2...etc] according to field order

It would be better to use mysql_fetch_array or mysql_fetch_assoc in your case.

#3 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 08 March 2006 - 01:47 AM

This is the correction that I came up with it works very well. Thanks for the reply

else{
if (isset($_POST['submit'])) {
$image_query ="SELECT file_name FROM uploads
WHERE uploads.vendor_id = ('".$_POST['vendor_id']."');";
$result = mysql_query($image_query);
while ($record = mysql_fetch_row($result)) {
for ($i = 0; $i < count($record); $i++) {
echo "<table align='center' width='90%'>
<tr>
<td><img src='http://uswebproducts.com/country_savings/uploads/$record[$i]'>
</td>
</tr>
</table>";
}
}
}
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users