vet911 Posted August 27, 2019 Share Posted August 27, 2019 (edited) $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> </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 August 27, 2019 by vet911 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 27, 2019 Share Posted August 27, 2019 (edited) 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 August 27, 2019 by ginerjm fix the code box Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 27, 2019 Share Posted August 27, 2019 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 - 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? 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. there are several 'empty' <a> anchor/link tags being produced. why? 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? 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} Quote Link to comment Share on other sites More sharing options...
vet911 Posted August 27, 2019 Author Share Posted August 27, 2019 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 27, 2019 Share Posted August 27, 2019 I'm guessing that the 500 is a sign that you had a php error in your improvements. Have to debug that. Quote Link to comment Share on other sites More sharing options...
vet911 Posted August 27, 2019 Author Share Posted August 27, 2019 (edited) That is what I figured out because when I took it back out of the code it was working as before. I haven't been able to figure it out sense. I'll continue to work at it some more. Thanks Edited August 27, 2019 by vet911 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 27, 2019 Share Posted August 27, 2019 Have you turned on php error checking? Quote Link to comment 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.