Jump to content

Archived

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

bagnallc

variables

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

Share this post


Link to post
Share on other sites
ehm... define it in the "root" of the PHP tag i suppose

[code]
<?php
$trainerqry6=mysql_query("SELECT DISTINCT trainers.trainer_id as trainerid, trainers.trainer AS trainer
FROM trainers");
...
...
...
?>
[/code]

Share this post


Link to post
Share on other sites
im sorry i dont know what you mean by this.

it is currently defined at the top of the page in the first block of php code

it works fine when called once but the second time it returns nothing

thanks again

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.