Jump to content

variables


bagnallc

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.