westminster86 Posted January 7, 2008 Share Posted January 7, 2008 The script provides a link to each product in a category. Each link is suffixed with a parameter. This time around, its the productid for the product in question. im having trouble retrieving images of the server. if (file_exists('images/'.$row['productid'].'.jpg')) The directory is... /htdocs/images any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/ Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 Can we see some more code? In particular, where does the $row array get created? Don't foget the tags! Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432618 Share on other sites More sharing options...
westminster86 Posted January 7, 2008 Author Share Posted January 7, 2008 Can we see some more code? In particular, where does the $row array get created? Don't foget the tags! function get_products($catid) { // query database for the products in a category if (!$catid || $catid=='') return false; @ $db = mysql_connect(''); mysql_select_db(''); $query = "select * from products where catid = $catid"; $result = mysql_query($query); if (!$result) return false; $num_products = mysql_num_rows($result); if ($num_products ==0) return false; $result = db_result_to_array($result); return $result; } function db_result_to_array($result) { $res_array = array(); for ($count=0; $row = mysql_fetch_assoc($result); $count++) $res_array[$count] = $row; return $res_array; } function display_products($product_array) { // display all products in the array passed in if (!is_array($product_array)) { echo '<br />No products currently available in this category<br />'; } else { echo '<table border = "0" width = "30%">'; // create a table row for each product foreach ($product_array as $row) { $url = 'showProduct.php?productid='.($row['productid']); echo '<tr><td>'; if (file_exists('images/'.$row['productid'].'.jpg')) { $size = GetImageSize('images/'.$row['productid'].'.jpg'); if ($size[0]>0 && $size[1]>0) { $image = '<img src=\'images/'.($row['productid']).'.jpg\' border = 0 width = '. $size[0]/4 .' height = '. $size[1]/4 .' />'; do_html_url($url, $image); } } else { echo ' '; } echo '</td><td>'; $name = $row['name']; $price = $row['price']; do_html_url($url, $name); echo 'Price: £'.$row['price']; echo '</td></tr>'; } echo '</table>'; } echo '<hr />'; } Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432632 Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 You forgot the tags. Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432633 Share on other sites More sharing options...
westminster86 Posted January 7, 2008 Author Share Posted January 7, 2008 You forgot the tags. my bad Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432635 Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 $image = '<img src=\'images/' . $row['productid'] . '.jpg\' border = 0 width = '. $size[0]/4 .' height = '. $size[1]/4 .' />'; Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432640 Share on other sites More sharing options...
westminster86 Posted January 7, 2008 Author Share Posted January 7, 2008 $image = '<img src=\'images/' . $row['productid'] . '.jpg\' border = 0 width = '. $size[0]/4 .' height = '. $size[1]/4 .' />'; still nothing. Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432643 Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 $query = "select * from products where catid = '$catid'"; Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432646 Share on other sites More sharing options...
trq Posted January 7, 2008 Share Posted January 7, 2008 Breaking your code into all these small functions really just makes things more diificult to debug escpecially when it hasn't really inhanced any reusability. You going to need to at least try some debugging to find out which function is failing. is your query failing? I don't see your calling code. Are you checking get_products() has returned true prior to trying to use its result? Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432648 Share on other sites More sharing options...
westminster86 Posted January 7, 2008 Author Share Posted January 7, 2008 Breaking your code into all these small functions really just makes things more diificult to debug escpecially when it hasn't really inhanced any reusability. You going to need to at least try some debugging to find out which function is failing. is your query failing? I don't see your calling code. Are you checking get_products() has returned true prior to trying to use its result? Theres nothing wrong with the coding. Previously id stored the images in the cgi-bin directory along with my scripts. However the directory was getting clattered, so i created a new directory called images. The directory holds the appropriate images. So the line if(file_exists) is the issue. I had no problems before hand, the images were retrieving. Quote Link to comment https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432652 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.