Jump to content

[SOLVED] help


westminster86

Recommended Posts

 

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?

Link to comment
https://forums.phpfreaks.com/topic/84864-solved-help/
Share on other sites

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 />';
}

Link to comment
https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432632
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432648
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/84864-solved-help/#findComment-432652
Share on other sites

Archived

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

×
×
  • Create New...

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.