c_shelswell Posted November 14, 2006 Share Posted November 14, 2006 Hi i have this problem. I'm taking data from a mysql table and trying to output it formatted on my webpage. This is easy enough what i'm really stuck on is that i have many items and i want the first 3 to be formatted one way and the rest to appear a different way.the data to be formatted is taken from a function in a seperate file. I've basically got foreach ($media_array as $row){i want it to be (basically) [b]"foreach ($media_array as $row '[i]until the point i tell it to stop[/i]')"[/b] any ideas would be great thanks the whole code is below.function display_bundles($media_array, $logImgUrl, $logUrl){ ?> <table width="80%" border=0> <tr> <td align="center"><h2>Featured Bundles</h2></td> <td> </td> <td align="right"> <a href="<?php echo $logUrl ?>"><img src="<?php echo $logImgUrl ?>" border=0/></a> <a href="./show_cart.php"><img src="../images/checkout.jpg" border=0/> </td> </tr><?php if(!is_array($media_array)) { echo 'No bundles currently available'; return; } foreach ($media_array as $row) { $url = 'cart_add.php?media_id='.($row['media_id']).'&pic='.($row['picture']); $title = $row['title']; $pic = $row['picture']; echo '<tr><td align="center">'; // Displays and halfs actual image size the prints data if (@file_exists('./images/'.$pic.'')) { $size = GetImageSize('./images/'.$pic.''); if ($size[0]>0 && $size[1]>0) { echo '<img src="./images/'.$pic.'" width = '.$size[0]/2 .' height = '.$size[1]/2 .' /></td>'; echo '<td><div id="desc">'.$row['title'].'</div></td>'; echo '<td><div id="desc">'.$row['description'].'</div>'; echo '<br /><div id="price">Price £'.$row['price'].'</div>'; echo '<div id="buy_but">'; display_button ($url, 'buy', 'add to cart'); echo '</div></td>'; echo '</tr>'; } } } } Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 14, 2006 Share Posted November 14, 2006 Rather than using a foreach(), just us a for() with your control numbers in it:[code]<?phpfor ($i = 0; $i < 3; $i++) { $row = $media_array[$i]; // display your first three here}// now, everything that's left is your default display:for ($i = 3; $i < count($media_array); $i++) { $row = $media_array[$i]; // display here}?>[/code]Hope this helps Quote Link to comment Share on other sites More sharing options...
c_shelswell Posted November 14, 2006 Author Share Posted November 14, 2006 brilliant thanks so much. I was trying to use a for statment too but it was the $row thing i was making a mess of. Couildn't get anything to display. I'll try this way.Thanks again Quote Link to comment 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.