Jump to content

Using Value from Database in If Statement


Icewolf
 Share

Recommended Posts

Hi

Can you please help me with an issue I am having? I have three description fields that I am pulling from a database. I did this so when it displays it isn't one long string. However the issue I am running into is if the 3rd description box is empty I do not what to display it. I cant figure out why it is only hitting the first display option. I created this variable $dishdesc3 = $_POST["dish_desc_3"]. I would like to say when it is NULL display the only the first 2 description boxes. Otherwise have it display all three description boxes. Is there  a way to do that?

 

<?php
// Include the database configuration file  
require_once 'con_php.php'; 

//check connection
if ($con -> connect_error){
	die ("connection failed: " . $con -> connect_error);
}


$chsql = "SELECT * FROM dish_pic where cat_name = 'Chicken'";

$chresult = $con ->query($chsql);
$dishdesc3 = $_POST["dish_desc_3"];

if ($chresult-> num_rows >0){
	
	
	while ($row = $chresult -> fetch_assoc()){
		
		
	if ($dishdesc3 = "3")
	{
		echo"<table border='0' cellpadding='4' cellspacing='0' width='100%'>";
		echo" <tr><td class='style1' align='center'  colspan='3' valign='top'>". $row["dish_name"] .".........................$" . $row["price"] . "<br><td></tr>
		<tr>
		<td class='style2' align='center' >" . $row["dish_desc"] . "<br>
		" . $row["dish_desc_2"] . "<br>
		<tr><td class='style3' align='center' >Serving " . $row["dish_size"] . " Calories " . $row["dish_cal"] . " Total Carbs " . $row["dish_tot_carbs"] . " Net Carbs " . $row["dish_net_carbs"] . " Fat " . $row["dish_fat"] . " Fiber " . $row["dish_fiber"] ." Protein " . $row["dish_protein"] . "<br></td></tr>
	  	<tr><td class='style2' align='center' >Recommend Side " . $row["dish_recommend"] . "</td></tr>
		<br>
		";
	echo"</table>";
	}
	  
Else
{
		echo"<table border='0' cellpadding='4' cellspacing='0' width='100%'>";
		echo" <tr><td class='style1' align='center'  colspan='3' valign='top'>". $row["dish_name"] .".........................$" . $row["price"] . "<br><td></tr>
		<tr>
		<td class='style2' align='center' >" . $row["dish_desc"] . "<br>
		" . $row["dish_desc_2"] . "<br>
		" . $row["dish_desc_3"] . "<br></td></tr>
		<tr><td class='style3' align='center' >Serving " . $row["dish_size"] . " Calories " . $row["dish_cal"] . " Total Carbs " . $row["dish_tot_carbs"] . " Net Carbs " . $row["dish_net_carbs"] . " Fat " . $row["dish_fat"] . " Fiber " . $row["dish_fiber"] ." Protein " . $row["dish_protein"] . "<br></td></tr>
	  	<tr><td class='style2' align='center' >Recommend Side " . $row["dish_recommend"] . "</td></tr>
		<br>
		";
	  echo"</table>";
	}
	}
}

$con->close();
?>

 

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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