Jump to content

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

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.