If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > search db by ID

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-21-08, 10:10
ruler ruler is offline
Registered User
 
Join Date: Mar 2008
Posts: 16
Question 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
Reply With Quote
  #2 (permalink)  
Old 03-21-08, 10:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-21-08, 10:37
ruler ruler is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 03-21-08, 10:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
sqlzoo.net
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-21-08, 10:40
ruler ruler is offline
Registered User
 
Join Date: Mar 2008
Posts: 16
thank you i will have a look
Reply With Quote
  #6 (permalink)  
Old 03-21-08, 11:14
ruler ruler is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 03-21-08, 11:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
what's your favourite search engine? google? yahoo? msn?

do a search for sql tutorial

there are thousands and thousands of them
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 03-22-08, 04:48
smartsoft smartsoft is offline
Registered User
 
Join Date: Jul 2007
Location: Africa
Posts: 7
beta still you consult someone who is very good in MysQL
Reply With Quote
  #9 (permalink)  
Old 03-22-08, 04:52
ruler ruler is offline
Registered User
 
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
Reply With Quote
  #10 (permalink)  
Old 03-22-08, 07:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 03-22-08, 07:56
ruler ruler is offline
Registered User
 
Join Date: Mar 2008
Posts: 16
i got the help i asked for and problem solved thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On