bagnallc Posted June 27, 2006 Share Posted June 27, 2006 Hi hopefully this is an easy answeri 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 onceThank you and apologies for the stupid question Quote Link to comment https://forums.phpfreaks.com/topic/13010-variables/ Share on other sites More sharing options...
uraniumdeer Posted June 27, 2006 Share Posted June 27, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/13010-variables/#findComment-50034 Share on other sites More sharing options...
bagnallc Posted June 27, 2006 Author Share Posted June 27, 2006 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 codeit works fine when called once but the second time it returns nothingthanks again Quote Link to comment https://forums.phpfreaks.com/topic/13010-variables/#findComment-50037 Share on other sites More sharing options...
hvle Posted June 27, 2006 Share Posted June 27, 2006 $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 Quote Link to comment https://forums.phpfreaks.com/topic/13010-variables/#findComment-50039 Share on other sites More sharing options...
uraniumdeer Posted June 27, 2006 Share Posted June 27, 2006 Yeah... ofcourse, i was thinking it was only the querystring and not the query itself - sorry... Quote Link to comment https://forums.phpfreaks.com/topic/13010-variables/#findComment-50040 Share on other sites More sharing options...
bagnallc Posted June 27, 2006 Author Share Posted June 27, 2006 i now have this working. many thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/13010-variables/#findComment-50044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.