fxuup Posted January 22, 2012 Share Posted January 22, 2012 I'm trying to echo data from phpMyadmin, but i want it to only echo data that doesn't have a blank space. view the image below please. I'm trying to display the data but i don't want to display the empty data either. If anyone has any ideas on how i could do this it would be greatly appreciated. My code is below. Thank you. <div id="content"> <h2>Inventory</h2> <form name="weapons" method="POST" action="<?php echo $_SERVER['php_self']; ?>"> <br> <? $swords = $_POST['weapons']; if(!empty($swords)){ echo "You equipped a " .$swords; $set = "UPDATE `users` SET `weapon` = '$swords' WHERE `username`='$username'"; mysql_query($set); } echo ' <table border="0" id="text"> <tr> <td width="235px" id="text2"> Swords </td> </table> '; ?> <table border="0" id="text3"> <? $display = mysql_query("SELECT `swords` FROM `inventory` WHERE `username`='$username'"); while($rowz = mysql_fetch_array($display)) { echo ' <tr> <td id="text3"> <input type="radio" name="swords" size="1" value="' .$rowz['swords']. '">' .$rowz['swords']. '<br> </td> </tr> '; ?> </table> <br> <input type="submit" name="submit" value="Equip"> <br> <? $bows = $_POST['bows']; if(!empty($bows)){ echo "You equipped a " .$bows; $set2 = "UPDATE `users` SET `weapon` = '$bows' WHERE `username`='$username'"; mysql_query($set2); } echo ' <table border="0" id="text"> <tr> <td width="235px" id="text2"> Axes </tr> </table> '; ?> <table border="0" id="text3"> <? $display2 = mysql_query("SELECT `axes` FROM `inventory` WHERE `username`='$username'"); while($rowzz = mysql_fetch_array($display2)) { echo ' <tr> <td id="text3"> <input type="radio" name="axes" size="1" value="' .$rowzz['axes']. '">' .$rowzz['axes']. '<br> </td> </tr> '; } ?> </table> <br> <input type="submit" name="submit" value="Equip"> <br> </div> Quote Link to comment https://forums.phpfreaks.com/topic/255537-php-displaying-blanks/ Share on other sites More sharing options...
ManiacDan Posted January 22, 2012 Share Posted January 22, 2012 Inside your while loops, check to see if the value. if it's empty, don't echo. Quote Link to comment https://forums.phpfreaks.com/topic/255537-php-displaying-blanks/#findComment-1310099 Share on other sites More sharing options...
fxuup Posted January 22, 2012 Author Share Posted January 22, 2012 I was thinking something like that but how would i go about that? can you give me an example maybe? Quote Link to comment https://forums.phpfreaks.com/topic/255537-php-displaying-blanks/#findComment-1310134 Share on other sites More sharing options...
jcbones Posted January 23, 2012 Share Posted January 23, 2012 while($rowzz = mysql_fetch_array($display2)) { if(!empty($rowzz['axes'])) { echo ' <tr> <td id="text3"> <input type="radio" name="axes" size="1" value="' .$rowzz['axes']. '">' .$rowzz['axes']. '<br> </td> </tr> '; } } Quote Link to comment https://forums.phpfreaks.com/topic/255537-php-displaying-blanks/#findComment-1310206 Share on other sites More sharing options...
PFMaBiSmAd Posted January 23, 2012 Share Posted January 23, 2012 Your database table is laid out like a spreadsheet. That wastes storage, takes more code, and more complicated queries to manage or retrieve the data. The inventory table should only have id, user_id, and weapon_id columns (and perhaps a quantity column if you can have more than one of each weapon.) You should have a separate table that holds the definition of all the weapons. It would have the id, type, and name (and any other characteristics for each weapon.) The inventory table would only have rows for actual weapons in the inventory. When a user adds a weapon to his inventory, you would add a row to the inventory table (or increase his quantity of that weapon if he can have more than one and he already has at least one.) When a user looses/uses a weapon, you would delete the row for that weapon (or decrease his quantity of the weapon if he had more than one to start with.) Doing this will save a TON of code. All the repeated code you posted, that only varies in the weapon type, can be replaced by one query and a loop that outputs the appropriate weapon type heading every time the weapon type changes. Quote Link to comment https://forums.phpfreaks.com/topic/255537-php-displaying-blanks/#findComment-1310211 Share on other sites More sharing options...
fxuup Posted January 23, 2012 Author Share Posted January 23, 2012 Thank you guys very much! Im only a amature when it comes to PHP, HTML, and MySQL coding. Ive been coding for about 4 months now. PFMaBiSmAd so your saying in the inventory it should put quantities instead of the weapons so like the top would say DAGGER and the values with be 2 as i have two daggers? Quote Link to comment https://forums.phpfreaks.com/topic/255537-php-displaying-blanks/#findComment-1310307 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.