Jump to content

I need help with if/else statements, thanks in advance.


Recommended Posts

$result = $dbh->query($sql);

			if($result)
			{
				$i = 0;
				$max_columns = 3;
				foreach ($result as $row)
				{
					// open row if counter is zero
					if($i == 0)
					{
						echo "<tr VALIGN='top'>";
					}
          // if ($row['avail'] != "0")
          //{
					// make sure we have a valid product ALIGN='CENTER'

					if($row['image'] != "" && $row['image'] != null)
					{
						echo "<td><div class=box><a href=$row[image] rel=lightbox title=$row[image]><img class=border src=$row[image]>";  
            						
						if($row['itemno'] != "" && $row['itemno'] != null)
						{
							echo "<a>Item No: </a>$row[itemno]<br />";
						}
						if($row['description'] != "" && $row['description'] != null)
						{
							echo "<a>Description: </a>$row[description]<br /> ";
						}
						//if($row['sold'] !=1)
							//{
                                   if($row['price'] != "" && $row['price'] != null)
						           {
						             echo "<a>Price: $</a>$row[price]<br />";
									 
									
									echo "<form target='paypal' action='' method='post'>";
									echo "<input type='hidden' name='cmd' value='_cart'>";
									echo "<input type='hidden' name='add' value='1'>";
									echo "<input type='hidden' name='business' value=''>";
									echo "<input type='hidden' name='item_name' value='$row[description]'>";
									echo "<input type='hidden' name='item_number' value='$row[itemno]'>";
									echo "<input type='hidden' name='amount' value='$row[price]'>";
									echo "<input type='hidden' name='shipping' value='7.00'>";
									echo "<input type='hidden' name='shipping2' value='0.50'>";
									echo "<input type='hidden' name='handling' value='2.00'>";
									echo "<input type='hidden' name='currency_code' value='USD'>";
									echo "<input type='hidden' name='return' value=''>";
									echo "<input type='hidden' name='undefined_quantity' value='1'>";
									echo "<input type='image' src='' height='21' border='0' name='submit'  alt=''>";
									echo "</form>";
									
									
						           }                                                                                                                
                            
                                   //else($row['sold'] !=0)
                                        //{
                                        //echo "<img src='images/sold.png'>";                                                  
										//}
								//}
						
						
                             //echo "</form>";
					}
				
           
                 
						echo "</div></td>";
				//	}
					// increment counter - if counter = max columns, reset counter and close row
					if(++$i == $max_columns)
					{
						echo "</tr>";
						$i=0;
					}	// end if
				} // end while
			} // end if results
      
     
			
			// clean up table - makes your code valid!
			if($i < $max_columns)
			{
				for($j=$i; $j<$max_columns;$j++)
				{
					echo "<td>&nbsp;</td>";
				}
			}
		}

My website shows items listed from the database with a picture and associated information including a icon to make the purchase. I want to show the item as sold after the purchase and not the hidden info that is sent to aPayapl to make the purchase. I would like show the item as sold and attach a sold icon but eliminate the paypal hidden info. I tried but when I run the program it breaks. I tried to comment out the stuff i tried. I need some help please. Thanks in advance for any help.

Edited by vet911
25 minutes ago, vet911 said:

echo "<td><div class=box><a href=$row[image] rel=lightbox title=$row[image]><img class=border src=$row[image]>";

One problem you have is the failure to quote your indices and string values.  In the above line, the words  box, image, lightbox, border and $row[image'] need quotes aroun them.  

echo "<td><div class='box'><a href='$row[\"image\"]' rel='lightbox' title='$row[\"image\"]'><img class='border' src='$row[\"image\"]'>";

Now you have to explain what "breaks" means to you.  Do you have error checking turned on at least?  Do you get any messages?  A white screen?  Anything?

Edited by ginerjm
fix the code box

the posted code contains some problems and questionable logic that need to be corrected before you worry about making changes to what it is doing -

  1. to display a product, a commented out 'avail' value, an image, and a price are being checked in the code. this should be done in the sql query. you should only query for products that should be displayed. in the case of having an image and a price, should the product even have been INSERTed if these pieces of data weren't submitted?
  2. the html table 'cleanup' code needs to be inside the end of the if($result) logic and also needs to output a closing </tr> tag.
  3. there are several 'empty' <a> anchor/link tags being produced. why?
  4. the non-empty <a> tag that starts with the product image is never closed. should this even be a link and what portion of the product information should it include?
  5. if there's no item no and description for a product, do you really have a product to display? these two values are being put into the paypal form data. do you want empty values for them to be submitted to paypal?

for your added conditional logic, if there are only two choices, a zero or a one, you only need - if(expression) { logic for a true expression } else { logic for a false expression} 

I did get an error message: 500 Internal Server Error.  I removed the important info from the paypal hidden stuff. What I tried to do was check the $row['sold'] value to see if it was sold.  1= sold, 0 = not sold.

It works, but not the way I would like. I was trying some different things that's why the commented out stuff.

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.