Jump to content

Recommended Posts

In my code I have:

a query and a result, and then I grab everything I need from the database.  Later on down the page, I have to do another query, etc.

Do I need to close the database connection or anything before I start the next query?

 

in other words, can I have:

$query = "some query statement";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);
.
.
.
$query = "some other query statement'";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);

 

Can both variables be called $query, or do I need to start a new name for the next query, like $query2, $result2, $data2?

 

 

Do I need to close the database connection or anything before I start the next query?

 

No.

 

Can both variables be called $query, or do I need to start a new name for the next query, like $query2, $result2, $data2?

 

I'm almost positive you can keep the variable names the same because you're reassigning the values.  I would rename them because this could cause issues and it's better to assign descriptive names, just like any other variable, so you can refer to them later.

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.