Jump to content

displaying


westminster86

Recommended Posts

i have a page that displays images acording to what category the user has selected. However, the images are being displayed in a single column...so one underneath the other. how can i display the images for instance showing 4 across the page and another 4 underneath and so on. And how do i show say only 12 images per page. heres the current coding..

 

 

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($row['productid'].'.jpg'))

    { 

      $size = GetImageSize($row['productid'].'.jpg');

      if ($size[0]>0 && $size[1]>0)

      {

        $image = '<img src="'.($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
Share on other sites

Could i also use a for loop to do this? because im getting the results directly from an array. Im just getting the same outputs as i ddi before even though im using a counter

Or a while loop, which would probably be better.

 

Hint: You can use modulo which may or may not help you depending on whether or not you know how to utilize it.

Link to comment
Share on other sites

Could i also use a for loop to do this? because im getting the results directly from an array. Im just getting the same outputs as i ddi before even though im using a counter

Or a while loop, which would probably be better.

 

Hint: You can use modulo which may or may not help you depending on whether or not you know how to utilize it.

 

nah i dnt... so ill give that one a miss.. thanks ill try with a while loop

Link to comment
Share on other sites

Could i also use a for loop to do this? because im getting the results directly from an array. Im just getting the same outputs as i ddi before even though im using a counter

Or a while loop, which would probably be better.

 

Hint: You can use modulo which may or may not help you depending on whether or not you know how to utilize it.

 

nah i dnt... so ill give that one a miss.. thanks ill try with a while loop

 

i havent stored my images in the database, ive just uploaded them to the server does that matter?

Link to comment
Share on other sites

i havent stored my images in the database, ive just uploaded them to the server does that matter?

It probably doesn't matter, but then again, I'm not 100% sure I know what you're doing.

 

im trying to display images on the webpage, which i have working but i want to change the layout. there currently being displayed one underneath the other in a single colum. ive stored the images on the server.

Link to comment
Share on other sites

i havent stored my images in the database, ive just uploaded them to the server does that matter?

It probably doesn't matter, but then again, I'm not 100% sure I know what you're doing.

 

im trying to display images on the webpage, which i have working but i want to change the layout. there currently being displayed one underneath the other in a single colum. ive stored the images on the server.

 

can someone help me out because ive been trying to change my coding around to the post that thorpe posted but im nt getting nehwre

Link to comment
Share on other sites

Post your current code.

 

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($row['productid'].'.jpg'))

    { 

      $size = GetImageSize($row['productid'].'.jpg');

      if ($size[0]>0 && $size[1]>0)

      {

        $image = '<img src="'.($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 />';

}

 

thats displaying them in a single colum with the product name a url and the price of the item underneath the item

Link to comment
Share on other sites

Post your current code.

 

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($row['productid'].'.jpg'))

    { 

      $size = GetImageSize($row['productid'].'.jpg');

      if ($size[0]>0 && $size[1]>0)

      {

        $image = '<img src="'.($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 />';

}

 

thats displaying them in a single colum with the product name a url and the price of the item underneath the item

 

because the indices in the array are not numbers, i cant use a counter so how can i use a for loop?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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