Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2010
    Posts
    51

    help me with an sql command

    not sure if this is in the write section but can anyone help me with an sql command, Basically i have 2 tables
    -list
    -store

    now in plist each record has 3 colums for each record so id wich is genereated, title and a field called uid, uid has values which are numbes, all i want is a sql command that will search for an id in pid and then get the uid resulr. so far i have
    PHP Code:
     'SELECT `pid` FROM `list`  WHERE pid = "1" 
    that gets the row now i just need it to get the last bit any ideas

  2. #2
    Join Date
    Dec 2007
    Location
    Indiana, USA
    Posts
    16,086
    Code:
    SELECT uid FROM list WHERE pid='1';
    Michael Denney - MDDHosting LLC
    New shared plans for 2016! Check them out!
    Highly Available Shared, Premium, Reseller, and VPS
    http://www.mddhosting.com/

  3. #3
    Join Date
    Sep 2010
    Posts
    51
    Thanks, muchas gracias.

    Any chance you can help me build on that further, basically the results from
    PHP Code:
    SELECT uid FROM list WHERE pid='1'
    would give me a list of ids ie 3 or 3,4,5 so what i want it to do is take the uids results and split away any commers and then run another query for each output to search the colume names uid in the table store. and bring back the entire row. The row table store consists of uid, url, image, title, description,

    I was told the query mysql_fetch_assoc may be usefull, not sure if it helps but the sql will be used in a php script.

    Much appreciated

  4. #4
    You're request is still a little vague, but from what I'm gathering you're wanting to grab all of the fields in your "list" table.

    If your "list" table contains the fields (uid, url, image, title, description) then you could do a simple PHP loop to output the results;

    PHP Code:
    $query mysql_query("SELECT * FROM list WHERE pid = '1');
    while (
    $row = mysql_fetch_array($query)) {
         echo 
    $row['uid'] .'-'. $row['url'] .'-'. $row['image'] .'-'. $row['title'] .'-'. $row['description'];

    This would effectively grab all rows where the "pid" was equal to 1 and then loop through those rows and print out the data in each field.

    This can be done different ways, but this is one of the simplest ways.

    Hope this helps!

  5. #5
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    If you have the pid from the list table and you want the other data from the corresponding items in the store table, you can use a JOIN to link the two tables together and get the results you want from a single query.
    Code:
    SELECT `store`.`uid`, `url`, `image`, `title`, `description`
    FROM `store` JOIN `list` USING (`uid`)
    WHERE pid='1';
    Use hostlighter's PHP code to loop through the results.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  6. #6
    whenever you want to retrieve the data form two different table then you use the SELECT Command.

  7. #7
    Join Date
    Aug 2010
    Posts
    39
    Quote Originally Posted by imryan View Post
    not sure if this is in the write section but can anyone help me with an sql command, Basically i have 2 tables
    -list
    -store

    now in plist each record has 3 colums for each record so id wich is genereated, title and a field called uid, uid has values which are numbes, all i want is a sql command that will search for an id in pid and then get the uid resulr. so far i have
    PHP Code:
     'SELECT `pid` FROM `list`  WHERE pid = "1" 
    that gets the row now i just need it to get the last bit any ideas
    I don't understand what you exactly want. Canyou give some examples of records in tables and tell us what your query result need to be ?
    Thanks

Similar Threads

  1. Help in sql queries and insert command
    By zedthrone in forum Programming Discussion
    Replies: 3
    Last Post: 11-10-2008, 07:51 AM
  2. sql command to save image
    By michael1234539 in forum Programming Discussion
    Replies: 8
    Last Post: 03-25-2008, 04:07 PM
  3. Need SQL command for this
    By Jeff - Exceed in forum Hosting Security and Technology
    Replies: 3
    Last Post: 04-20-2006, 08:07 AM
  4. SQL command Help! List DB
    By DigiCrime in forum Hosting Security and Technology
    Replies: 3
    Last Post: 11-07-2002, 03:50 PM
  5. Ensim SQL command
    By Acronym BOY in forum Hosting Security and Technology
    Replies: 5
    Last Post: 08-24-2002, 11:58 AM

Posting Permissions

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