Page 1 of 1

reusing query from mySQL with php

Posted: Thu Jul 01, 2004 2:54 pm
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?

Posted: Thu Jul 01, 2004 3:19 pm
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"

Posted: Thu Jul 01, 2004 3:31 pm
by udwo
so this way the query will only un once per session?

Posted: Thu Jul 01, 2004 3:40 pm
by feyd
no, it'd occur on every page with that.. you can, however cache the data inside your sessions if you'd like..

Posted: Thu Jul 01, 2004 4:25 pm
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?

Posted: Thu Jul 01, 2004 5:07 pm
by feyd
basically, yes.

Posted: Thu Jul 01, 2004 8:23 pm
by udwo
thanx for your help, i will try it.