Jump to content

Database query question; simple design;


wawo

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.