PHP help - customised user queries!!!!

dragon2309

P.I Dragon
damn semi colons, i always forget those, so yeh, form is inside the PHP block and its being echoed to be displayed on the page. NOTE: it doesnt actually work anymore though, it comes up with 404

code is:

PHP:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>price Query</title>
</head>
    <link rel="stylesheet" href="../menu.css">
<body>
</head>
 <body>
    <form>
    <p align="center">
    <img border="0" src="../logo%202%20better.jpg" width="640" height="150"><script language="JavaScript" src="menu.js"></script><script language="JavaScript" src="menu_items.js"></script><script language="JavaScript" src="menu_tpl.js"></script><script language="JavaScript">
        <!--//
        new menu (MENU_ITEMS, MENU_POS, MENU_STYLES);
        //-->
    </script></p>
    <p align="right"><b><font face="Tahoma"><a href="javascript:history.back()">&lt;-- 
    Back</a></font></b></p>
    </form> 
   <br>
 
   <?php
      echo"<form id='make_select' action='<?php $PHP_SELF; ?>' method='post'>
   <p>
     Select price:
     <select name='price'>
       <option value='£1.99'>£1.99</option>
       <option value='£2.99'>£2.99</option>
       <option value='£3.99'>£3.99</option>
       <option value='£4.99'>£4.99</option>
       <option value='£5.99'>£5.99</option>
       <option value='£6.99'>£6.99</option>
       <option value='£7.99'>£7.99</option>
       <option value='£8.99'>£8.99</option>
       <option value='ALL'>All Price Options</option>
       </select>
     Select category:
     <select name='cat'>
       <option value='ad_brac'>Adult Bracelets</option>
       <option value='ch_brac'>Child Bracelets</option>
       <option value='charm_brac'>Charm Bracelets</option>
       <option value='ad_neck'>Adult Necklaces</option>
       <option value='ch_neck'>Child Necklaces</option>
       <option value='ad_set'>Adult Sets</option>
       <option value='ch_set'>Child Sets</option>
       <option value='earring'>Earrings</option>
       <option value='k_pin'>Kilt Pins</option>
       <option value='l_pin'>Lapel Pins</option>
       <option value='wine_ch'>Wine Charms</option>
       <option value='bag_ch'>Bag Charms</option>
       <option value='bookmark'>Bookmarks</option>
     </select>
      <input type='submit' />
   </p>
   </form>";

     if( ! empty( $_POST["price"] ) )
     if( ! empty( $_POST["cat"] ) )
     {
     echo"<font face='Tahoma' style='font-size: 11pt'>You have selected to view all </font>";
     if($cat == 'ad_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Bracelets</u></b></font>";
     if($cat == 'ch_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Bracelets</u></b></font>";
     if($cat == 'ad_neck')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Necklaces</u></b></font>";
     if($cat == 'ch_neck')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Necklaces</u></b></font>";
     if($cat == 'ad_set')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Sets</u></b></font>";                 // This is all the IF statements
     if($cat == 'ch_set')                                                                                   // for the top section
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Sets</u></b></font>";                 // This displays what the user
     if($cat == 'bag_ch')                                                                                   // has actaully searched for,
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Bag Charms</u></b></font>";
     if($cat == 'wine_ch')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Wine Charms</u></b></font>";
     if($cat == 'l_pin')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Lapel Pins</u></b></font>";
     if($cat == 'k_pin')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Kilt Pins</u></b></font>";
     if($cat == 'earring')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Earrings</u></b></font>";
     if($cat == 'charm_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Charm Bracelets</u></b></font>";
     if($cat == 'bookmark')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Bookmarks</u></b></font>";
        
     print"<font face='Tahoma' style='font-size: 11pt'> at </font>";
     
     if($price == '£1.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£1.99</u></b><br><br><br></font>";
     if($price == '£2.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£2.99</u></b><br><br><br></font>";
     if($price == '£3.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£3.99</u></b><br><br><br></font>";
     if($price == '£4.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£4.99</u></b><br><br><br></font>";
     if($price == '£5.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£5.99</u></b><br><br><br></font>";
     if($price == '£6.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£6.99</u></b><br><br><br></font>";
     if($price == '£7.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£7.99</u></b><br><br><br></font>";
     if($price == '£8.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£8.99</u></b><br><br><br></font>";
        
     echo '<table border="1" div align="center" bgcolor="#FFD9FF" bordercolor="#FF9DFF" bordercolorlight="#FF9DFF" bordercolordark="#FF9DFF" cellpadding="6" style="border-collapse: collapse; font-family: Tahoma; font-size: 11pt">
     <tr>
       <th><font face="Tahoma">Item Number</font></th>
       <th><font face="Tahoma">Description</font></th>
       <th><font face="Tahoma">Price</font></th>
       <th><font face="Tahoma">Image</font></th>
       <th><font face="Tahoma">Information</font></th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th>Item Number</th>
       <th>Description</th>
       <th>Price</th>
       <th>Image</th>
       <th>Information</th>
     </tr>



     <tr>
       <td bgcolor="#FFECFF">&nbsp;</td>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
     </tr>';

       require "dbinfo.php";
 
       // Connect to MySQL DBMS
       if (!($connection = @ mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD)))
         showerror();
 
       // Use the cars database
       if (!mysql_select_db(DB_DATABASENAME, $connection))
         showerror();
 
       // Create SQL statement
       $cat = $_POST["cat"];
       $price = $_POST["price"];
       
       if ($price == 'ALL')
       $query = "SELECT * FROM $cat WHERE StockCount >0 ORDER BY Price DESC";
       else
       $query = "SELECT * FROM $cat WHERE Price='$price' AND StockCount > 0 ORDER BY Price DESC";
               
       // Execute SQL statement
       if (!($result = @ mysql_query ($query, $connection)))
         showerror();
 
// starts counter at 0
       $counter=-1; 
    while ($row = @ mysql_fetch_array($result))
       {

       if($counter == 2){//this will tell us we already have 2 items in the row so start a new row
        echo "</tr>";//close the old row
        $counter=0; //reset the counter as we will now be starting a new row
        echo "<tr>";//start a new row
    }
    
    if ($counter == -1) {
        //this code will only action on the first time through, after that counter will hold values on 0,1,or 2
        $counter=0; //reset the counter to begin
        echo "<tr>";//start the first row of the results
    }

        if($counter < 2){ //if we already have 2 items in the row then we need to start a new row
        

               echo "<td>{$row['StockCode']}</td>
               <td>{$row['Description']}</td>
               <td>{$row['Price']}</td>
               <td><p><a href='{$row['IMGURL']}'><img src='{$row['IMG']}'></img></p></td>
               <td><center>{$row['URL']}</center></td>";

        if ($counter == 0) echo '<td bgcolor="#FFECFF">&nbsp;&nbsp;&nbsp;&nbsp;</td>'; //do this to ensure a nice space between the two coloumn
    
        $counter++; //increment the counter to show we have added one item to the current row
    }
    }//end of while loop
    
    //so now we are out of the while loop, we need to assess how the table ended. how many items are in the last row
    //if there is only one then we need to flesh out the second item in that row is &nbsp; to make it look good
    if ($counter==1){
    echo "    <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>";
    }    
        
 
       echo "</td></table>";
       }
       
       if($counter == -1)
        echo "<br><br><font face='Tahoma' style='font-size: 11pt'>We're sorry, simplyTrue currently do not have any items of jewellery in stock that meet your criteria. Please try your search again or use the <a href='http://www.simplytrue.co.uk/customnotes.htm'><b>Custom Jewellery</b></a> link to request a specific item of jewellery.<br><br>Thankyou, simplyTrue.</font>";

     ?>
</body>

</html>
 
Last edited:

apj101

VIP Member
ok, i'll keep trying to come back to this, but it may be tomorrow.

to start with think about this line, which is currently an error
<form id='make_select' action='<?php $PHP_SELF; ?>' method='post'>

do we need the <?php tags now we are already in a php block, or can we just leave it as $PHP_SELF
 

dragon2309

P.I Dragon
oh yes, i didnt notice that that was a seperate PHP block... ill go change that now and see how it reacts...

thanks apj, dragon

*EDIT* - ok, that works again now. thanks, so now we have it inside the PHP block, it is a lot more manageable, before i was kinda thinking about having the varables for the menu stored in the URL, this may have made it easier at a later date to recall them... perhaps not now though. im not sure, you obviously have something planned so i'll let you explain it when you can...

thanks dragon
 
Last edited:

apj101

VIP Member
I have seen the updates dragon. I will look into this at some point tomorrow mate, i promise :) although it may be the evening.

In the mean time do a little research around the various options for select boxes in html, specifically look at how to specify which of the <option> tags are selected by default (you need to be looking for the "selected" flag) spend about 15-30 mins researching this tonights as we'll be using it tomorrow.
 

dragon2309

P.I Dragon
ok, prev post deleted...

i know you wont see this as your offline, but you will tomorrow, i was trying some stuff out, better to be independant hey.... i came up with this....

if($PHP_SELF['price'] == '£3.99')
echo '<option value="£3.99" SELECTED>3.99</option>';

It compiles fine, so theres nothing actaully syntactically wrong with it, just it doesnt work. I was probably WAAAY off the mark, i wasnt actually expecting it to compile, but it did, lol... i tried it both inside and outside of the loop. no luck, ok, well, ill speak toy ya tomorrow, thanks for all your help...

dave
 

Cromewell

Administrator
Staff member
You don't want $PHP_SELF[price], you want $_POST[price] to get html post variables

$PHP_SELF holds the PHP file name
 

apj101

VIP Member
your on the right lines though dragon, you could just have lots of if statements to catch all possibilities the user has pressed. But a little better than using the if blocks, spend a few mins looking into the switch statement http://uk2.php.net/switch
 

dragon2309

P.I Dragon
Cromewell said:
You don't want $PHP_SELF[price], you want $_POST[price] to get html post variables

$PHP_SELF holds the PHP file name
aaaah right, thanks cromewell, ill keep that in mind when im cahnging it next time.

apj101 said:
your on the right lines though dragon, you could just have lots of if statements to catch all possibilities the user has pressed. But a little better than using the if blocks, spend a few mins looking into the switch statement http://uk2.php.net/switch
ok, im reading that article now, is there any real world advantage of using the switch statement as opposed to a series of IF's and ELSEIF's...??

dragon

*EDIT* - ok, i started using $_POST instead of $PHP_SELF and i kinda got somewhere but kinda didnt, now if the user does selecte £3.99 and hit submit the text "£3.99" gets printed at the bottom of the table, i dont know why, shouldnt it have at least formed it into a selection box seeing as thats what its supposed to be echoing...?? im confused

page is at http://www.simplytrue.co.uk/stocklist/querytest.php

*EDIT AGAIN* - ok, so i thought about it a different way, i defined all of the SELECT OPTIONS as variables ranging from $p1 all the way to the end at $p9, then in the IF statement, well, its easier if i show you....

if($_POST['price'] == '£3.99')
$p3 == "<option value='£3.99' SELECTED>£3.99</option>";

Is that anywhere near right or am i way off again, it compiles but on selecting £3.99, it does nothing. Oh and apj, i dont get the CASE function thingies. i have interpreted them as just an IF statement with multiple outcomes, is that right....??

dragon
 
Last edited:

apj101

VIP Member
i have interpreted them as just an IF statement with multiple outcomes, is that right....??
thats exactly right, but it is much neater code that having 10 IF statements.

I will reply in one min
 

apj101

VIP Member
we are getting closer, what you need to think about is
if the price is XXX
then echo this entire select option

if the price is yyy
then echo this entiure select option

if the price is zzz
then echo this entire select option

after 9 of these blocks the code will look messy, but will be very simple to understand, lets do it like this first

also dont forget to have an if block to catch when there is no price specified.

(we'll migrate to a switch later)
 

dragon2309

P.I Dragon
ok, is this what you meant....

PHP:
if($_POST['price'] == '£1.99')
          echo"<option value='£1.99' SELECTED>£1.99</option>";
       if($_POST['price'] == '£2.99')
          echo"<option value='£2.99' SELECTED>£2.99</option>";
       if($_POST['price'] == '£3.99')
          echo"<option value='£3.99' SELECTED>£3.99</option>";
       if($_POST['price'] == '£4.99')
          echo"<option value='£4.99' SELECTED>£4.99</option>";
       if($_POST['price'] == '£5.99')
          echo"<option value='£5.99' SELECTED>£5.99</option>";
       if($_POST['price'] == '£6.99')
          echo"<option value='£6.99' SELECTED>£6.99</option>";
       if($_POST['price'] == '£7.99')
          echo"<option value='£7.99' SELECTED>£7.99</option>";
       if($_POST['price'] == '£8.99')
          echo"<option value='£8.99' SELECTED>£8.99</option>";
       if($_POST['price'] == 'ALL')
          echo"<option value='ALL' SELECTED>All Price Options</option>";
       if($_POST['price'] == '')
          echo"<option value='' SELECTED></option>";
i wasnt sure about the one where nothing is selected, an empty field, i dont know... but i tried this before with just a single ne, on £3.99 and it didnt work. oh and should this be inside the query/echo loop or outside...

dragon
 

apj101

VIP Member
dragon your not thinking this through, imagine if the price was 2.99 (meaning the user selected 2.99 last time around) what will be echo'd? Well according to your code only this line will be echo'd

echo"<option value='£2.99' SELECTED>£2.99</option>";

but what about the rest of the select block, i.e. all the other options... we still need these to be echo'd, but just 2.99 needs to be selected.
inside each of the if statements you need to be echoing out the whole select block with all the options, the only difference between the if statements is that each one will echo a different options SELECTED


also note that price != Price I'm not sure if php is case sensitive in its arrays but its good technique to use the correct case :)

we are getting closer
 
Last edited:

dragon2309

P.I Dragon
ah, damn... sorry about that, ok, ive got taht going, it echoes the whole menu with the correct option selected, this makes 2 menus though, and the one that is echoed does not govern what is submitted/searched for, if that makes any sense, the page is same as last time @ www.simplytrue.co.uk/stocklist/querytest.php

Code is as follows for the IF block
PHP:
                // Below - the block of IF statements to govern the
                // preselected option inside any drop down menus...
          
       if($_POST['price'] == '£1.99')
          echo"<select name='price'>
               <option value='£1.99' SELECTED>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£2.99')
          echo"<select name='price'>
               <option value='£1.99'D>£1.99</option>
               <option value='£2.99' SELECTED>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£3.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99' SELECTED>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£4.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99' SELECTED>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£5.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99' SELECTED>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£6.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99' SELECTED>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£7.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99' SELECTED>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£8.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99' SELECTED>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == 'ALL')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL' SELECTED>All Price Options</option>
                </select>";
Code for entire page is as follows...
PHP:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>price Query</title>
</head>
    <link rel="stylesheet" href="../menu.css">
<body>
</head>
 <body>
    <form>
    <p align="center">
    <img border="0" src="../logo%202%20better.jpg" width="640" height="150"><script language="JavaScript" src="menu.js"></script><script language="JavaScript" src="menu_items.js"></script><script language="JavaScript" src="menu_tpl.js"></script><script language="JavaScript">
        <!--//
        new menu (MENU_ITEMS, MENU_POS, MENU_STYLES);
        //-->
    </script></p>
    <p align="right"><b><font face="Tahoma"><a href="javascript:history.back()">&lt;-- 
    Back</a></font></b></p>
    </form> 
   <br>
 
   <?php
      echo"<form id='make_select' action='$PHP_SELF' method='post'>
   <p>
     Select price:
     <select name='price'>
       <option value='£1.99'>£1.99</option>
       <option value='£2.99'>£2.99</option>
       <option value='£3.99'>£3.99</option>
       <option value='£4.99'>£4.99</option>
       <option value='£5.99'>£5.99</option>
       <option value='£6.99'>£6.99</option>
       <option value='£7.99'>£7.99</option>
       <option value='£8.99'>£8.99</option>
       <option value='ALL'>All Price Options</option>
       </select>
     Select category:
     <select name='cat'>
       <option value='ad_brac'>Adult Bracelets</option>
       <option value='ch_brac'>Child Bracelets</option>
       <option value='charm_brac'>Charm Bracelets</option>
       <option value='ad_neck'>Adult Necklaces</option>
       <option value='ch_neck'>Child Necklaces</option>
       <option value='ad_set'>Adult Sets</option>
       <option value='ch_set'>Child Sets</option>
       <option value='earring'>Earrings</option>
       <option value='k_pin'>Kilt Pins</option>
       <option value='l_pin'>Lapel Pins</option>
       <option value='wine_ch'>Wine Charms</option>
       <option value='bag_ch'>Bag Charms</option>
       <option value='bookmark'>Bookmarks</option>
     </select>
      <input type='submit' />
   </p>
   </form>";
     if( ! empty( $_POST["price"] ) )
     if( ! empty( $_POST["cat"] ) )
     
     {
     echo"<font face='Tahoma' style='font-size: 11pt'>You have selected to view all </font>";
     if($cat == 'ad_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Bracelets</u></b></font>";
     if($cat == 'ch_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Bracelets</u></b></font>";
     if($cat == 'ad_neck')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Necklaces</u></b></font>";
     if($cat == 'ch_neck')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Necklaces</u></b></font>";
     if($cat == 'ad_set')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Sets</u></b></font>";                 // This is all the IF statements
     if($cat == 'ch_set')                                                                                   // for the top section
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Sets</u></b></font>";                 // This displays what the user
     if($cat == 'bag_ch')                                                                                   // has actaully searched for,
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Bag Charms</u></b></font>";
     if($cat == 'wine_ch')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Wine Charms</u></b></font>";
     if($cat == 'l_pin')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Lapel Pins</u></b></font>";
     if($cat == 'k_pin')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Kilt Pins</u></b></font>";
     if($cat == 'earring')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Earrings</u></b></font>";
     if($cat == 'charm_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Charm Bracelets</u></b></font>";
     if($cat == 'bookmark')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Bookmarks</u></b></font>";
        
     print"<font face='Tahoma' style='font-size: 11pt'> at </font>";
     
     if($price == '£1.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£1.99</u></b><br><br><br></font>";
     if($price == '£2.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£2.99</u></b><br><br><br></font>";
     if($price == '£3.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£3.99</u></b><br><br><br></font>";
     if($price == '£4.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£4.99</u></b><br><br><br></font>";
     if($price == '£5.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£5.99</u></b><br><br><br></font>";
     if($price == '£6.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£6.99</u></b><br><br><br></font>";
     if($price == '£7.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£7.99</u></b><br><br><br></font>";
     if($price == '£8.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£8.99</u></b><br><br><br></font>";
     if($price == 'ALL')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>All Prices</u></b><br><br><br></font>";
        
             
                // Below - the block of IF statements to govern the
                // preselected option inside any drop down menus...
          
       if($_POST['price'] == '£1.99')
          echo"<select name='price'>
               <option value='£1.99' SELECTED>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£2.99')
          echo"<select name='price'>
               <option value='£1.99'D>£1.99</option>
               <option value='£2.99' SELECTED>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£3.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99' SELECTED>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£4.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99' SELECTED>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£5.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99' SELECTED>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£6.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99' SELECTED>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£7.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99' SELECTED>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£8.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99' SELECTED>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == 'ALL')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL' SELECTED>All Price Options</option>
                </select>";

        
     echo '<table border="1" div align="center" bgcolor="#FFD9FF" bordercolor="#FF9DFF" bordercolorlight="#FF9DFF" bordercolordark="#FF9DFF" cellpadding="6" style="border-collapse: collapse; font-family: Tahoma; font-size: 11pt">
     <tr>
       <th><font face="Tahoma">Item Number</font></th>
       <th><font face="Tahoma">Description</font></th>
       <th><font face="Tahoma">Price</font></th>
       <th><font face="Tahoma">Image</font></th>
       <th><font face="Tahoma">Information</font></th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th>Item Number</th>
       <th>Description</th>
       <th>Price</th>
       <th>Image</th>
       <th>Information</th>
     </tr>



     <tr>
       <td bgcolor="#FFECFF">&nbsp;</td>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
     </tr>';

       require "dbinfo.php";
 
       // Connect to MySQL DBMS
       if (!($connection = @ mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD)))
         showerror();
 
       // Use the cars database
       if (!mysql_select_db(DB_DATABASENAME, $connection))
         showerror();
 
       // Create SQL statement
       $cat = $_POST["cat"];
       $price = $_POST["price"];

       if ($price == 'ALL')
       $query = "SELECT * FROM $cat WHERE StockCount >0 ORDER BY Price DESC";
       else
       $query = "SELECT * FROM $cat WHERE Price='$price' AND StockCount > 0 ORDER BY StockCode DESC";
               
       // Execute SQL statement
       if (!($result = @ mysql_query ($query, $connection)))
         showerror();
 
// starts counter at 0
       $counter=-1; 
    while ($row = @ mysql_fetch_array($result))
       {

       if($counter == 2){//this will tell us we already have 2 items in the row so start a new row
        echo "</tr>";//close the old row
        $counter=0; //reset the counter as we will now be starting a new row
        echo "<tr>";//start a new row
    }
    
    if ($counter == -1) {
        //this code will only action on the first time through, after that counter will hold values on 0,1,or 2
        $counter=0; //reset the counter to begin
        echo "<tr>";//start the first row of the results
    }

        if($counter < 2){ //if we already have 2 items in the row then we need to start a new row
        

               echo "<td>{$row['StockCode']}</td>
               <td>{$row['Description']}</td>
               <td>{$row['Price']}</td>
               <td><p><a href='{$row['IMGURL']}'><img src='{$row['IMG']}'></img></p></td>
               <td><center>{$row['URL']}</center></td>";

        if ($counter == 0) echo '<td bgcolor="#FFECFF">&nbsp;&nbsp;&nbsp;&nbsp;</td>'; //do this to ensure a nice space between the two coloumn
    
        $counter++; //increment the counter to show we have added one item to the current row
    }
    }//end of while loop
    
    //so now we are out of the while loop, we need to assess how the table ended. how many items are in the last row
    //if there is only one then we need to flesh out the second item in that row is &nbsp; to make it look good
    if ($counter==1){
    echo "    <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>";
    }    
        
 
       echo "</td></table>";
       
       }
            
       if($counter == -1)
        echo "<br><br><font face='Tahoma' style='font-size: 11pt'>We're sorry, simplyTrue currently do not have any items of jewellery in stock that meet your criteria. Please try your search again or use the <a href='http://www.simplytrue.co.uk/customnotes.htm'><b>Custom Jewellery</b></a> link to request a specific item of jewellery.<br><br>Thankyou, simplyTrue.</font>";

     ?>
</body>

</html>
Yeh, you say we are getting closer but the end does not seem at all near....

dave
 
Last edited:

apj101

VIP Member
well you have the select block being echos twice, once a the top of the php block (before all the if statements) and then once again a bit lower down (in the if statements)
 

dragon2309

P.I Dragon
oh, so your saying i should get rid of the fist one, and have the menu be displayed according to the IF statement, if so then can you advise on what the IF statement would look like for when NOTHINg has been selected, as in when the user first comes to the page....

dragon
 

apj101

VIP Member
sure i can advise ya ;)
well think about what value will be in "Price" on the first load... nothing, it will be completely empty. How does php interpret an empty value... well as FALSE or == ""
maybe that will help you?
 

dragon2309

P.I Dragon
ok, im not getting this at all.... comes up with an error, you can see at www.simplytrue.co.uk/stocklist/querytest.php

complete page code:
PHP:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>price Query</title>
</head>
    <link rel="stylesheet" href="../menu.css">
<body>
</head>
 <body>
    <form>
    <p align="center">
    <img border="0" src="../logo%202%20better.jpg" width="640" height="150"><script language="JavaScript" src="menu.js"></script><script language="JavaScript" src="menu_items.js"></script><script language="JavaScript" src="menu_tpl.js"></script><script language="JavaScript">
        <!--//
        new menu (MENU_ITEMS, MENU_POS, MENU_STYLES);
        //-->
    </script></p>
    <p align="right"><b><font face="Tahoma"><a href="javascript:history.back()">&lt;-- 
    Back</a></font></b></p>
    </form> 
   <br>
 
   <?php
      echo"<form id='make_select' action='$PHP_SELF' method='post'>
   <p>
     Select price:
       if($_POST['price'] == '£1.99')
          echo"<select name='price'>
               <option value='£1.99' SELECTED>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£2.99')
          echo"<select name='price'>
               <option value='£1.99'D>£1.99</option>
               <option value='£2.99' SELECTED>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£3.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99' SELECTED>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£4.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99' SELECTED>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£5.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99' SELECTED>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£6.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99' SELECTED>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£7.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99' SELECTED>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == '£8.99')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99' SELECTED>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
       if($_POST['price'] == 'ALL')
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL' SELECTED>All Price Options</option>
                </select>";
        else
          echo"<select name='price'>
               <option value='£1.99'>£1.99</option>
               <option value='£2.99'>£2.99</option>
               <option value='£3.99'>£3.99</option>
               <option value='£4.99'>£4.99</option>
               <option value='£5.99'>£5.99</option>
               <option value='£6.99'>£6.99</option>
               <option value='£7.99'>£7.99</option>
               <option value='£8.99'>£8.99</option>
               <option value='ALL'>All Price Options</option>
                </select>";
                
     Select category:
     <select name='cat'>
       <option value='ad_brac'>Adult Bracelets</option>
       <option value='ch_brac'>Child Bracelets</option>
       <option value='charm_brac'>Charm Bracelets</option>
       <option value='ad_neck'>Adult Necklaces</option>
       <option value='ch_neck'>Child Necklaces</option>
       <option value='ad_set'>Adult Sets</option>
       <option value='ch_set'>Child Sets</option>
       <option value='earring'>Earrings</option>
       <option value='k_pin'>Kilt Pins</option>
       <option value='l_pin'>Lapel Pins</option>
       <option value='wine_ch'>Wine Charms</option>
       <option value='bag_ch'>Bag Charms</option>
       <option value='bookmark'>Bookmarks</option>
     </select>
      <input type='submit' />
   </p>
   </form>";
     if( ! empty( $_POST["price"] ) )
     if( ! empty( $_POST["cat"] ) )
     
     {
     echo"<font face='Tahoma' style='font-size: 11pt'>You have selected to view all </font>";
     if($cat == 'ad_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Bracelets</u></b></font>";
     if($cat == 'ch_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Bracelets</u></b></font>";
     if($cat == 'ad_neck')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Necklaces</u></b></font>";
     if($cat == 'ch_neck')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Necklaces</u></b></font>";
     if($cat == 'ad_set')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Adult Sets</u></b></font>";                 // This is all the IF statements
     if($cat == 'ch_set')                                                                                   // for the top section
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Child Sets</u></b></font>";                 // This displays what the user
     if($cat == 'bag_ch')                                                                                   // has actaully searched for,
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Bag Charms</u></b></font>";
     if($cat == 'wine_ch')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Wine Charms</u></b></font>";
     if($cat == 'l_pin')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Lapel Pins</u></b></font>";
     if($cat == 'k_pin')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Kilt Pins</u></b></font>";
     if($cat == 'earring')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Earrings</u></b></font>";
     if($cat == 'charm_brac')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Charm Bracelets</u></b></font>";
     if($cat == 'bookmark')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>Bookmarks</u></b></font>";
        
     print"<font face='Tahoma' style='font-size: 11pt'> at </font>";
     
     if($price == '£1.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£1.99</u></b><br><br><br></font>";
     if($price == '£2.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£2.99</u></b><br><br><br></font>";
     if($price == '£3.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£3.99</u></b><br><br><br></font>";
     if($price == '£4.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£4.99</u></b><br><br><br></font>";
     if($price == '£5.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£5.99</u></b><br><br><br></font>";
     if($price == '£6.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£6.99</u></b><br><br><br></font>";
     if($price == '£7.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£7.99</u></b><br><br><br></font>";
     if($price == '£8.99')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>£8.99</u></b><br><br><br></font>";
     if($price == 'ALL')
        echo "<font face='Tahoma' style='font-size: 11pt'><b><u>All Prices</u></b><br><br><br></font>";
        
             
        
     echo '<table border="1" div align="center" bgcolor="#FFD9FF" bordercolor="#FF9DFF" bordercolorlight="#FF9DFF" bordercolordark="#FF9DFF" cellpadding="6" style="border-collapse: collapse; font-family: Tahoma; font-size: 11pt">
     <tr>
       <th><font face="Tahoma">Item Number</font></th>
       <th><font face="Tahoma">Description</font></th>
       <th><font face="Tahoma">Price</font></th>
       <th><font face="Tahoma">Image</font></th>
       <th><font face="Tahoma">Information</font></th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th>Item Number</th>
       <th>Description</th>
       <th>Price</th>
       <th>Image</th>
       <th>Information</th>
     </tr>



     <tr>
       <td bgcolor="#FFECFF">&nbsp;</td>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
       <th bgcolor="#FFECFF">&nbsp;</th>
     </tr>';

       require "dbinfo.php";
 
       // Connect to MySQL DBMS
       if (!($connection = @ mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD)))
         showerror();
 
       // Use the cars database
       if (!mysql_select_db(DB_DATABASENAME, $connection))
         showerror();
 
       // Create SQL statement
       $cat = $_POST["cat"];
       $price = $_POST["price"];

       if ($price == 'ALL')
       $query = "SELECT * FROM $cat WHERE StockCount >0 ORDER BY Price DESC";
       else
       $query = "SELECT * FROM $cat WHERE Price='$price' AND StockCount > 0 ORDER BY StockCode DESC";
               
       // Execute SQL statement
       if (!($result = @ mysql_query ($query, $connection)))
         showerror();
 
// starts counter at 0
       $counter=-1; 
    while ($row = @ mysql_fetch_array($result))
       {

       if($counter == 2){//this will tell us we already have 2 items in the row so start a new row
        echo "</tr>";//close the old row
        $counter=0; //reset the counter as we will now be starting a new row
        echo "<tr>";//start a new row
    }
    
    if ($counter == -1) {
        //this code will only action on the first time through, after that counter will hold values on 0,1,or 2
        $counter=0; //reset the counter to begin
        echo "<tr>";//start the first row of the results
    }

        if($counter < 2){ //if we already have 2 items in the row then we need to start a new row
        

               echo "<td>{$row['StockCode']}</td>
               <td>{$row['Description']}</td>
               <td>{$row['Price']}</td>
               <td><p><a href='{$row['IMGURL']}'><img src='{$row['IMG']}'></img></p></td>
               <td><center>{$row['URL']}</center></td>";

        if ($counter == 0) echo '<td bgcolor="#FFECFF">&nbsp;&nbsp;&nbsp;&nbsp;</td>'; //do this to ensure a nice space between the two coloumn
    
        $counter++; //increment the counter to show we have added one item to the current row
    }
    }//end of while loop
    
    //so now we are out of the while loop, we need to assess how the table ended. how many items are in the last row
    //if there is only one then we need to flesh out the second item in that row is &nbsp; to make it look good
    if ($counter==1){
    echo "    <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>";
    }    
        
 
       echo "</td></table>";
       
       }
            
       if($counter == -1)
        echo "<br><br><font face='Tahoma' style='font-size: 11pt'>We're sorry, simplyTrue currently do not have any items of jewellery in stock that meet your criteria. Please try your search again or use the <a href='http://www.simplytrue.co.uk/customnotes.htm'><b>Custom Jewellery</b></a> link to request a specific item of jewellery.<br><br>Thankyou, simplyTrue.</font>";

     ?>
</body>

</html>

dragon
 

apj101

VIP Member
echo"<form id='make_select' action='$PHP_SELF' method='post'>
<p>
Select price:
if($_POST['price'] == '£1.99')
...

well for starter you didnt close the echo quotes after Select price:
all your if statements are in the echo block

should read

echo"<form id='make_select' action='$PHP_SELF' method='post'>
<p>
Select price:"
if($_POST['price'] == '£1.99')
 
Top