phpknight Posted September 29, 2009 Share Posted September 29, 2009 I am running into a weird issue. Normally, if you store the result from a query in a variable you can go through it with mysql_fetch_array. I am attempting to store the result in a session variable, but when I try to run through it using ajax and mysql_fetch_array, it just does not work as expected. Should you be able to use mysql_fetch_array with database results with persistent results in a session variable? I am not sure if I am doing something wrong or just need to make the application a different way. Quote Link to comment https://forums.phpfreaks.com/topic/175965-using-mysql_fetch_array-and-sessions/ Share on other sites More sharing options...
cags Posted September 29, 2009 Share Posted September 29, 2009 I'm not sure what your asking here?! Does your code look like one of these? <?php $sql = "Some Query"; $result = mysql_query($sql); // this $session['result'] = $result; // or this $session['result'] = mysql_fetch_array($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/175965-using-mysql_fetch_array-and-sessions/#findComment-927207 Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 The problem with this is that once the script stops executing the mysql connection is closed and those mysql resources will no longer be valid. Explain your situation better and we can help you find an alternative. Quote Link to comment https://forums.phpfreaks.com/topic/175965-using-mysql_fetch_array-and-sessions/#findComment-927217 Share on other sites More sharing options...
phpknight Posted September 29, 2009 Author Share Posted September 29, 2009 I just figured that out myself. I guess I posted here because I was thinking it had something to do with variable types. So, I guess the other way would be to get the results once, copy them to an array row by row, and then store the array to a session variable? Alternately, I could query just one row each time. Any better ideas? Quote Link to comment https://forums.phpfreaks.com/topic/175965-using-mysql_fetch_array-and-sessions/#findComment-927229 Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 I don't know your specific situation so it's hard to give you advice. You could be going in a completely wrong way and I wouldn't know because I don't know what you're trying to accomplish. From the given information it seems like you'd be best off doing something like: session_start(); //Query stuff $_SESSION['result'] = Array(); while($row = mysql_fetch_assoc($result)) $_SESSION['result'][] = $row; Quote Link to comment https://forums.phpfreaks.com/topic/175965-using-mysql_fetch_array-and-sessions/#findComment-927231 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.