Jump to content

Formatting mysql data output


c_shelswell

Recommended Posts

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>&nbsp;</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>';

}
}

}

}
Link to comment
Share on other sites

Rather than using a foreach(), just us a for() with your control numbers in it:
[code]
<?php
for ($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
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.