reusing query from mySQL with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
udwo
Forum Newbie
Posts: 7
Joined: Thu Jul 01, 2004 2:54 pm

reusing query from mySQL with php

Post by udwo »

I am new to php+mySQL. worked mostly with asp before. i have a query that the results will have to show basically on every page of the site i am building. is there a way to do it globaly (like global.asa)? what would be the best approach?
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

something i tend to do is have a config.php file, where all of my global vairables (like user names for mysql and such) are kept. If you do that, you could have a variable defined as like

Code: Select all

<?php
$QUERY = "SELECT * FROM Table";
?>
And then use the include() or require() functions to be able to use those variables


OR you could use session, and have like $_SESSION['query'] = "SELECT * FROM Table"
udwo
Forum Newbie
Posts: 7
Joined: Thu Jul 01, 2004 2:54 pm

Post by udwo »

so this way the query will only un once per session?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no, it'd occur on every page with that.. you can, however cache the data inside your sessions if you'd like..
udwo
Forum Newbie
Posts: 7
Joined: Thu Jul 01, 2004 2:54 pm

Post by udwo »

so would i just create a session variable to check if the query has an data stored in its variables and if yes post it and if not i would run the query?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

basically, yes.
udwo
Forum Newbie
Posts: 7
Joined: Thu Jul 01, 2004 2:54 pm

Post by udwo »

thanx for your help, i will try it.
Post Reply