many thanks for your swift replies. I apologize for my messy code, i was just experimenting and so i didn't indent / name my variables.
the join function is what i was thinking of. I figured this sort of thing probably exists, but i was having a hard time finding out about it.
The problem is, i'm not sure if it will be adequate in my circumstances, having researched the function. If you'll allow me to explain a little..
In my database I have three tables.
Table one - a list of destinations and companiess that represent them.
Table two - a list of the companies.
Table three - a list of personnel.
Table one: port
| NAME | COUNTRY | LINERS |
|______ |_____|__|
| Aden | Yemen | TC EF |
|___ |_____|_____|
Table two: liners
| ID | LINER | LINE_MANAGER | EMAIL |
|_ |_______|_______|________|
| TC | Test Company | MK | admin@tc.com |
| EF | Eastern Freight | JB | admin@ef.com |
| |_________|_______|___________|
Table three: people
| ID | NAME | EXTENSION |
|__|_______|____|
| MK | Mike Karachi | 111222 |
| JB | Joe Bloggs | 333444 |
||________|_______|
Now currently, i have a ajax instant search script. so if i type "aden" it'll query the ports table like this.
[INDENT]"SELECT * FROM port WHERE NAME LIKE %$search%"[/INDENT]
This bit works great. it does a while loop and returns any records with 'aden' in it.
But now, on each record that is returned, i would like to do another query. This is where i'm having the problem.
So let's say i've got my port of Aden record. In the liners field, i have TC EF.
I now perform an explode function on the field, seperated by a space:
[INDENT]$linernames = explode(" ", $row['LINERS'])[/INDENT]
This also works fine. But now, i want to perform an SQL query on each record returned (there may be more than just the one 'Aden', and they may have different data in the 'liners' field.), using this information i just got, within the new query... for example.. (i know this code wouldn't work in it's current form.. i'm hoping that you can understand my logic if i write it this way though.)
[INDENT]
foreach($linernames as $linerID){
$linerSQL = "SELECT * FROM liners WHERE ID=$linerID";
$linerRESULT = mysql_query($linerSQL);
while($linerROW = mysql_fetch_array($linerRESULT))
{
echo $linerROW['LINE_MANAGER'];
}
}
[/INDENT]
So in theory... i would be:
- grabbing the port i searched for from the database.
- Looking at the liners field on the port record.
- blowing that data up into an array, by exploding it with the space character.
- doing a query on each object in this array.
I'm not sure if this is possible with the join function, since i am only getting the list of liners AFTER i have done the initial query, and performed the explode function.
I'm wondering if you guys had any ideas.
I would like to thank you in advance for taking the time to read this, and for any possible contribution you may have.
Regards,
Josh