4 Replies - 595 Views - Last Post: 08 December 2012 - 08:03 PM Rate Topic: -----

#1 hwoarang69  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 171
  • Joined: 23-October 12

php object oriented

Posted 08 December 2012 - 06:22 PM

just started learn about object oriented in php and iam not sure how can i use in this code.

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.



        [code] <?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>
                ";


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.

Is This A Good Question/Topic? 0
  • +

Replies To: php object oriented

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10784
  • View blog
  • Posts: 40,160
  • Joined: 27-December 08

Re: php object oriented

Posted 08 December 2012 - 06:32 PM

Moved to PHP. Please start posting your PHP questions in the proper forum.
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: php object oriented

Posted 08 December 2012 - 07:25 PM

The way you are using OOP in that last snippet is both wrong from a design perspective, as there is no point in that class or how you are trying to use it; and it's also incorrectly coded. I'm not sure exactly why you are trying to use OOP in that situation, but you aren't doing it right.

What I suggest you do is go through some tutorials on OOP and try to find some basic OOP exercises to follow. Perhaps even consider finding a OOP textbox and going through that.
Was This Post Helpful? 0
  • +
  • -

#4 hwoarang69  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 171
  • Joined: 23-October 12

Re: php object oriented

Posted 08 December 2012 - 07:56 PM

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?
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: php object oriented

Posted 08 December 2012 - 08:03 PM

PHP runs on the server machine. Javascript runs on the client's browser. You can't execute server-side code in the client's browser.

If you want to fetch data, or have any sort of PHP code executed, as a response to a client-side event (like selecting a drop-down item), then you need to issue a new request to the server to execute said PHP code. In Javascript you can do that with AJAX. It simply allows you to send new requests to the server without having to reload the page, and returns whatever result the PHP page returns to your Javascript code. This tutorial explains that pretty well. There are also a lot of others out there if that one doesn't do it for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1