Results 1 to 3 of 3

 

Thread: php mysql query based on previous query?

  1. #1
    curiouser and curiouser

    Status
    Offline
    Join Date
    Sep 2003
    Location
    uk
    Posts
    659
    Thanks
    1
    Thanked 0 Times in 0 Posts


    I have a 2 databases one containing information, one containing photos.

    I have all the information appearing on screen each record in a seperate div,


    what i need is to access the photos database and grab 1 photo for each information set.

    the photos are all tagged with the sime id the information is?

    any ideas if this can be done,

    regards andy

    p.s. sorry if its not explained well

  2. #2
    Super Member

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Costa Del Sheffield
    Posts
    2,838
    Thanks
    5
    Thanked 18 Times in 14 Posts
    explained terribly

    might be way off the mark but something like...

    PHP Code:
    $getinfomysql_query("SELECT * FROM information") or die("Database Error"  mysql_error());
    while (
    $data_infomysql_fetch_array($getinfoMYSQL_ASSOC)) {

    // here we can call records using $data_info[field-name];

    // presuming you have a ID field in your 'information' database...
    $ID_for_image $data_info[ID];
    $getimagemysql_query("SELECT * FROM images WHERE id = $ID_for_image") or die("Database Error"  mysql_error());
    while (
    $data_imgmysql_fetch_array($getimageMYSQL_ASSOC)) {

    // here we can call records using $data_img[field-name];

    }


    // here we can call records using $data_info[field-name];  (still)


    Dan Morley
    alpharooms.com
    daniel at alpharooms dot com - Hotels, Flights, Airport Transfers, Care Hire + More! sign up
    My Blog | Cheap Holidays

  3. #3
    Registered User

    Status
    Offline
    Join Date
    Dec 2004
    Location
    Batley, West Yorks
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can also do this by joining the 2 tables together:

    PHP Code:

    $sql 
    "select database1.tablename.*,database2.tablename.image from database1.tablename inner join database2.tablename using (id)";

    $rowset mysql_query($sql);
    while(
    $row mysql_fetch_array($rowset))
    {
        echo 
    $row['information'];
                    echo 
    $row['image '];

    This query is joining 2 tables from 2 separate databases - if your tables are in the same database you can just remove the database names from the SQL command. I wasn't sure from your post whether you if your images were in a separate database or a separate table.

    This query will show 1 photo per piece of information.

    Simon
    Up to 12% commission on aromatherapy, incense, bath, gifts, massage + more.

    £10 CASH BONUS on 1st £150 of sales.

    http://www.reallyrelaxing.co.uk/affiliate_scheme.php



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Best PHP & MySQL
    By Stellar in forum Programming
    Replies: 13
    Last Post: 28-07-06, 04:27 PM
  2. MySQL query
    By Brett in forum Programming
    Replies: 6
    Last Post: 23-02-05, 11:56 AM
  3. Anyone anygood with xml, php, mysql and Affiliate Window
    By AnnonnyMouse in forum Affiliate Marketing Lounge
    Replies: 1
    Last Post: 23-09-04, 11:00 AM
  4. PHP & MYSQL
    By Affiliates4u in forum Programming
    Replies: 8
    Last Post: 13-01-03, 08:12 PM

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2