reckoelyk Posted January 10, 2010 Share Posted January 10, 2010 Okay, I've been trying to do this for a while, and I'm finally going to ask for help so I can get the simple answer and feel like an idoit . Anyway, I'm building a dynamic driver profile page for my NASCAR website. I have sections for hometown, driver website, spouse, etc. This is all displayed down the side of the page. However, if there is a single driver that has no spouse, there is still an area where the Spouse label is displayed when it is on the website. Each page has labels going down for each field in the MySql table. These show when the MySql database is queried. Hopefully that makes since? Anyway, here is what I have tried and all it does is break the page. <?php // Connects to your Database mysql_connect("BLAH BLAH BLAH", BLAH BLAH BLAH", "BLAH BLAH BLAH") or die(mysql_error()); mysql_select_db("BLAH BLAH BLAH") or die(mysql_error()); $data = mysql_query("SELECT * FROM `BLAH BLAH BLAH` WHERE `BLAH BLAH BLAH` = 'BLAH BLAH BLAH'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { if (".$info['spouse']."=="") {echo "None";} else {echo "Spouse: ".$info['spouse'] . "";} } ?> Any help is really, really, really, really appreciated. Link to comment https://forums.phpfreaks.com/topic/187912-php-if-in-mysql-query-hiding-labels-if-a-field-is-empty/ Share on other sites More sharing options...
mmarif4u Posted January 10, 2010 Share Posted January 10, 2010 Try this: <?php // Connects to your Database mysql_connect("BLAH BLAH BLAH", BLAH BLAH BLAH", "BLAH BLAH BLAH") or die(mysql_error()); mysql_select_db("BLAH BLAH BLAH") or die(mysql_error()); $data = mysql_query("SELECT * FROM `BLAH BLAH BLAH` WHERE `BLAH BLAH BLAH` = 'BLAH BLAH BLAH'") or die(mysql_error()); while($info = mysql_fetch_array($data)) { if ($info['spouse'] == "") {echo "None";} else {echo "Spouse: ".$info['spouse'];} } ?> When you run your code, did you get any error? Link to comment https://forums.phpfreaks.com/topic/187912-php-if-in-mysql-query-hiding-labels-if-a-field-is-empty/#findComment-992182 Share on other sites More sharing options...
reckoelyk Posted January 10, 2010 Author Share Posted January 10, 2010 Try this: <?php // Connects to your Database mysql_connect("BLAH BLAH BLAH", BLAH BLAH BLAH", "BLAH BLAH BLAH") or die(mysql_error()); mysql_select_db("BLAH BLAH BLAH") or die(mysql_error()); $data = mysql_query("SELECT * FROM `BLAH BLAH BLAH` WHERE `BLAH BLAH BLAH` = 'BLAH BLAH BLAH'") or die(mysql_error()); while($info = mysql_fetch_array($data)) { if ($info['spouse'] == "") {echo "None";} else {echo "Spouse: ".$info['spouse'];} } ?> When you run your code, did you get any error? Thanks a bunch! With my code, it either did nothing, showed the field regardless, or stopped the page from loading. This is exactly what I needed it to do, thanks again! Link to comment https://forums.phpfreaks.com/topic/187912-php-if-in-mysql-query-hiding-labels-if-a-field-is-empty/#findComment-992352 Share on other sites More sharing options...
mmarif4u Posted January 10, 2010 Share Posted January 10, 2010 You are most welcome mate.. And yeh please mark the thread as solved. Link to comment https://forums.phpfreaks.com/topic/187912-php-if-in-mysql-query-hiding-labels-if-a-field-is-empty/#findComment-992363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.