SitePoint Sponsor

User Tag List

Page 2 of 9 FirstFirst 123456 ... LastLast
Results 26 to 50 of 219

Thread: PHP Quiz

  1. #26
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm Matt dude! can't you see my signature (it says Matt there)? someone (naramation) said the other day that he couldn't see sigs.


    anyway, anyone can do the next question, i can't really think of anything right now.

  2. #27
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't see your sig right now... I see everyone elses though....

    EDIT: actually i see it on the other previous post now, but not the one right above this.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #28
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's not on the one above yours because i'm not showing it. i usually only include my sig the first time i post in a thread... just to keep it cleaner.


    who's gonna come up with the next question?

  4. #29
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yuhhu, Maattt....

  5. #30
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yuhoo, i said i can't think of anything.

  6. #31
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming Matt means he's letting someone else post a question, here goes:

    Let's say you have a SQL DDL script like this:
    Code:
    /**
    * File: create_tables.sql
    * Begin date: 3rd Jan 2003
    * TODO:
    add linx_group table to contain group_id details
    */
    
    /* Table: linx_user
    * Description: stores login information for users
    */
    CREATE TABLE linx_user (
    user_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(30) NOT NULL UNIQUE,
    password VARCHAR(16) NOT NULL,
    group_id SMALLINT UNSIGNED NOT NULL
    );
    INSERT INTO linx_user (user_id, username, password, group_id)
    VALUES ('', 'admin', PASSWORD('admin'), 0);
    
    /* Table: linx_cat
    * Description: stores category information
    */
    CREATE TABLE linx_cat (
    cat_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    cat_pid INT UNSIGNED NOT NULL,
    name VARCHAR(100) NOT NULL,
    description TEXT,
    UNIQUE (cat_pid, name),
    FOREIGN KEY (cat_pid) REFERENCES linx_cat (cat_id)
    ON DELETE CASCADE
    );
    INSERT INTO linx_cat (cat_id, cat_pid, name, description)
    VALUES ('', 0, 'General', 'A category for everything and anything!');
    How would you write a PHP script so as to run the queries in the script (create_tables.sql)? Assume the database is MySQL. Note the existence of comments in the script, and it is good form to let the user know of success/failure [img]images/smilies/smile.gif[/img]

    EDIT: basically the idea is to create an installer script for setting up database tables - should be useful (and easy!) to anyone distributing his/her own PHP software packages
    Last edited by redemption; Apr 3, 2003 at 21:38.

  7. #32
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll let someone else answer for once . Although if they post crap, i'll post something better
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  8. #33
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you don't want me to answer these things, just say so.

    i'm gonna have to do this read and parse a SQL file for the installer on my forum system. so i've already thought about it. the only issue i'll have is having to add a possible prefix to the table names (while accounting for the names possibly appearing in column values).

    anyway, here's my code:

    PHP Code:
    <?php

    // Use implode('', file('./create_tables.sql')) for PHP < 4.3.0
    $contents get_file_contents('./create_tables.sql');

    // Not just explode() on ; because ; can be in column values
    $queries preg_split('/; *(?:\r\n?|\n)\s*/'$contentsPREG_SPLIT_NO_EMPTY);

    foreach (
    $queries as $query)
    {
        
    mysql_query($query) or die(mysql_error());
    }

    ?>

    BTW, MySQL 4.1 is supposed to allow multiple queries in 1 mysql_query() call (or maybe a different function for that). then you could just send the whole file contents in 1 call.

  9. #34
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for DP2, the installer is actually completely written with MySQL function calls, and seperated into steps, so that the script won't time-out.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  10. #35
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does that take care of the comments?


    About multiple queries in one call - great! I didn't know that. Wait... Is it a going to be a MySQL query or a new PHP function?

  11. #36
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by redemption
    Does that take care of the comments?
    nope, the comments are sent in the queries and MySQL ignores them.


    Quote Originally Posted by redemption
    About multiple queries in one call - great! I didn't know that. Wait... Is it a going to be a MySQL query or a new PHP function?
    it's done with the MySQL's API functions. so PHP would need to extend its MySQL function wrapper to handle the new option CLIENT_MULTI_QUERIES in mysql_connect() according to the manual and the multi result set fetching functions (for multiple SELECTs anyway). for more info:

    Changes in release 4.1.x
    C API Handling multiple query executions

    edit note: i think there's a mistake in the code example in that second link.

    /* Connect to server with option CLIENT_MULTI_QUERIES */
    mysql_real_query(..., CLIENT_MULTI_QUERIES);

    should be

    mysql_real_connect(..., CLIENT_MULTI_QUERIES);

    i think.
    Last edited by DR_LaRRY_PEpPeR; Apr 3, 2003 at 22:43.

  12. #37
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DR_LaRRY_PEpPeR
    nope, the comments are sent in the queries and MySQL ignores them. [img]images/smilies/wink.gif[/img]


    it's done with the MySQL's API functions. so PHP would need to extend its MySQL function wrapper to handle the new option CLIENT_MULTI_QUERIES in mysql_connect() according to the manual and the multi result set fetching functions (for multiple SELECTs anyway). for more info:

    Changes in release 4.1.x
    C API Handling multiple query executions
    Yep that's right there. Why did I go and remove comments in the first place (long time ago)? Hmm... I think I tried to do it with hash comments '#' and it didn't work? Oh well.


    That's good to know of... thanks.

  13. #38
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Next question then ...

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  14. #39
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, seen as nobody's posted a question

    Use a PHP function to find my message in the following:

    Code:
    WWVwLCBJIHVzZWQgYmFzZTY0X2VuY29kZSgpIC0gU2VhbiA6KQ==
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  15. #40
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    base64_decode('WWVwLCBJIHVzZWQgYmFzZTY0X2VuY29kZSgpIC0gU2VhbiA6KQ=='); 
    Maybe... don't have PHP to test it on where I am right now.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  16. #41
    SitePoint Addict sojomy's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ran it through the Sojomy Universal Decoder
    PHP Code:
    sojomy_decode('WWVwLCBJIHVzZWQgYmFzZTY0X2VuY29kZSgpIC0gU2VhbiA6KQ==''English'); 
    and it said something about Cross Dressing. Is that right?

  17. #42
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by seanf
    Ok, seen as nobody's posted a question

    Use a PHP function to find my message in the following:
    Code:
    WWVwLCBJIHVzZWQgYmFzZTY0X2VuY29kZSgpIC0gU2VhbiA6KQ==
    Sean images/smilies/smile.gif
    The answer is
    Yep, I used base64_encode() - Sean images/smilies/smile.gif

    Seing that cyborg was first i guess it's his turn to ask a question.

  18. #43
    SitePoint Zealot nsr81's Avatar
    Join Date
    Nov 2002
    Location
    B'klyn, NY
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cyborg_from_dh is correct.

    Result: Yep, I used base64_encode() - Sean [img]images/smilies/smile.gif[/img]

    edit: think I'm a little late

  19. #44
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [ Edit: Missed second page, ]

    I'm asking one

    PHP Code:
    <?php

    $array 
    = array("d""m""n");
    echo 
    "GOOD ";
    asort($array);
    for (
    $i 2$i <= count($array); $i--)
    {
    echo 
    $array[$i]++;
    }

    Try that one on

  20. #45
    SitePoint Zealot nsr81's Avatar
    Join Date
    Nov 2002
    Location
    B'klyn, NY
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    output: GOOD bjo

  21. #46
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Edited it, I screwed up

  22. #47
    SitePoint Zealot nsr81's Avatar
    Join Date
    Nov 2002
    Location
    B'klyn, NY
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ++ in "echo $array[$i]++;" seems odd.

  23. #48
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's what it should be

  24. #49
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I probably should've tested that prior

    Ok, after a few tweakings to make it work:

    PHP Code:
    <?php 

    $array 
    = array("d""m""n" ); 
    echo 
    "GOOD "
    asort($array);
    natsort($array);
    rsort($array);
    foreach(
    $array AS $key=>$value)
    {
    $var = ++$value;
    echo 
    $var;
    }

  25. #50
    SitePoint Member
    Join Date
    Feb 2003
    Location
    United States
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would echo
    GOOD one
    to the browser.


Bookmarks

Posting Permissions

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