Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
multuple queries for different tables in one page
Old 01-12-2012, 02:30 PM multuple queries for different tables in one page
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Hello guys,

I'm doing some alerts or reminders in a page using php i have the main table alerts. the alerts depend in many different tables. my question is, if it is safe or is it a good method to have multiple queries for different tables on the same page for example there are about 20 reminders..

//alert 1
query 1 table alerts
if(------){ show alert 1
}
//alert 2
query 2 table alert and voc
if(------){ show alert 2
}
//alert 3
query 3 table alert and falgs
if(------){ show alert 3
}
//alert 4
query 4 table alert and casketss
if(------){ show alert 4
}

and so on....

thanks in advance for your input
stivens is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-12-2012, 05:35 PM Re: multuple queries for different tables in one page
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Is it a good idea to have multiple queries for different tables? Well, I don't know if you could do it any other way . Don't you need multiple queries to get information from multiple tables? As long as the data/structure is different, I don't see why not.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 01-12-2012, 05:36 PM Re: multuple queries for different tables in one page
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
I'd question the purposes of the page if I had 20 separate queries, or I'd question the database design - I'd expect a page to contain mainly related data and hence for some of the queries to be capable of being conflated into one query.

That said, if the db performance is satisfactory then go ahead. It is worth ensuring that every query is written for optimal performance - efficient execution and minimum necessary amount of data generated. (Though that should be true for every application.)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-13-2012, 02:13 AM Re: multuple queries for different tables in one page
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Thanks guys for your input, i am trying to have it all in one table, but i am going crazy getting the logic to work here :S :/ maybe if i can explain the situation i can get some ideas from you? i would really appreciate it... this is the scenario..

all the alerts depend when the counselor is assigned..

1 table is `exp` here the counselor is assigned there is a table for each service that is required.. for example there are about 10 to 20 services..

the first alert should show up at 4:30 pm of the day the counselor is assigned..

so this is what i do when they update the table and assign a counselor i insert the first alert into the table `alerts` here all goes well. then this is how i get the first alert to show up

PHP Code:
$sql "SELECT * FROM alert WHERE counselor = '$user' AND status = 'Active' ORDER BY date, time LIMIT 1";
$q mysql_query($sql);
$row mysql_fetch_array($q);

$alert_id $row['id'];
$dtime strtotime($row['date'] . " " $row['time']);
$status $row['status'];
$counselor $row['counselor'];
$task $row['task'];
$show $row['show'] +1;

//alert one
if($ctime $dtime && $status == "Active" && $counselor == $user){
    
    
    
$q mysql_query("update `alert` set `show` = '$show' where `id` = '$alert_id'") or die(mysql_error());
    
    echo 
"<script type='text/javascript'>window.open('alerts/alert_one.php?id=$alert_id&task=$task','user','height=660,width=680');</script>";

ok this where i am stocked the second alert needs to be 2 hours after the counselor is assigned and the field `req_voc` on table `voc` is == Yes

so what i was thinking is that everytime the save yes on `voc` table, i can add a field on alerts table and update it with the value yes.. but then again i can not update the record because is set up for the first alert i can not change the time.. :/ also i wont be able to update the table if the counselor has not been assigned yet :/ im going crazy here :/
stivens is offline
Reply With Quote
View Public Profile
 
Old 01-13-2012, 07:12 AM Re: multuple queries for different tables in one page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Why would you have a table for every service???

It sounds like a database schema "designed" by a programmer!!

You have a table for all the various services and then use "link tables" to create a relationship between the appointment time and service required.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-13-2012, 09:06 AM Re: multuple queries for different tables in one page
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
There's not enough info to accurately produce tables but I'd be looking at

counselor
service
alert
assignment with foreign key links to the three above (any or all potentially NULL)

or, if assignments can have more than one alert, add a linking table referencing just those two tables and recording response.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 01-13-2012 at 09:08 AM..
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-13-2012, 04:55 PM Re: multuple queries for different tables in one page
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
thanks for your help,

I didn't get what you mean by that.. :S
maybe it was not clear why i tried to explained?
stivens is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to multuple queries for different tables in one page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.82064 seconds with 12 queries