GD_GRAY
asked on
How can I get a query to only echo rows if it has data
How can i get the query to echo rows only if it has data. in the script below I have it echo the results for lineitem1, but in some case if the table has data for lineitem2 I want to echo it as well but I dont want the results to fill the page with empty rows . How would I tell it to echo only rows with data and not the other.
$unit = $_POST['unit'];
$result = mysql_query("SELECT * FROM workorder WHERE wo_unit='$unit' ORDER BY wo_status, wo_hub DESC;");
echo "<table border='1'>
<tr>
<th>W/O Number</th>
<th>Unit</th>
<th>Date</th>
<th>Hub</th>
<th>Description</th>
<th>Notes</th>
<th>Status</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['wo_number'] . "</td>";
echo "<td>" . $row['wo_unit'] . "</td>";
echo "<td>" . $row['wo_date'] . "</td>";
echo "<td>" . $row['wo_hub'] . "</td>";
echo "<td>" . $row['lineitem1'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['wo_status'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh wait, I am not sure you can check what is in the field $row['lineitem1'] at the same time you are getting the results. You might have to make it be another if statement inside the while loop
while($row = mysql_fetch_array($result))
{
if ($row['lineitem1'] !="") {
echo "<tr>";
echo "<td>" . $row['wo_number'] . "</td>";
echo "<td>" . $row['wo_unit'] . "</td>";
echo "<td>" . $row['wo_date'] . "</td>";
echo "<td>" . $row['wo_hub'] . "</td>";
echo "<td>" . $row['lineitem1'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['wo_status'] . "</td>";
echo "</tr>";
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was never able to get any of this to work. but thanks for your help.
ASKER
workorder number date hub notes
Description | | | |
workorder number date hub notes
Description | | | |
workorder number date hub notes
Description | | | |