In php working with mysql, how can I output two columns values only once, and then loop thru the others.
Here:
$exe_fetch_data = mysql_query("select category, subcategory, title, body, views from table");
while($row = mysql_fetch_array($exe_fetch_data))
echo $row['category']; //Only once
echo $row['subcategory']; //Only once
{
echo $row['title'];
echo $row['body'];
echo $row['views'];
}
Desired output:
Category->SubCategory //Outputted only once
Title, //Title Body and Views depend on whatever's there in the db. Could be 10 or more
Body,
Views
Title,
Body,
Views
Title,
Body,
Views
This code shoud do the trick
You could also try using a flag whose value is initially
trueand will turnfalseafter first iteration.But I think above code will be faster than using a flag as it wont compare/check flag value after each iteration and with a huge database it will save execution time.