Jump to content

Recommended Posts

Hi

hopefully this is an easy answer

i have the following variable

$trainerqry6=mysql_query("SELECT DISTINCT trainers.trainer_id as trainerid, trainers.trainer AS trainer
FROM trainers");

it works fine - but i want to use the same query several times in different places on the page. how do i make the variable accessible more than once

Thank you and apologies for the stupid question
Link to comment
https://forums.phpfreaks.com/topic/13010-variables/
Share on other sites

$trainerqry6 is a resultset, correct me if i'm wrong.

so, it's resultset.

If you like to use it inside a function, you'll need to global it inside that function.

Resultset is special. When you fetch result, the internal pointer of result set point to the next row. So, after a while, eventually, fetch will return null to indicate the end of result.
If you need to re-use the results, you have to mysql_data_seek.
This function move the internal pointer to the location you wanted.
mysql_data_seek($trainerqry6, 0); will reset the resultset
Link to comment
https://forums.phpfreaks.com/topic/13010-variables/#findComment-50039
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.