Results 1 to 11 of 11

Thread: search db by ID

  1. #1
    Join Date
    Mar 2008
    Posts
    16

    Question Unanswered: search db by ID

    i have searched before asking here for help and there is so much to look through but its like looking for a needle in a haystack
    i have a simple db setup and using php i can connect, get data from it perfectly but i dont know the best way to get the data from the db.

    i am using $HTTP_GET_VARS['id'] to get the ID from the address bar and then trying to use the number so that it will list the whole row of the ID in the db. i think its just the main loop i am not sure about and what mysql commands to use. is there a fast and easy way to do this (if anyone understands what i mean).

    the code i have to connect to my db is what i have below (and works) and i have also built the db into my forum so i can do more with it.

    Code:
    $query = "SELECT Id, Name, Address FROM phpbb_private_data";
    $result = mysql_query($query)
    or die("Query Failed: " . mysql_error());
    if anyone has any tips or useful links i'd be much appreciated
    thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    a fast and easy way would be to add a WHERE clause to that query:

    ... WHERE Id = value

    and of course value would be the sql-injection-safe value from your url
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2008
    Posts
    16
    do you know of any demo's that might be useful for this as i am a total novice. i have no idea where to look but i am keen to learn. thanks for your reply

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    sqlzoo.net
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Mar 2008
    Posts
    16
    thank you i will have a look

  6. #6
    Join Date
    Mar 2008
    Posts
    16
    that site doesnt help at all sorry. on the SELECT
    WHERE tab i click submit query leaving what was default settings on there and their site gives errors. murphys law

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what's your favourite search engine? google? yahoo? msn?

    do a search for sql tutorial

    there are thousands and thousands of them
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Jul 2007
    Location
    Africa
    Posts
    7
    beta still you consult someone who is very good in MysQL

  9. #9
    Join Date
    Mar 2008
    Posts
    16
    thats why i was asking on this forum, i was told that this forum was supposed to be pretty good for getting help

  10. #10
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by ruler
    ...this forum was supposed to be pretty good for getting help
    it is!!!

    you asked how to get the row for a specific ID, and i said you need a WHERE clause

    you then asked for a demo and i gave you a link to a site where you can actually try out your SQL

    what additional help would you like to have?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  11. #11
    Join Date
    Mar 2008
    Posts
    16
    i got the help i asked for and problem solved thanks

Posting Permissions

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