bgbs Posted October 7, 2009 Share Posted October 7, 2009 I'm trying to find a way to have the php code display a message if there is no inventory listed in the box, I just want it to say something like "User has no inventory listed" You can see the actual box http://modern-wireless-inc.wassociation.com titled Inventory Wizard. Its on the right. I want all the content in the box disappear if there is nothing in the inventory and only display the message. Is it hard to do? <?PHP if (!$item) { ?> <div class="account-left-column"><div><img src="images/account-left-column-back-top.gif" alt="" /></div> <div class="account-left-column-header">Inventory Wizard Items</div> <div class="account-left-column-content"> <form action="search.php" method="get" > <p>Search <?PHP echo $vuser->co_name; ?> Inventory:</p> <input type="text" name="q" size="30" maxlength="250" accesskey="S" /> <input name="Submit" type="submit" class="button" value="SEARCH" /> <input name="onlyinventory" type="hidden" value="yes" /> <input name="searchuserid" type="hidden" value="<?PHP echo $v_id; ?>" /> </form> <table width="260" align="left" cellpadding="2" cellspacing="2"> <tr> <td colspan="6" align="left" valign="top"> <p>Last 10 inventory items added:</p> </td> </tr> <tr> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"><strong>Category</strong></td> <td align="left" valign="top"><strong>Model</strong></td> <td align="left" valign="top"><strong>Description</strong></td> </tr> <?php } $inventories = $db->get_results("SELECT id,category,brand,model,description,qty,price,price_negotiable,picture_1,picture_2,inventory_timestamp FROM inventory where user_id in ($allempids) and status = 'active' order by id desc limit 10 "); if ($inventories) { foreach ( $inventories as $invt ) { $selected_category_phone = ""; $selected_category_accessory = ""; $selected_category_parts = ""; if ($invt->category == "phone"){$selected_category_phone = ' selected="selected" '; } if ($invt->category == "accessory"){$selected_category_accessory = ' selected="selected" '; } if ($invt->category == "parts"){$selected_category_parts = ' selected="selected" '; } if (!$item) { $invt->description = substr($invt->description,0,25); ?> <tr onmouseover="this.bgColor='#f1f0f0'" onmouseout="this.bgColor='#FFFFFF'"> <td align="left" valign="top"> <?PHP echo $invt->category; ?> </td> <td align="left" valign="top"> <?PHP echo $invt->model; ?></td> <td align="left" valign="top"> <a href="inventory.php?view_id=<?PHP echo $v_id; ?>&item=<?PHP echo $invt->id; ?>"> <?PHP echo $invt->description; ?>...</a></td> </tr> <?php } else { ?> <?php } } } ?> </table> <div class="account-button"><a href="inventory.php?view_id=<?PHP echo $v_id; ?>">See All Inventory</a></div></div> <!-- end of .account-left-column --> <div><img src="images/account-left-column-back-bottom.gif" alt=""/></div></div> Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/ Share on other sites More sharing options...
Paystey Posted October 7, 2009 Share Posted October 7, 2009 If I'm not mistaken you have if (!$item) {. this will will run the code below it if there is no item. Change to if ($item) and see if that does it. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-932520 Share on other sites More sharing options...
bgbs Posted October 7, 2009 Author Share Posted October 7, 2009 if I do that then it makes the whole block dissapear, but when the person has inventory listed, it just dumps it without block and styling. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-932525 Share on other sites More sharing options...
Paystey Posted October 7, 2009 Share Posted October 7, 2009 Ahh! then it would be this piece which is outputting your data? <td align="left" valign="top"> <a href="inventory.php?view_id=<?PHP echo $v_id; ?>&item=<?PHP echo $invt->id; ?>"> <?PHP echo $invt->description; ?>...</a></td> If so, change it too: <td align="left" valign="top"> <?php if($item) { ?> <a href="inventory.php?view_id=<?PHP echo $v_id; ?>&item=<?PHP echo $invt->id; ?>"> <?PHP echo $invt->description; ?>...</a> <?php } ?> </td> This way the <td> is still generated, and therefore formatted. While the code which dumps out your values is only ran if there is a value in the variable. You can also remove the other large if statement with the if(!$item). Unless you know for certain you need it (I'm pretty sure you don't). Any good? Remembeer to click solved if it has been. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-932529 Share on other sites More sharing options...
bgbs Posted October 8, 2009 Author Share Posted October 8, 2009 Hello Paystey, I appreciate you taking the time with this issue. Its still not working, what it does it just removes data for the description column from the user who has inventory, the other user's who dont have inventory are not effected. I hope I described what I'm trying to accomplish here correctly. Here are the Three image examples. First Image is displaying the "Inventory Wizard" correctly, no issues here. The Second pic shows what the empty box, with no inventory, looks like right now. The third pic shows the example of what I would like it to look like when there is no inventory listed Just the box with one simple message. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-933369 Share on other sites More sharing options...
Paystey Posted October 9, 2009 Share Posted October 9, 2009 In that case then you need to put the top of the if statement just below: <div class="account-left-column-header">Inventory Wizard Items</div> if ($items){ and put the else just here: <div class="account-button"><a href="inventory.php?view_id=<?PHP echo $v_id; ?>">See All Inventory</a></div> } else { echo "User has no Inventory"; } </div> Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-933683 Share on other sites More sharing options...
bgbs Posted October 9, 2009 Author Share Posted October 9, 2009 I think I'm doing something wrong. I get a parse error when I add your code, and I think that is because the if and else statement should be included in one php bracket but I have other php code inside it and so that causes a mix up and gives me another parse error. Let me show you how I placed your code, and maybe we can go from there to get it properly adjusted. Your code is in purple <div class="account-left-column"><div><img src="images/account-left-column-back-top.gif" alt="" /></div> <div class="account-left-column-header">Inventory Wizard Items</div> <?PHP if (!$item) { ?> <div class="account-left-column-content"> <form action="search.php" method="get" > <p>Search <?PHP echo $vuser->co_name; ?> Inventory:</p> <input type="text" name="q" size="30" maxlength="250" accesskey="S" /> <input name="Submit" type="submit" class="button" value="SEARCH" /> <input name="onlyinventory" type="hidden" value="yes" /> <input name="searchuserid" type="hidden" value="<?PHP echo $v_id; ?>" /> </form> <table width="260" align="left" cellpadding="2" cellspacing="2"> <tr> <td colspan="6" align="left" valign="top"> <p>Last 10 inventory items added:</p> </td> </tr> <tr> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"><strong>Category</strong></td> <td align="left" valign="top"><strong>Model</strong></td> <td align="left" valign="top"><strong>Description</strong></td> </tr> <?php } $inventories = $db->get_results("SELECT id,category,brand,model,description,qty,price,price_negotiable,picture_1,picture_2,inventory_timestamp FROM inventory where user_id in ($allempids) and status = 'active' order by id desc limit 10 "); if ($inventories) { foreach ( $inventories as $invt ) { $selected_category_phone = ""; $selected_category_accessory = ""; $selected_category_parts = ""; if ($invt->category == "phone"){$selected_category_phone = ' selected="selected" '; } if ($invt->category == "accessory"){$selected_category_accessory = ' selected="selected" '; } if ($invt->category == "parts"){$selected_category_parts = ' selected="selected" '; } if (!$item) { $invt->description = substr($invt->description,0,25); ?> <tr onmouseover="this.bgColor='#f1f0f0'" onmouseout="this.bgColor='#FFFFFF'"> <td align="left" valign="top"> <?PHP echo $invt->category; ?> </td> <td align="left" valign="top"> <?PHP echo $invt->model; ?></td> <td align="left" valign="top"> <a href="inventory.php?view_id=<?PHP echo $v_id; ?>&item=<?PHP echo $invt->id; ?>"> <?PHP echo $invt->description; ?>...</a></td> </tr> <?php } else { ?> <?php } } } ?> </table> <div class="account-button"><a href="inventory.php?view_id=<?PHP echo $v_id; ?>">See All Inventory</a></div> <?php } else { echo "User has no Inventory"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-933836 Share on other sites More sharing options...
lemmin Posted October 9, 2009 Share Posted October 9, 2009 Your HTML is messed up because you are not ending divs. Try something like this: <div class="account-left-column"><div><img src="images/account-left-column-back-top.gif" alt="" /></div> <div class="account-left-column-header">Inventory Wizard Items</div> <?PHP if (!$item) { echo "User has no items"; } else { ?> <div class="account-left-column-content"> <form action="search.php" method="get" > <p>Search <?PHP echo $vuser->co_name; ?> Inventory:</p> <input type="text" name="q" size="30" maxlength="250" accesskey="S" /> <input name="Submit" type="submit" class="button" value="SEARCH" /> <input name="onlyinventory" type="hidden" value="yes" /> <input name="searchuserid" type="hidden" value="<?PHP echo $v_id; ?>" /> </form> <table width="260" align="left" cellpadding="2" cellspacing="2"> <tr> <td colspan="6" align="left" valign="top"> <p>Last 10 inventory items added:</p> </td> </tr> <tr> <td colspan="3" align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"><strong>Category</strong></td> <td align="left" valign="top"><strong>Model</strong></td> <td align="left" valign="top"><strong>Description</strong></td> </tr> <?php } $inventories = $db->get_results("SELECT id,category,brand,model,description,qty,price,price_negotiable,picture_1,picture_2,inventory_timestamp FROM inventory where user_id in ($allempids) and status = 'active' order by id desc limit 10 "); if ($inventories) { foreach ( $inventories as $invt ) { $selected_category_phone = ""; $selected_category_accessory = ""; $selected_category_parts = ""; if ($invt->category == "phone"){$selected_category_phone = ' selected="selected" '; } if ($invt->category == "accessory"){$selected_category_accessory = ' selected="selected" '; } if ($invt->category == "parts"){$selected_category_parts = ' selected="selected" '; } if (!$item) { $invt->description = substr($invt->description,0,25); ?> <tr onmouseover="this.bgColor='#f1f0f0'" onmouseout="this.bgColor='#FFFFFF'"> <td align="left" valign="top"> <?PHP echo $invt->category; ?> </td> <td align="left" valign="top"> <?PHP echo $invt->model; ?></td> <td align="left" valign="top"> <a href="inventory.php?view_id=<?PHP echo $v_id; ?>&item=<?PHP echo $invt->id; ?>"> <?PHP echo $invt->description; ?>...</a></td> </tr> <?php } else { ?> <?php } } } ?> </table> <div class="account-button"><a href="inventory.php?view_id=<?PHP echo $v_id; ?>">See All Inventory</a></div> And you need to go down and find where the "accounts-left-column-content" div ends to end the else statement. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-933846 Share on other sites More sharing options...
bgbs Posted October 9, 2009 Author Share Posted October 9, 2009 Yes there was one extra div I had to remove. When you say to end the else statement you mean to do this right? <?PHP } ?> When I do this, it still gives me parse error. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-933923 Share on other sites More sharing options...
Paystey Posted October 10, 2009 Share Posted October 10, 2009 Yep thats the one, just run through the logic and try to understand it, once you can grasp logical statements like those, others will be a sinche. Don't forget to check this as solved. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-934466 Share on other sites More sharing options...
bgbs Posted October 12, 2009 Author Share Posted October 12, 2009 Lemmin's logic seems to work, but all it does is spit table-less data in the block. It disregards all formatting and tables. Your logic, on the other hand does not work for me, no matter how I lay it out. I put: <?PHP if (!$item) { ?> above the <div class="account-left-column-content"> and <?php } else { echo "User has no Inventory"; } ?> in the end of the </div> statement The Result: Parse Error. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-935509 Share on other sites More sharing options...
lemmin Posted October 12, 2009 Share Posted October 12, 2009 It doesn't make sense to display the "User has no inventory" message after writing all the HTML to display inventory data. If you post the entire HTML of that "Inventory Wizard Items" div, I can try to show you exactly where you should be putting the if statements. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-935607 Share on other sites More sharing options...
bgbs Posted October 12, 2009 Author Share Posted October 12, 2009 All I want to do is to do is have the inside block stuff disappear when there is no inventory listed. The images that I pasted above into this topic show exactly what I want the php to do. Your solution kind of does it already, except that when it does show the inventory content it just dumps it without tables and css. Quote Link to comment https://forums.phpfreaks.com/topic/176848-need-help-to-modify-php-else-code/#findComment-935716 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.