Jump to content

Need help to modify php ELSE code


bgbs

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

pic1.png

 

The Second pic shows what the empty box, with no inventory, looks like right now.

pic2.png

 

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. 

pic3.png

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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";
                      }
                    ?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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