Query output
Posted: Sat Feb 23, 2008 12:05 am
Hi guys, I'm new at php/mysql and im trying to fetch 2 fields of 10 rows of data. And I want to output the first 5 with the 2 fields and then the last 5 with just one field.
So it will look like this for the first 5
New Items in stock..
Product
Description
Product
Description
Then I want to put this for the next 5 products
Also now in stock..
Product
Product
Product
I have a basic script I been trying to work it out on but I have not had any luck. Would anyone be able to help me out or even point me in the direction of some tutorials that shows this.
Thanks
Bradley
So it will look like this for the first 5
New Items in stock..
Product
Description
Product
Description
Then I want to put this for the next 5 products
Also now in stock..
Product
Product
Product
I have a basic script I been trying to work it out on but I have not had any luck. Would anyone be able to help me out or even point me in the direction of some tutorials that shows this.
Code: Select all
<?php
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
('Error connecting to mysql');
$dbname = '';
mysql_select_db($dbname);
$query = 'SELECT *FROM `products` ORDER BY `products`.`ID` ASC';
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo "{$row['product_title']} <br>" .
"{$row['description']} <br><br>";
}
mysql_close($conn);
?>Bradley