Jump to content

[SOLVED] fetch row of data but set one to a limit of 1


dazzclub

Recommended Posts

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

<?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'];

}
}
?>

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++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.