wawo Posted August 23, 2007 Share Posted August 23, 2007 Designing a site with MySql and php; mainly db for navigational and reading .htm files. If I am running several queries for different parts of the site does it make sense to run all queries in 1 php file and then include that file; then display the record sets throughout the page? Example 1 file; to make this simple as possible index.php include('mysql_queries.php'); include('top.php'); include('middle.php'); Content of php pages; mysql_queries.php has db_connect and runs 3 separate queries; query1_RECSET, query2_RECSET and query3_RECSET top.php displays <?php echo $row_query1_RECSET['contentA']; ?> (results from query1) middle.php displays <?php echo $row_query2_RECSET['contentX']; ?> (results from query2) bottom.php displays <?php echo $row_query3_RECSET['contentY']; ?> (results from query3) Would this be a good design to display all results in index.php? Where would you run the following code? bottom.php for example? <?php mysql_free_result($MainNav_RECSET);(on all 3 queries) ?> I presume that if you run it at the end of each query the results would not show up? or Example B; Would you run a separate query on each page such as; top.php; query1 with results <?php echo $row_query1_RECSET['contentA']; ?> middle.php; query 2 with results <?php echo $row_query2_RECSET['contentx']; ?> bottom.php; query 3 with results <?php echo $row_query3_RECSET['contentY']; ?> What is a better design? or wrong way? I have tried both ways and not really found a difference, my thought is that perhaps keeping all queries in the same php page might be easier but not sure. One problem I have with both designs is that my $variables are sometimes empty; not sure if I need to set them up as global somehow or something. Any suggestions from a db / php designer?? ??? Thanks alot for your help; appreciate the time. Quote Link to comment https://forums.phpfreaks.com/topic/66282-database-query-question-simple-design/ Share on other sites More sharing options...
matthewhaworth Posted August 23, 2007 Share Posted August 23, 2007 No, there's no point putting the queries into another file and including it, because as far as the compiler as concerned, it's all the same file once it's included anyways. But, since we're talking about designs.. I'd look into functions if I were you.. then try this again. Quote Link to comment https://forums.phpfreaks.com/topic/66282-database-query-question-simple-design/#findComment-331538 Share on other sites More sharing options...
wawo Posted August 23, 2007 Author Share Posted August 23, 2007 Thanx! Will look into functions; To send me in the right direction; use funcion to run the query and results and then post function on page? thanks again Quote Link to comment https://forums.phpfreaks.com/topic/66282-database-query-question-simple-design/#findComment-332363 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.