westminster86 Posted January 6, 2008 Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/ Share on other sites More sharing options...
trq Posted January 6, 2008 Share Posted January 6, 2008 Take a look at this thread in the FAQ/Code snippet library. Link to comment https://forums.phpfreaks.com/topic/84746-displaying/#findComment-431871 Share on other sites More sharing options...
westminster86 Posted January 6, 2008 Author Share Posted January 6, 2008 Take a look at this thread in the FAQ/Code snippet library. 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 Link to comment https://forums.phpfreaks.com/topic/84746-displaying/#findComment-431913 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/#findComment-431915 Share on other sites More sharing options...
westminster86 Posted January 6, 2008 Author Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/#findComment-431923 Share on other sites More sharing options...
westminster86 Posted January 6, 2008 Author Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432061 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432064 Share on other sites More sharing options...
westminster86 Posted January 6, 2008 Author Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432091 Share on other sites More sharing options...
westminster86 Posted January 6, 2008 Author Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432156 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 Post your current code. Link to comment https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432160 Share on other sites More sharing options...
westminster86 Posted January 6, 2008 Author Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432164 Share on other sites More sharing options...
westminster86 Posted January 6, 2008 Author Share Posted January 6, 2008 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 https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432166 Share on other sites More sharing options...
teng84 Posted January 6, 2008 Share Posted January 6, 2008 because the indices in the array are not numbers, i cant use a counter so how can i use a for loop? can you explain this? Link to comment https://forums.phpfreaks.com/topic/84746-displaying/#findComment-432170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.