Start New Discussion within our Web Development Community

my code works fine but i feel i my structure of this code is not good. can any one help me out? i puted all code in one page.

so i have a page. this page is made up by 3 parts.
1st part is the header. in header i am connecting to database.
2nd part is the form. in form i have a html select. where user can pick "price: heigh to low", "price: low to heigh".
3rd part is where i am display the items. each item has a price. so if user pick "price: heigh to low" than height price item will be at top and low item will be at bottom.



1st part is simple just one line.

    <?php include("../../INCLUDE/header.php");?> 

2nd part is just html form

       <form action='male.php' method='POST'>
          <label>Order by:</label> 
              <select  name="order_by">
                   <option value="heigh_low">price: height to low</option>
                   <option value="low_heigh">Price: Low to Heigh</option>
            <button type="submit" name="male_button">go</button>  

3rd part is where iam displaying the items. over all i am just running different query at bottom.



            <div id = 'index_content_page_wrapper'>
                    <br/> <br/>

                        /*** display images ***/
                        //$user_name_c = $_COOKIE['username'];

                         if(isset($_POST['male_button'])) //if user hit submit button 
                             $order_by_p  = $_POST['order_by'];

                             if($order_by_p == 'heigh_low')
                                $male_query = mysql_query("SELECT * FROM item WHERE sub_category='Male_T-Shirts' ORDER BY price DESC LIMIT 8") or die(mysql_error());
                            $male_query = mysql_query("SELECT * FROM item WHERE sub_category='Male_T-Shirts' LIMIT 8"); 

                        $count = 0;
                        while($row = mysql_fetch_assoc($male_query))
                            $image_user_name_db = $row['image_user_name'];
                                $image_user_name_db = ucwords($image_user_name_db);   // upper case begining of every word
                            $image_folder_name_db = $row['image_folder_name'];
                            $price_db = $row['price'];
                                $price_db = number_format($price_db, 2); //2 decimal. ex (1.0, 1)= 1.00

                            echo"<td >";

                                echo"<img src='http://localhost/E_COMMERCE/IMAGE/STORE_ITEMS_DB/$image_folder_name_db' width='150' height='150'/> <br/>";
                                echo"<p id='name'>$image_user_name_db</p>";
                                echo"<p id='price'>Our Price $$price_db</p>";

                            echo "</td>";

                             if($count == 4)       //3 cols
                                echo "</tr><tr>"; // Start a new row at 3 cols
                              $count = 0;
                        }//end of while loop


i dont know object oriented but i just search and i kind of see how to use it. for ex

  class ram01
  public $name;
  public function setName($x)
   $this->name = $x;

   $ram02 = new $ram01();
   $ram02->setName("ram name");
   echo "$ram02->name";

but i am lil confused on how can apply on to my code.


$ram02 = new $ram01();

Should be:

$ram02 = new ram01();

There are many ways. You could put the "high-low", "low-high" within a class method and have an object call it.. Looks more cleaner.

just one last thing on this topic. right now user has to pick a select tag than hit button. is there a way so user pick a select tag and information display without the need of reloading?

i was thinking puting <?php...?> it in jquery function but not sure?

You need to learn ajax request,
html page sends request to server on any event with parameters,
there on server you must have some script to handle such request ,
the script will return you some output, that you can reflect on html page,

all this will not need to reload whole page, only part of page is updated.

This article has been dead for over six months. Start a new discussion instead.