English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Okay I have a database of people that work in certain cities. I have a second database with other (secondary) cities (near by) that they work in. What I want to do is go into the first database and see if there is no one listed for that city. If so, go into the other database and find those who have that city listed as a secondary city. Then get their ID and go back into the first database and get their info (using ID).

Code:
check for primaries
if($cat_rows == 0)
{
$cat_altresult = DatabaseSelect(MY FUNCTION.. ITS FINE searches for secondary cities get array??);
$cat_rows = sizeof($cat_altresult);

if($cat_rows != 0)
{
$alt_msg = "blah";
}
else
$alt_msg = "blah blah";
}

Take IDs from secondary cities, go into primary table and gather info for EVERYONE who has that city listed as a secondary.

Getting the multiple rows is my problem... i think... someone recommend a join, but I am not sure how to do this on two databases. Thanks

Someone recommend a join, but Im n

2006-07-26 04:52:58 · 3 answers · asked by Duds331 5 in Computers & Internet Programming & Design

I meant tables... :\ same DB two tables... my bad

2006-07-26 05:05:34 · update #1

3 answers

It works best if you are using two tables in one database, not two independant databases.

A join is just a select statement using different tables.

Say you had a table xxx and a table yyy. xxx is about your customers and yyy has city info. Assuming your xxx file has a city id for each entry that correspoonds to a city_id field in yyy:

SELECT * FROM xxx, yyy WHERE xxx.city_id = yyy.city_id

2006-07-26 05:03:24 · answer #1 · answered by sheeple_rancher 5 · 8 1

I don't think you need to do a join. Are you using a MySQL db or something else?

I recommend, whatever you use, to use PDO as an abstraction layer to your database. Using PDO you can get a result set from your query and then loop through each result with a for each statement.

More info on setting up and using PDO can be found http://us3.php.net/manual/en/ref.pdo.php

If PDO is not an option, most DB functions allow you to loop through a result set using a while loop like:
while ($rs = fetchRow($resultSet)){
//do stuff with the data
}

2006-07-26 04:57:05 · answer #2 · answered by John J 6 · 0 0

i won't be able to take care of to workout all of your source code, yet i visit provide it a try.... a million. the first aspect i might want to do is to get the total form of information you've interior the database. you're waiting to attempt this by using calling a question some thing like: 'ensure on count number huge variety([your_primary_field]) as numrecs from tutorials' ... $numofrecs = $row['numrecs']; 2. ensure on on what volume information you opt for to coach on an internet site. so in case you 'numrecs' is 31, and also you want 10 per website, you'll opt for say 4 pages. optimal proper? $recperpage = 10; $numberofpages = ceil ($numofrecs/$recperpage); 3. you may want to get yet another huge variety it is the starting up aspect the position you opt for to start up counting the subsequent '$recperpage' information. the kind you'll artwork that out is by ability of.. $starting_record = ($current_page_num* $recperpage)+a million; so if you're on website 3, you've done (3*10)+a million information, subsequently your starting_record is thirty first record. 4. you're waiting to then adjust your ensure on statement to coach shrink factors.... ensure on * FROM tutorials the position subcat = '$sub' and prestige='2' shrink $starting_record, $recperpage; want that receives you began. it truly isn't any longer the cleanest of codes, besides the easy incontrovertible certainty that it might want to do.

2016-11-26 00:51:41 · answer #3 · answered by ? 3 · 0 0

fedest.com, questions and answers