Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 9 of 9

Thread: sql stuff

  1. #1
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default sql stuff

    okay i have tryed to make this for over 4 hours and still do not get how to do it so here i am

    what i want to do is make a function that can make my sql stuff like this

    Code:
    $userq = select("*", "users", array('aid' => $this->cookies[aid], 'username' => $this->cookies[username], 'password' => $this->cookies[password], 'sesid' => $this->cookies[sid]));
    
    
    $groupq = select("*", "groups", "group = '$this->user[group]'");
    select(the fiealds or the *, what table , a array or the normal for WHERE);

    thank you your help if you can give it.

  2. #2
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    I've made it so it's just array('field' => 'value') not normal, it'll save time in the long run if you ever need to add anything. This should be near enough what you're looking for, took me a few minutes to whip it up.

    PHP Code:
    <?php
    function selectSql$what$from$where null )
    {
        
    $what = ( $what === '*' ) ? '*' '`' $what '`';
        
    $query 'SELECT ' $what ' FROM `' $from '` ';
        if( 
    is_array$where ) )
        {
            foreach( 
    $where as $key => $value )
            {
                
    $query .= '`' $key '` = \'' $value '\'';
            }
        }
        return 
    mysql_query$query );
    }

    ?>
    You'll have to clean the input yourself.


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  3. #3
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    Yo thank you but the bit i do not get is how to make array('field' => 'value','field2' => 'value2','field3' => 'value3') and that would be field = 'value' AND field2 = 'value2' AND field3 = 'value3' and so on.

  4. #4
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    Sorry for two post but would some thing like this do it?

    PHP Code:
    <?php
    function select$type '*'$from$where null )
    {
        
    $count count($where);
        
    $i 1;
        
    $query 'SELECT ' $what ' FROM `' $from '` ';
        if( 
    is_array$where ) )
        {
            foreach( 
    $where as $key => $value )
            {
                
    $query .= ' `' $key '` = \'' $value '\'';
                if(
    $count $i)
                {
                    
    $query .= ' AND';
                    
    $i++;
                }
            }
        }
        else
        {
                die(
    'error in sql missing array');
        }
        return 
    mysql_query$query );
    }

    ?>

  5. #5
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Jewish Bear View Post
    I've made it so it's just array('field' => 'value') not normal, it'll save time in the long run if you ever need to add anything. This should be near enough what you're looking for, took me a few minutes to whip it up.

    PHP Code:
    <?php
    function selectSql$what$from$where null )
    {
        
    $what = ( $what === '*' ) ? '*' '`' $what '`';
        
    $query 'SELECT ' $what ' FROM `' $from '` ';
        if( 
    is_array$where ) )
        {
            foreach( 
    $where as $key => $value )
            {
                
    $query .= '`' $key '` = \'' $value '\'';
            }
        }
        return 
    mysql_query$query );
    }

    ?>
    You'll have to clean the input yourself.
    ]

    Oops sorry, forgot the AND part, but no that wouldn't do it, however this would:

    PHP Code:
    <?php
    function selectSql$what$from$where null )
    {
        
    $what = ( $what === '*' ) ? '*' '`' $what '`';
        
    $query 'SELECT ' $what ' FROM `' $from '` ';
        if( 
    is_array$where ) )
        {
            foreach( 
    $where as $key => $value )
            {
                
    $query .= '`' $key '` = \'' $value '\' AND ';
            }
            
    $query preg_replace'#AND $#'''$query );
        }
        return 
    mysql_query$query );
    }

    ?>


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  6. #6
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    Cool thanks as i want to learn from this how dose
    PHP Code:
    $query preg_replace'#AND $#'''$query ); 


    like in how dose it know to remove the AND at the end??

  7. #7
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by VistaBoy View Post
    Cool thanks as i want to learn from this how dose
    PHP Code:
    $query preg_replace'#AND $#'''$query ); 


    like in how dose it know to remove the AND at the end??
    the $ = end of string, so it will only remove it if it matches "AND " then the end of the string.


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  8. #8
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    Umm ye i got an issue with it okay it only dose it with in classes funny?

    okay this is my code

    PHP Code:
           $getkeyq $this->db->select('*''keys', array('keycode' => $keycode));
            
    $getkeyf $this->db->fetch_array($getkeyq);
            
    $getscriptq $this->db->select('*''scripts', array('script' => $script));
            
    $getscriptf $this->db->fetch_array($getscriptq);
                
            if(
    $this->db->num_rows($getkeyq) == '1' && $this->db->num_rows($getscriptq) == '1' ) { 
    and if i input the right data it still saying its not right like it not finding any rows but there is but when i tack out the mysql_query bit in my data_layer and echo the $getkeyf to see what it shows it shows "Resource id #8" and not a prober query???
    Last edited by VistaBoy; 13-08-2008 at 11:13 AM.

  9. #9
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    Sorry for two post but i fixed the error it was mt clean it was to go it sriped all the contents.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •