As I said, I am definitely a beginner and this is the most complex code I have written so if it looks horrible I shall apologise in advance. Here is the php part of the page ...
<!-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Start of work area @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -->
<div class="searchworkbox">
<?php // ++++++++++++++++++ START OF INITIAL SEARCH TO GET NUMBER OF ITEMS AND GENERIC NAMES OF ITEMS ++++++++
$suche=$_POST['found'];
$keywords=mysql_query("SELECT DISTINCT generic FROM prices WHERE keywords LIKE '%$suche%'");
$count=mysql_num_rows($keywords);
if($count>0){
$farbe=1;
$outerloop=$count;
// =============== START OF OUTER LOOP ====================
while($outerloop>0){
$innerloop=1;
$found=mysql_result($keywords,($outerloop-1));
$items=mysql_query("SELECT * FROM details, prices, quantity WHERE detailsgeneric='$found'");
$all=mysql_fetch_array($items);
$kk=$all[setquan];
$set=$kk;
// ~~~~~~~~~~~~~~~ START OF HEADER SECTION ~~~~~~~~~~~~~~~~~~~~~~
?><div class="searchHeaderGreen">
<?php echo $all['headertxt'];?>
</div>
<div class="searchwhitespace1">
</div>
<div class="search2AA">
<div class="search2A">
<div class="search2B">
<a href="<?php echo $all['javaURL']; ?>" onClick="return popup(this, 'VARA')">
<img border="0" src="<?php echo $all['thumbURL']; ?>" width="248" height="128" alt="">
</a>
<p></p>
<font color="red"><b>Click on image for larger pictures</b></font>
</div>
</div>
<div class="searchDescribeTxt">
<?php echo $all['describetxt'];?>
</div>
<div class="clear">
</div>
</div>
<?php
?><div class="searchGreenBar">
<div class="search3A">
Item
</div>
<div class="search3B">
Part No.
</div>
<div class="search3C">
Price
</div>
<div class="search3D">
Stock
</div>
<div class="search3E">
</div>
</div>
<div class="searchwhitespace1">
</div><?php
// ############### END OF HEADER SECTION IE PICTURE AND DESCRIPTION TEXT #################
// ============= START OF INNER LOOP WHICH DISPLAYS ALL ITEMS EG XX-01, XX-02 ETC =============
// %%%%%%%%%%%%%%%%%%%%%%%%%%% START OF SECTION THAT DECIDES WHETHER A COMPLETE SET PRICE SHOULD BE SHOWN %%%%%%%
$ct=0;
$discountprice=0;
$okay=1;
$ergebnis=mysql_query("SELECT amount, mqfs, discount, retail, setquan FROM prices, details, quantity WHERE generic=detailsgeneric AND generic LIKE '$found'");
$initial=mysql_fetch_array($ergebnis);
$sets=$initial['setquan'];
$dsc=$initial['discount'];
if($dsc>5){ // Do we want to have a discount bar ie dsc=0 no and dsc=90 yes
while($sets>$ct){ // loops through items in a set
$am=$initial['amount'];
$mq=$initial['mqfs'];
$pp=$initial['retail'];
if($okay==1){
if($am>$mq){
$discountprice=$discountprice+($pp*$mq);
}else{
$okay=0;} // 1 means enough parts 0 means too few therefore no display bar should be shown;
}else{};
$ct=$ct+1;
};
}else{$okay=0;}; //jump here if no discount bar required
if($okay==1){
?>
<div class="searchYellowBar">
<div class="searchDescription">
<?php echo "Complete set inc. ".(100-$dsc)."% Discount";
$farbe=0; ?>
</div>
<div class="searchPart">
<?php echo $found."-00";
$farbe=0; ?>
</div>
<div class="searchPrice">
<?php
echo "£".number_format($discountprice*($dsc/100),2);
$farbe=0;
?>
</div>
<div class="searchQuant">
<img border="0" src="../searchimages/plus.gif" width="24" height="23" alt="">
</div>
<div class="searchBuyButton">
<form target="paypal" action="
https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="cancel_return" value="
http://www.dreamhomeminiatures.co.uk/cancelled.htm">
<input type="hidden" name="return" value="
http://www.dreamhomeminiatures.co.uk/thankyou.htm">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="page_style" value="Primary">
<input type="hidden" name="amount" value="<?php echo number_format($discountprice*($dsc/100),2); ?>">
<input type="hidden" name="item_number" value="<?php echo $found."-00"; ?>">
<input type="hidden" name="item_name" value="<?php echo $found." Set";?>">
<input type="hidden" name="business" value="
shop@dreamhomeminiatures.co.uk">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="image" src="
https://www.paypal.com/en_GB/i/btn/x-click-but22.gif" name="submit" alt=" Pay Dream Home
Miniatures using PayPal - it's fast, free and secure!" width="94" height="21">
<input type="hidden" name="bn" value="PP-ShopCartBF">
</form></p>
</div>
</div>
<?php }
else{};
// &&&&&&&&&&&&&&&&& END OF SECTION THAT DECIDES WHETHER FULL SET PRICE CAN BE SHOWN &&&&&&&&&&&&&&&&&&&&&&&&
$fullset=mysql_query("SELECT description, partNo, retail, amount, setquan FROM prices, details, quantity WHERE generic=detailsgeneric AND partNo=part AND generic LIKE '$found'");
$loop=$sets;
while(($innerloop-1)<$loop){ // START OF WHILE INNER LOOP
$sdisc=mysql_fetch_array($fullset);
if($farbe==1){
?><div class="searchYellowBar">
<div class="searchDescription"><?php
echo $sdisc['description'];
?>
</div>
<div class="searchPart">
<?php echo $sdisc['partNo'];?>
</div>
<div class="searchPrice">
<?php echo "£" .$sdisc['retail'];?>
</div>
<div class="searchQuant">
<?php $yesno=$sdisc['amount'];
if($yesno>0){?>
<img border="0" src="../searchimages/plus.gif" width="24" height="23" alt="">
<?php
}else{
?><img border="0" src="../searchimages/zero.gif" width="24" height="23" alt=""><?php
}
?>
</div>
<div class="searchBuyButton">
<form target="paypal" action="
https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="cancel_return" value="
http://www.dreamhomeminiatures.co.uk/cancelled.htm">
<input type="hidden" name="return" value="
http://www.dreamhomeminiatures.co.uk/thankyou.htm">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="page_style" value="Primary">
<input type="hidden" name="amount" value="<?php echo $sdisc['retail']; ?>">
<input type="hidden" name="item_number" value="<?php echo $sdisc['partNo']; ?>">
<input type="hidden" name="item_name" value="<?php echo $sdisc['description'];?>">
<input type="hidden" name="business" value="
shop@dreamhomeminiatures.co.uk">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<?php
if($yesno == 0){
?><img src="templateimages/outofstock.gif" alt="" height="21" width="94"><?php
}else{ ?>
<input type="image" src="
https://www.paypal.com/en_GB/i/btn/x-click-but22.gif" name="submit" alt=" Pay Dream Home
Miniatures using PayPal - it's fast, free and secure!" width="94" height="21">
<input type="hidden" name="bn" value="PP-ShopCartBF">
</form></p>
<?php } ?>
</div>
</div>
<?php
$farbe=0;
}else{
?><div class="searchWhiteBar">
<div class="searchDescription"><?php
echo $sdisc['description'];?>
</div>
<div class="searchPart">
<?php echo $sdisc['partNo'];?>
</div>
<div class="searchPrice">
<?php echo "£" .$sdisc['retail'];?>
</div>
<div class="searchQuant">
<?php $yesno=$sdisc['amount'];
if($yesno>0){?>
<img border="0" src="../searchimages/plus.gif" width="24" height="23" alt="">
<?php }
else{
?><img border="0" src="../searchimages/zero.gif" width="24" height="23" alt=""><?php
}
?>
</div>
<div class="searchBuyButton">
<form target="paypal" action="
https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="cancel_return" value="
http://www.dreamhomeminiatures.co.uk/cancelled.htm">
<input type="hidden" name="return" value="
http://www.dreamhomeminiatures.co.uk/thankyou.htm">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="page_style" value="Primary">
<input type="hidden" name="amount" value="<?php echo $sdisc['retail']; ?>">
<input type="hidden" name="item_number" value="<?php echo $sdisc['partNo']; ?>">
<input type="hidden" name="item_name" value="<?php echo $sdisc['description'];?>">
<input type="hidden" name="business" value="
shop@dreamhomeminiatures.co.uk">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<?php
if($yesno == 0){
?><img src="templateimages/outofstock.gif" alt="" height="21" width="94"><?php
}else{ ?>
<input type="image" src="
https://www.paypal.com/en_GB/i/btn/x-click-but22.gif" name="submit" alt=" Pay Dream Home
Miniatures using PayPal - it's fast, free and secure!" width="94" height="21">
<input type="hidden" name="bn" value="PP-ShopCartBF">
</form></p>
<?php } ?>
</div>
</div><?php
$farbe=1;
} // OOOOOOOOOOO end of if loop to draw either white or yellow OOOOOOOOOOOOOOOOO
$innerloop=$innerloop+1;
} //%%%%%%%%%%%%%%% end of inner loop %%%%%%%%%%%%%%%%%
?>
<div class="searchbottomspace">
</div>
<a href="#pagetop">
<div class="top">
</div>
</a><?php
$items=$items-1;
// +++++++++++++++ END OF INNER LOOP (White/Yellow )++++++++++++++++++++++++++++++++++
$outerloop=$outerloop-1;
} // ============= END OF OUTERLOOP IF ===============================================
}else{
echo "Sorry but no results were found ";
} // ============= END OF IF THAT CHECKS IF ANY SEARCH RESULTS FOUND =================
?>
<!-- @@@@@@@@@@@@@@@ END OF AUTOMATIC PAGE BUILD @@@@ -->
</div><!-- @@@ End Searchworkbox DIV @@ -->