We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,708 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

make my code structure better

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.

---------------

male.php

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>
               </select>
            <button type="submit" name="male_button">go</button>  
         </form>

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

       <?php 

                echo"

            <div id = 'index_content_page_wrapper'>
                    <br/> <br/>
                    <table>
                        <tr'>
                ";

                        /*** 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());
                             }
                         }
                        else
                        {
                            $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>";

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


                echo"
                    </tr>
                </table></div>
                ";
3
Contributors
5
Replies
5 Hours
Discussion Span
5 Months Ago
Last Updated
6
Views
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

Why are you not using a more Object Oriented approach?

phorce
Master Poster
738 posts since Jul 2011
Reputation Points: 63
Solved Threads: 91
Skill Endorsements: 16

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

<?php
  class ram01
  {
  public $name;
  public function setName($x)
   {
   $this->name = $x;
   }
  }
?>

<html>
<?php
   $ram02 = new $ram01();
   $ram02->setName("ram name");
   echo "$ram02->name";
?>
</html>

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

hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

This:

$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.

phorce
Master Poster
738 posts since Jul 2011
Reputation Points: 63
Solved Threads: 91
Skill Endorsements: 16

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?

hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

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.

http://www.w3schools.com/php/php_ajax_database.asp

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.3041 seconds using 2.71MB