Jump to content

quyen

Member
  • Posts

    44
  • Joined

  • Last visited

Posts posted by quyen

  1. I've been trying to solve my problem by using http://www.desilva.biz/php/phprefresh.html and http://www.tizag.com/javascriptT/javascriptredirect.php, but I haven't solved my problems yet, I will try some other solutions, but I am still looking for someone to help me. I know "Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\index.php:15) in C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\user_manager.php on line 319" is just a warning, not an error, but the thing is I don't want this warning to show up on the page, and whenever this warning is occurs, it stops redirecting. I will try to use Adam's solution and see what'll happen....

     

    Thank you very much Adam,

    Quyen,

  2. Hello everybody,

     

    This is a warning i've got whenever I use "header("Location: $url"); ".

    Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\index.php:15) in C:\Inetpub\vhosts\qwebdesign.net\httpdocs\admin\user_manager.php on line 319

     

    Is there any solution to redirect to a url without using "header("Location: $url"); Or somehow I can fix the above problem?

     

    I've been reading some topics on some websites, and they are all about how to use header("Location: $url"); but i haven't found any right answer for my situation.

     

    Note: "header("Location: $url");" runs ok on localhost at my computer, I only got this problem when I upload my project to a hosting.

     

    Thank a lot for helping me!

    Quyen,

  3. Hi,

     

    I just help you to fix the problem. I hope it works fine on your pc. Have a nice day (~_~) !

     

    <?php 
      /* BEFORE YOU RUN THIS FILE, YOU SHOULD CHANGE THE PASSING VALUES  FOR CONSTRUCTOR.
          * THEN IT WILL WORK OK.
       */
      //////////////////////////////////////////////////////////////////////////////////
    
       /*  Acctually This object connect to db, but haven't done anything on the 
        *    database 'mysql' yet.
        */
       $myObj = new DBConnect("localhost","root","","mysql");
       $myObj ->connectToMySQL();
    
       /*
           You need to pass the values to the arguments for the constructor from 
           superclass DBConnect. If not $dbData won't know how to connect to database.
       */
       $dbData = new DBData("localhost","root","","information_schema");
    
       /*
           You need to connect to MySQL before work on any databases.
       */
       $dbData ->connectToMySQL();
    
       /*
           - Because the class DBData defined only one method selectDB(); 
           - Whenever you want to work with a database, you need to connect to MySQL first.
           - In your situation, You didn't call method connectToMySQL() from superclass DBObject.
           --> That's why You cannot select any databases.(Thats why you've got the errors)
       */
       $dbData ->selectDB();
    
       class  DBConnect{
           /////////////////////////////////////////////////
           // PROTECTED PROPERTIES  
           /////////////////////////////////////////////////
           protected $hostname, $username, $password,$db_name, $con ;
    
        /**
          * Constructor
          * @param String $hostname,$username,$password,$db_name. 
          * All information we need to provide whenever connect to db.
          */
           public function __construct($hostname,$username,$password,$db_name){
    
               $this->hostname = $hostname;
               $this->username = $username;
               $this->password = $password;
               $this->db_name = $db_name;
    
           }
    
        /**
          * Connect to MySQL.
          * @return void
          */
           public function connectToMySQL(){
               $this->con = mysql_connect($this->hostname,$this->username,$this->password);
               if($this->con){
                   echo "
    Connected sucessfully to MySQL .
    ";
               }
               else{
                   die( "
    Could not connect to MySQL" . mysql_error() . ".
    ");
               }
           }
         }      
    
       /*  
        * DBData class extends DBConnect
        */
       class DBData extends DBConnect{
           /* This class doesn't define any constructors. Whenever you create a object from  
            * this class, The object will automaticaly refer to constructor of 
            * super class (DBObject class). cause DBData extends from DBConnect class 
            */ 
           public function selectDB(){
               $result = mysql_select_db($this->db_name,$this->con);
               if($result){
                   echo "
    Connected sucessfully to database ' ".$this->db_name." ' .
    ";
               }
               else{
                   die( "
    Could not connect to database ' ". $this->db_name. " '  ".mysql_error() . ".
    ");
               }
           }
       }
    
       /*     You don't need to create a class just for closing a connection. 
        *    This method you can build  in DBConnect or DBObject class. But anyhow this is your option
        *    Maybe you have some special reason to have this class.
        */   
       class DBClose extends DBConnect{
           function closeConnection(){
              mysql_close();
           }
       }
    
       //GOODLUCK
    
    ?>
    

     

    Quyen,

  4. I am getting an error, and i am unsure what i have done wrong.

    LIVE demo - http://www.designvisa.com/beta/include/dbconnect/opendb.php

     

    $vconfig = new VConfig();
    
       //Create objects from DBObject class.
       $myObj = new DBConnect("localhost","$vconfig->user","$vconfig->dbpass","$vconfig->db");
    
       //Call methods of objects.
       $myObj ->connectToMySQL();
    
       $myObj2 = new DBData();
       $myObj2 ->selectDB();
       $myObj2 ->showMessage();
    
    class  DBConnect{
           /////////////////////////////////////////////////
           // PRIVATE PROPERTIES  
           /////////////////////////////////////////////////
           private $hostname, $username, $password, $db_name, $con;
    
       /**
          * Constructor
          * @param String $hostname,$username,$password,$db_name. 
          * All information we need to provide whenever connect to db.
          */
           public function __construct($hostname,$username,$password,$db_name){
               $this->hostname = $hostname;
               $this->username = $username;
               $this->password = $password;
               $this->db_name = $db_name;
           }
    
       /**
          * Connect to MySQL.
          * @return void
          */
           public function connectToMySQL(){
               $this->con = mysql_connect($this->hostname,$this->username,$this->password);
               if($this->con){
                   echo "
    Connected sucessfully to MySQL .
    ";
               }
               else{
                   die( "
    Could not connect to MySQL" . mysql_error() . ".
    ");
               }
           }
    
    
     }      
    
    
    
    class DBData extends DBConnect{
    
    public function selectDB(){
               $result = mysql_select_db($this->db_name,$this->con);
               if($result){
                   echo "
    Connected sucessfully to database ' ".$this->db_name." ' .
    ";
               }
               else{
                   die( "
    Could not connect to database ' ". $this->db_name. " '  ".mysql_error() . ".
    ");
               }
           }
    }
    
    
    
    
    class DBClose extends DBConnect{
       function closeConnection(){
          //Do something else here and at the end you can
          mysql_close();//For example
       }
    }
    

     

    Can anyone help!

     

    100% sure this won't work. I will reply to you soon, cause i am working now. But goodluck.

  5. Thanks Quyen, Just wondering the following:

     

    Say i want to have one file that handles connecting to the database. - opendb.php

    and one that closes the database - closedb.php

     

    is that possible, and how?

     

    Then say i want another a page to handle MYSQL. - fruitdb.php

    How would one go about that?

     

    Hi,

    Sorry I haven't replied to you yet! Cause I just take a look at CSS forum(*_*).

    About your question:

    - To open a connection to a database or close this connection is not complicate, right? But the thing is how to organize your coding in php file?

    For me I won't put them in a seperate files. Cause close or open is methods (behaviors) of objects. With mysql_connect() and mysql_close() Why don't you write some methods like this:

     

    function connectToMySQL(){

    //You write your code here

    }

     

    function closeConnection(){

    //Do something else here and at the end you can

    mysql_close();//For example

    }

     

    And then:

    Whenever you create a object from the class above, after you are done everything like select a database, execute sql queries,....After you're done you just need a line of coding like:

    objectName.closeConnection();

     

    Notes: For me, I don't care much about number of php files, I care more about what my object can do? Is it enough or need some more fields, methods,.... If your object is perfect, that mean you did a great job (*_*). Don't worry about how many php file you going to create, lets care about how many object do u need in your project? And all fields & methods of your objects are enough or not?

     

    And one more thing I guess you need to read some more is about OOP. Cause whenever you want your object do something, you will go and create a object and then call the suitable method of the object for it.

    All the methods you create in your projects are called by objects (*_*).

     

    I am not sure if this could help u! but still hope that you understand what i mean!

    Let me know if you need something!

    Quyen,

  6. Hi kitster79,

    I just take a look at your html and css file. And now I guess I know why you have the purple background between "#indexThmbs" and "#indexHeader1".

     

    Let edit your css file at this ID = "indexThmbsInner" like this:

     

    #indexThmbsInner {

    width: 900px;

    margin-right: auto;

    margin-left: auto;

    height: 130px;

    margin-top: 0px;

    }

     

    I have no idea why you want to put margin-top: 65px; (*_*). But it was the problem for you layout. Check it out soon.

     

    Hope this can help you! have a nice day.

    Quyen,

  7. Hi again,

     

    I just finished it, have look and I hope this could help you a bit (*_*).

    Notes: In this database, I created a table called 'yum' , 2 fields are 'id' and 'name'. When you test this example, try to created a database has the same my database information. If not then you will get some errors. OR you can set the database name and table name in the code below.

     

    DBObject.php

    >
    <?php 
       /* Created by Quyen. 11 July 2009
        *    Email : cuncon.it@gmail.com
        * DBObject.php
        */
    
       /* 
        * I just create a very simple class called DBObject 
        */
       class  DBObject{
           /////////////////////////////////////////////////
           // PRIVATE PROPERTIES  
           /////////////////////////////////////////////////
           private $hostname, $username, $password, $db_name, $con, $table_name;
    
       /**
          * Constructor
          * @param String $hostname,$username,$password,$db_name. 
          * All information we need to provide whenever connect to db.
          */
           public function __construct($hostname,$username,$password,$db_name){
               $this->hostname = $hostname;
               $this->username = $username;
               $this->password = $password;
               $this->db_name = $db_name;
           }
    
       /**
          * Connect to MySQL.
          * @return void
          */
           public function connectToMySQL(){
               $this->con = mysql_connect($this->hostname,$this->username,$this->password);
               if($this->con){
                   echo "
    Connected sucessfully to MySQL .
    ";
               }
               else{
                   die( "
    Could not connect to MySQL" . mysql_error() . ".
    ");
               }
           }
        /**
          * Select a database you will work with.
          * @return void
          */        
          public function selectDB(){
               $result = mysql_select_db($this->db_name,$this->con);
               if($result){
                   echo "
    Connected sucessfully to database ' ".$this->db_name." ' .
    
    ";
               }
               else{
                   die( "
    Could not connect to database ' ". $this->db_name. " '  ".mysql_error() . ".
    ");
               }
           }
        /**
          * Get back the name of database.
          * @return String $db_name
          */        
           public function getDBName(){
               return $this->db_name;
           }
    
        /**
          * Set table name that you want to select data from.
          * @return void
          */        
           public function setTableName($table_name){
               $this->table_name = $table_name;
           }        
    
        /**
          * Get back the name of a table
          * @return String $table_name
          */    
           public function getTableName(){
               return $this->table_name;
           }
    
        /**
          * View data of a table
          */    
           public function viewTableData($db_name,$table_name){
                  mysql_select_db($db_name);
               $sql = "Select * from $table_name";
               $result = mysql_query($sql);
               $count_fields = mysql_num_fields($result); 
               $count_rows = mysql_num_rows($result);
               $index = 0;
               echo "
    </pre>
    <table border="1" width="50%">This is '$table_name' table dataID Fruit name".$row['id']."".$row['name']."</table>
    <br>           "; <br>       }<br><br>   /**<br>      * Show a simple message.<br>      * @return void<br>      */        <br>       public function showMessage(){<br>           echo "<br><br><br>               I don't have much time, because I have something to do tomorrow, then if you<br>               have some time, read some more about MVC (Model - View - Control) to organize your <br>               object better.For now I just put all them together. Work more on your database (*_*)....<br><br>               Have a good time!<br><br>           ";<br>       }<br><br>   }<br>?&gt

     

    CreateObject.php

     

    <?php 
       //Include DBObject.php file 
       include ("DBObject.php");
    
       //Create objects from DBObject class.
       $myObj = new DBObject("localhost","root","","mydb");
    
       //Call methods of objects.
       $myObj ->connectToMySQL();
       $myObj ->selectDB();
    
       $myObj ->setTableName("yum");
       $myObj ->viewTableData($myObj->getDBName(),$myObj->getTableName());
       $myObj ->showMessage();
    ?>
    

     

    If you have any question, just email me at cuncon.it@gmail.com. or leave your reply in this forum. Goodnight.

    Quyen,

  8. hi Quyen,

     

    I get what you are doing, but just one last question if you can help that would be great.

    how to i fetch data from the database using oops?

     

    like say i need to show the table called "yum"

     

    inside the table "yum" it has two rows with data, under the row called "fruit"

    1 - apple

    2 - banana

     

    But i when i run the select fruit from yum;

    it prints both of the fruit - "applebanana"

    what i need it to do is give each fruit a class or a way i can call it by

     

    $class->fruitone;

    $class->fruittwo;

     

    Can you help there?

     

    Did you mean that:

    1. You want to select your data from table called 'yum'. This table has two fields: 'id' and 'fruit'.

    2. You need to select all the records from the table above, and fill up them in a table? like

     

    id name

     

    1 banana

    2 apple

    3 warter melon

    .. ...................

     

    Is that what you mean?(*_*)

    Quyen,

  9. Hi,

    You are welcome, i am not sure this will be a good example for you but I hope so.

     

    DBObject.php

     

    <?php 
       /* Created by Quyen. 11 July 2009
        *    Email : cuncon.it@gmail.com
        * DBObject.php
        */
    
       /* 
        * I just create a very simple class called DBObject 
        */
       class  DBObject{
           /////////////////////////////////////////////////
           // PRIVATE PROPERTIES  
           /////////////////////////////////////////////////
           private $hostname, $username, $password, $db_name, $con;
    
       /**
          * Constructor
          * @param String $hostname,$username,$password,$db_name. 
          * All information we need to provide whenever connect to db.
          */
           public function __construct($hostname,$username,$password,$db_name){
               $this->hostname = $hostname;
               $this->username = $username;
               $this->password = $password;
               $this->db_name = $db_name;
           }
    
       /**
          * Connect to MySQL.
          * @return void
          */
           public function connectToMySQL(){
               $this->con = mysql_connect($this->hostname,$this->username,$this->password);
               if($this->con){
                   echo "
    Connected sucessfully to MySQL .
    ";
               }
               else{
                   die( "
    Could not connect to MySQL" . mysql_error() . ".
    ");
               }
           }
       /**
          * Select a database you will work with.
          * @return void
          */        
          public function selectDB(){
               $result = mysql_select_db($this->db_name,$this->con);
               if($result){
                   echo "
    Connected sucessfully to database ' ".$this->db_name." ' .
    ";
               }
               else{
                   die( "
    Could not connect to database ' ". $this->db_name. " '  ".mysql_error() . ".
    ");
               }
           }
    
       /**
          * Later you can write some methods  to set and get value of Fields (Variables).
          * @
          */    
          public function setDBName()    {}
    
       /**
          * Show a simple message.
          * @return void
          */        
           public function showMessage(){
               echo "
    
    Now you can execute any queries or create a database or do what ever you like (*_*)....
    
                   Have a good time!
               ";
           }
    
       }
    ?>
    

     

    CreateObject.php

     

    <?php 
       //Include DBObject.php file 
       include ("DBObject.php");
    
       //Create objects from DBObject class.
       $myObj = new DBObject("localhost","root","","mysql");
       $anotherObj = new DBObject("localhost","root","","information_schema");
    
       //Call methods of objects.
       $myObj ->connectToMySQL();
       $myObj ->selectDB();
       //$myObj ->showMessage();
    
       $anotherObj->connectToMySQL();
       $anotherObj ->selectDB();
       $anotherObj ->showMessage();
    ?>
    

     

    Have a nice day!

    Quyen,

  10. Hi guys, I have looked everywhere with NO success, I don't understand any of these frameworks that are already out,

    and i have read all the killerphp.com documents and watch all the videos that i can find about OOP and still cant find what i need.

     

    I am new to OOP but know PHP, if someone can PLEASE help me out, and show me an example on how to use OOP to connect to MySQL that would be GREAT!

     

    PLEASE HELP

     

    Thanks

    Hi, I just created an object today, If you like I can share it with you. My object just does something simple like connect to mysql, select any database that you want to work with. Let me know if you interested this.

    Quyen,

  11. Hi,

     

    I think Stefan's right, After you read some more about Model - Control - View, You may understand what does he mean by that.

     

    For now I have some comment for you like these:

     

    for Q2:

    Acctually I don't think there are any rule to say that your class has to be this long or that long. Number of fields and methods in a class, it depends on your object you are creating.

     

    for Q3:

    You should read some more about OOP. if you understand OOP then you might have something to do with this object (the object i mentioned here is about the object in your question Q3). How to organize your php files??? (0_0). Let's think about your question.

    You can have different classes in a file. thats ok. Lets think your php file (You have different classes in this file) look like a library php file wherever you want to create an object, you can include that library file in and create your object.

    You also create different library php files depend on how you want to organize your projects.

     

    Thats all I can say now. Hope it can help you.

    Sorry my english is pretty bad, then still hope that you can understand what i mean.

     

    Quyen,

  12. Hi,

     

    Well, i think it depends on what is your purpose? what do you want it to do? and tags are both very helpful.

     

    programmers use tag :

    1. To create a link to another document, by using the href attribute

    2. To create a bookmark inside a document, by using the name attribute

    example: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_link_test

     

    The tag is used to define a client-side image-map. An image-map is an image with clickable areas.

    The name attribute is required in the map element. This attribute is associated with the 's usemap attribute and creates a relationship between the image and the map.

    The map element contains a number of area elements, that defines the clickable areas in the image map. This example will help you to choose the best options : http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_areamap

     

    Quyen,

×
×
  • Create New...