Icewolf Posted May 9, 2020 Share Posted May 9, 2020 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(); ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted May 9, 2020 Share Posted May 9, 2020 11 minutes ago, Icewolf said: if ($dishdesc3 = "3") That is setting the value to 3, not testing if it is equal to 3. The equality operator is "==" 1 Quote Link to comment 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.