chiprivers Posted November 25, 2006 Share Posted November 25, 2006 i created a function that queried database for records and then returned results but it is not working!function returnResult() {// build query$query = "blah blah";// run query$result = mysql_query($query);// return resultreturn $result;}Then when I try and use the results like this:while($row = mysql_fetch_array($result)) { // do this}it does not work!! is there a rule relating to functions that stops them from returning such information? Quote Link to comment https://forums.phpfreaks.com/topic/28464-problem-with-function/ Share on other sites More sharing options...
fert Posted November 25, 2006 Share Posted November 25, 2006 are you sure it's doing the query? Quote Link to comment https://forums.phpfreaks.com/topic/28464-problem-with-function/#findComment-130254 Share on other sites More sharing options...
chiprivers Posted November 25, 2006 Author Share Posted November 25, 2006 well if I put thewhile($row = mysql_fetch_array($result)) { // do this}bit inside the function instead of returning the results of the query, it works, so the query must be working.Is there any rule about retuning an array? Quote Link to comment https://forums.phpfreaks.com/topic/28464-problem-with-function/#findComment-130257 Share on other sites More sharing options...
fert Posted November 25, 2006 Share Posted November 25, 2006 your function doesn't return an array, it returns a resource, but PHP can return any type of varible Quote Link to comment https://forums.phpfreaks.com/topic/28464-problem-with-function/#findComment-130266 Share on other sites More sharing options...
chiprivers Posted November 26, 2006 Author Share Posted November 26, 2006 I am sure there is nothing wrong with my code, has anybody experienced simillar problem? Quote Link to comment https://forums.phpfreaks.com/topic/28464-problem-with-function/#findComment-130406 Share on other sites More sharing options...
.josh Posted November 26, 2006 Share Posted November 26, 2006 ..and you are calling your function by doing:[code=php:0]$result = returnResult(); // this right here?while($row = mysql_fetch_array($result)) { // do this}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28464-problem-with-function/#findComment-130407 Share on other sites More sharing options...
chiprivers Posted November 26, 2006 Author Share Posted November 26, 2006 I knew it would be something simple! Not doing much work with my own functions I didn't realise that you had to do:$result = returnResult();I was just doing:returnResult;I have amended script and it is working fine now. Many thanks CV Quote Link to comment https://forums.phpfreaks.com/topic/28464-problem-with-function/#findComment-130409 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.