Forum Moderators: coopster
There are two tables: `user` and `service`
This is all done using PHP and MySQL:
Step 1) An intial lookup is performed on the `user` table to find all possible matches for $lastname. Unique $username identifiers are extracted.
Step 2) A lookup on the `service` table is performed, matching each $username. A check for matching $date is performed. All matching fields are returned to the user.
Step 3) Step 1 may find matching $lastnames, but step 2 may fail because of an incorrect/omitted $date. In case that happens, I want to extract all matching records from the `service` table, no matter the $date.
Now, here's the real question: Should I store the results from step 1 in temporary arrays, or should I redo the SQL query from step 1 before step 3?
Which one is more efficient? ... both timewise as well as server load?
<added>fewer sql accesses is better but how many records are we talking about?
Are you using mysql_fetch_array (or something like it) to read the recs into an array? If so you could check the date while putting it into the array and building two arrays then.
What about selecting them regardless of date and then iterate through the array and do your date distinction in a loop?
Well, but the array can be really big then ..
eg.
$query_data = fetch_data_from_db<do something>
$query_data = fetch_data_from_db
<do something>
is not as effecient as:
$query_data = fetch_data_from_db<do something>
<do something>
Allen
1) lookup in `user`
2) while($get = mysql_fetch_row($lookup)) {
lookup in `service`
}
3) if 2 returns no matches {
lookup in `service` without matching date
}
Speaking of nothing .. Is there a simple way I can (in step 2)lookup all usernames in an array without doing OR ... OR ... OR, thus eliminating the while loop?
'Cause I just realized that this method is going to perform maybe hundreds of queries in the while loop, and I don't want that...
I want to join the `user` and `service` tables.
Then, I want to find a field 'misc' in `service` that matches $date, and field 'persinfo' in `user` that matches $lastname. Both rows should have identical 'username' fields.
Don't know if what I just said makes sense?