Jump to content


Photo

variables


  • Please log in to reply
5 replies to this topic

#1 bagnallc

bagnallc
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 27 June 2006 - 11:05 AM

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

#2 uraniumdeer

uraniumdeer
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 June 2006 - 11:16 AM

ehm... define it in the "root" of the PHP tag i suppose

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


#3 bagnallc

bagnallc
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 27 June 2006 - 11:23 AM

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

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 27 June 2006 - 11:28 AM

$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
Life's too short for arguing.

#5 uraniumdeer

uraniumdeer
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 June 2006 - 11:32 AM

Yeah... ofcourse, i was thinking it was only the querystring and not the query itself - sorry...

#6 bagnallc

bagnallc
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 27 June 2006 - 11:43 AM

i now have this working. many thanks for your help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users