www.webdeveloper.com
Results 1 to 5 of 5

Thread: Putting data in array

  1. #1
    Join Date
    Jan 2008
    Posts
    123

    Putting data in array

    Hello all,

    I'm working with a database someone else started and I'm having difficulty cross referencing data in tables.

    Basically, one table contains email addresses and instance_ids and another table contains instance_ids and file locations. I need someone to be able to enter their email address and get the corresponding files.

    I'm able to check email addresses and return all the instance_ids associated with it by doing:

    PHP Code:
    $testData "email_address='xxx@xxx.com'";
        
        
    $result mysql_query("SELECT * FROM ride_emails WHERE "$testData$connect);
        
        while(
    $row mysql_fetch_array($result)){
          
          echo 
    $row['email_id'];
        
        } 
    Right now I'm trying to store those instance_ids in an array, use that array to check for the matching instance_ids in the table that contains the file locations, then return the file locations in the same row.

    Does this sound like the best plan?

    Can anyone give me some help in achieving this? I'll be working on trying to make this work, but I'd appreciate any help or advice.

    Thanks.

    --thesprucegoose

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    You can get all the files associated with a single e-mail address with a single query. Because I don't know what the tables are or their structure, I had to be imaginative let me know if you need any help.

    Code:
    select file from `tablewithfiles`,`tablewithemails` where tablewithfiles.instanceid = tablewithemails.instanceid and tablewithemails.emailaddress = 'entered email address'
    That query will return all the files associated with a particular e-mail address.

  3. #3
    Join Date
    Jan 2008
    Posts
    123
    Thanks for the reply:

    Something like this?

    PHP Code:
    $testData "xxx@xxx.com'";
        
        
    $result mysql_query("SELECT instance_photofolder FROM ride_instances WHERE ride_emails.instance_id = ride_instances.instance_id AND ride_emails.email_address = " $testData$connect);
        
        echo 
    mysql_result($result); 
    It's not returning anything. Email address is correct.

    I've attached pictures of the table headers to be sure I've explained myself correctly.

    Thanks,

    --thesprucegoose
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    You could also use a join.

  5. #5
    Join Date
    Dec 2005
    Posts
    2,984
    You have to put in both tables after FROM, not just one.

    Code:
    mysql_query("SELECT instance_photofolder FROM ride_instances,ride_emails WHERE ride_emails.instance_id = ride_instances.instance_id AND ride_emails.email_address = " . $testData, $connect);

Thread Information

Users Browsing this Thread

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

Posting Permissions

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



Recent Articles