Php class question..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yusuf ali bozki
    New Member
    • Dec 2010
    • 4

    Php class question..?

    i want My database in all link_id data print screen. my database link_id's 10,22,30,40,45

    Code:
    <?php 
    class VeriCek{
        public $dbhost = 'localhost';
        public $dbuser = 'root';
        public $dbpass = '1';
        public $dbname = 'linkekle';
        public function BaglanDB(){
        if( $link ){
            return $link;
        }
            
        $link = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpass) or die('Sunucuya Bağlanamadı.' );
        mysql_select_db($this->dbname, $link) or die('Sunucuya Bağlanamadı.');
        mysql_query("SET NAMES UTF8");
        return $link;
        }
    
        public function cekhepsi(){
        $sql = "select * from linkler";    
        $query = mysql_query($sql,$this->BaglanDB());
        while ($rs=mysql_fetch_assoc($query)){
        return $rs["link_id"];
        }
        }
    }
    
    $deneme = new VeriCek();
    [B]echo $deneme->cekhepsi();[/B]
    
    ?>
    this line "return $rs["link_id"];" return the "10" database in the only first.
    i want all link_id print screen..
    please help me. :)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    then you must call return after finishing the while() loop.
    Code:
    $id = "";
    while ($rs=mysql_fetch_assoc($query)){
    $id .= $rs["link_id"];
    }
    return $id;

    Comment

    • yusuf ali bozki
      New Member
      • Dec 2010
      • 4

      #3
      Thank you very much.. :)

      Comment

      • Samishii23
        New Member
        • Sep 2009
        • 246

        #4
        May I make a suggestion?
        When you make a class, any variables or functions that are for "in-Class" only, set to private.

        Comment

        Working...