Page 1 of 7 12345 ... LastLast
Results 1 to 10 of 62
  1. #1
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default [TUT] Performing a simple database select query with PHP

    Pretty simple, a lot of people use PHP files too do this,

    PHP Code:
    <?php
    mysql_query
    "QUERY" );
    ?>
    Here are a few things;

    SELECT - Select's from your database
    * - Wildcard; grabs everything matching your query critera.
    WHERE - Where field name has the result of

    So here's an example query, using the three of them;

    Code:
    SELECT * FROM `users` WHERE `id` = '1'
    And a bit of PHP..

    PHP Code:
    <?php
    // Assume we're already connected to the database ;)

    // Querying the database..
    $query mysql_query"SELECT * FROM `users` WHERE `id` = '1'" );

    // While - gets all the results and does what you want to do with them in the while statement, and continously repeats them.
    while( $object mysql_fetch_object$query ) )
    {
           echo 
    $object->username// You can use object or arrays, I'm an object fan. We're grabbing the field name "username"
    }
    ?>
    That above, is just a simple select statement, and will repeat any result with the field named "id" which has the result of 1.
    Last edited by Calon; 09-12-2008 at 10:30 PM.

  2. #2
    Join Date
    Jun 2007
    Posts
    240
    Tokens
    0

    Default

    Gee, this is a pretty good tutorial

  3. #3
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by MasterFM View Post
    Gee, this is a pretty good tutorial
    Might help the new coders out! Like you! aha.

  4. #4
    Join Date
    Jun 2007
    Posts
    240
    Tokens
    0

    Default

    OOOooo.
    FAILLLLL


    Edited by Yoshimitsui (Forum Super Moderator): Please do not make pointless comments.
    Last edited by Yoshimitsui; 10-12-2008 at 05:57 PM.

  5. #5
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    INDENTATION CALON, INDENTATION!!!!

    PHP Code:
    <?php
    //connect here

    //perform the query
    $query mysql_query"SELECT * FROM `users` WHERE `id` = '1'" );

    //while loop for echoing out zem all
    while( $object mysql_fetch_array$query ) )
    {
          echo 
    $object['username'];
    }
    ?>


    www.fragme.co = a project.

  6. #6
    Join Date
    Sep 2008
    Location
    UK
    Posts
    3,670
    Tokens
    0

    Latest Awards:

    Default

    Didn't you post this on faildev? I mean codedev.

    Edited by Meti (Forum Moderator): Please don't post to cause arguments.
    Last edited by Meti; 10-12-2008 at 03:34 PM.
    Back for a while.

  7. #7
    Join Date
    Jun 2007
    Posts
    240
    Tokens
    0

    Default

    Quote Originally Posted by Source View Post
    INDENTATION CALON, INDENTATION!!!!

    PHP Code:
    <?php
    //connect here

    //perform the query
    $query mysql_query"SELECT * FROM `users` WHERE `id` = '1'" );

    //while loop for echoing out zem all
    while( $object mysql_fetch_object$query ) )
    {
          echo 
    $object->username;// You can use object or arrays, I'm an object fan. We're grabbing the field name "username"
    }
    ?>
    lmaocopters


    Edited by Yoshimitsui (Forum Super Moderator): Please do not continue to make pointless comments.
    Last edited by Yoshimitsui; 10-12-2008 at 06:00 PM.

  8. #8
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Source View Post
    INDENTATION CALON, INDENTATION!!!!

    PHP Code:
    <?php
    //connect here

    //perform the query
    $query mysql_query"SELECT * FROM `users` WHERE `id` = '1'" );

    //while loop for echoing out zem all
    while( $object mysql_fetch_object$query ) )
    {
          echo 
    $object->username;// You can use object or arrays, I'm an object fan. We're grabbing the field name "username"
    }
    ?>
    It was an example, I can't indent in firefox using tab. I would have otherwise.

    Quote Originally Posted by Excellent2
    Didn't you post this on faildev? I mean codedev.
    Nothing fails worse than you. Yes I did, the more people the tutorial helps the better.
    Last edited by Calon; 09-12-2008 at 10:27 PM.

  9. #9
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    5 spaces, SPACES!

    Ok, I'll stop with the over exaggeration now.


    www.fragme.co = a project.

  10. #10
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Source View Post
    5 spaces, SPACES!

    Ok, I'll stop with the over exaggeration now.
    Thank you!

    I never use spaces, even though firefox if I use tab they automatically convert.

Page 1 of 7 12345 ... LastLast

Posting Permissions

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