dazzclub Posted March 24, 2009 Share Posted March 24, 2009 Hi guys and girls Im echoing a row of data, but there is one row i would like to be displayed just once. What i am doing is displaying a table of information on a particular product. As each product can have loads of parts but only one specification see http://www.hallcrest.com/subcatindust.cfm?cat_id=68&sublvl_id=6&subcat_id=15 Refer to table just below the product image. here is the entire code i am working with function getIndustrialProducts() { if ((isset($_GET['medical_product'])) && (isset($_GET['subcat_id'])) && (is_numeric($_GET['medical_product'])) && (is_numeric($_GET['subcat_id']))) { //correctly accessed $medical_product=$_GET['medical_product']; $subcat_id=$_GET['subcat_id']; } else { $errors[] = 'You have accessed this page incorrectly.'; } global $dbc; $query ="SELECT * FROM industrialproducts WHERE CategoryID = $medical_product AND SubCatID = $subcat_id ORDER BY ChartTypeNum, ProdNum"; $result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query"); while ($row = mysqli_fetch_assoc($result)) { //need to format the date on this function //get NewsID echo " <tr> <td>$row[ProdNum]</td> <td>$row[PartNum]</td> <td>$row[ProdRangeF]</td> <td>$row[ProdRangeC]</td> <td colspan=\"5\">$row[ProdSpec]</td> </tr>"; } } What i would like is to set a limit on <td colspan=\"5\">$row[ProdSpec]</td> Is there a function i can wrap around that row so it only echo's once? Regards Darren Quote Link to comment https://forums.phpfreaks.com/topic/150884-solved-fetch-row-of-data-but-set-one-to-a-limit-of-1/ Share on other sites More sharing options...
lonewolf217 Posted March 24, 2009 Share Posted March 24, 2009 <?php function getIndustrialProducts() { if ((isset($_GET['medical_product'])) && (isset($_GET['subcat_id'])) && (is_numeric($_GET['medical_product'])) && (is_numeric($_GET['subcat_id']))) { //correctly accessed $medical_product=$_GET['medical_product']; $subcat_id=$_GET['subcat_id']; } else { $errors[] = 'You have accessed this page incorrectly.'; } global $dbc; $query ="SELECT * FROM industrialproducts WHERE CategoryID = $medical_product AND SubCatID = $subcat_id ORDER BY ChartTypeNum, ProdNum"; $result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query"); $prevSpec = ""; //initialize variable while ($row = mysqli_fetch_assoc($result)) { //need to format the date on this function //get NewsID echo " <tr> <td>$row[ProdNum]</td> <td>$row[PartNum]</td> <td>$row[ProdRangeF]</td> <td>$row[ProdRangeC]</td> "; //end the echo if(!($row['ProdSpec']==$prevSpec)) { echo "<td colspan=\"5\">$row[ProdSpec]</td>"; } else { echo "<td colspan=\"5\"></td>"; } echo "</tr>"; $prevSpec = $row['ProdSpec']; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150884-solved-fetch-row-of-data-but-set-one-to-a-limit-of-1/#findComment-792644 Share on other sites More sharing options...
wildteen88 Posted March 24, 2009 Share Posted March 24, 2009 If you want the specification field to span all the rows, change your while loop to $rows = mysqli_num_rows($result); $i = 0; while ($row = mysqli_fetch_assoc($result)) { //need to format the date on this function //get NewsID echo "\n <tr> <td>$row[ProdNum]</td> <td>$row[PartNum]</td> <td>$row[ProdRangeF]</td> <td>$row[ProdRangeC]</td>\n"; if($i == 0) echo "<td rowspan=\"$rows\" valign=\"top\">$row[ProdSpec]</td>\n"; echo "</tr>\n"; $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/150884-solved-fetch-row-of-data-but-set-one-to-a-limit-of-1/#findComment-792651 Share on other sites More sharing options...
dazzclub Posted March 24, 2009 Author Share Posted March 24, 2009 Thank you lonewolf217! and wildteen88 Quote Link to comment https://forums.phpfreaks.com/topic/150884-solved-fetch-row-of-data-but-set-one-to-a-limit-of-1/#findComment-792686 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.