adam291086 Posted February 19, 2009 Share Posted February 19, 2009 I have this function function GetIMfromDatabase($StartTimeStamp,$EndTimeStamp){ $sql=mysql_query("SELECT * FROM msnconvosations WHERE `StartTime` BETWEEN '".addslashes($StartTimeStamp)."' AND '".addslashes($EndTimeStamp)."'"); while ($text=mysql_fetch_array($sql)){ return $text; } } and i am calling it like $info = GetIMfromDatabase($StartTimestamp,$EndTimestamp); Now it should return two sets of information but its only return one set. Why??? Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/ Share on other sites More sharing options...
Philip Posted February 19, 2009 Share Posted February 19, 2009 Because return will break outta that loop and return that value. You need to do something like: function GetIMfromDatabase($StartTimeStamp,$EndTimeStamp){ $sql=mysql_query("SELECT * FROM msnconvosations WHERE `StartTime` BETWEEN '".addslashes($StartTimeStamp)."' AND '".addslashes($EndTimeStamp)."'"); while ($text=mysql_fetch_array($sql)){ $array[] = $text; } return $array; } Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766371 Share on other sites More sharing options...
adam291086 Posted February 19, 2009 Author Share Posted February 19, 2009 cool, that generate an array Array ( [0] => Array ( [0] => 2 [EnterID] => 2 [1] => 1 [ComputerID] => 1 [2] => sfdsfsd [From] => sfdsfsd [3] => sdfdsfds [To] => sdfdsfds [4] => 1235063869 [startTime] => 1235063869 [5] => 1235063869 [EndTime] => 1235063869 [6] => fgfgfdgdfgdf [Convosation] => fgfgfdgdfgdf ) [1] => Array ( [0] => 3 [EnterID] => 3 [1] => 1 [ComputerID] => 1 [2] => sdfsdfsdf [From] => sdfsdfsdf [3] => sdfsdfsdfd [To] => sdfsdfsdfd [4] => 1235063869 [startTime] => 1235063869 [5] => 1235063869 [EndTime] => 1235063869 [6] => eferertretet [Convosation] => eferertretet ) ) how will i get it all seperated out i.e computerID From To StartTime EndTime Convosation Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766377 Share on other sites More sharing options...
adam291086 Posted February 19, 2009 Author Share Posted February 19, 2009 i am trying this $count = count($info); if(isset($info)) { for ($i=1; $i<=$count; $i++) { echo "Information for the Date" .$d."/".$m."/".$y; echo "<br />"; echo $info[$i]['ComputerID']; echo "<br />"; echo $info[$i]['From']; echo "<br />"; echo $info[$i]['To']; echo "<br />"; echo date("F j, Y, g:i a",$info[$i]['StartTime']); echo "<br />"; echo date("F j, Y, g:i a",$info[$i]['EndTime']); echo "<br />"; echo $info[$i]['Convosation']; } } but getting nothing anyone?? Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766458 Share on other sites More sharing options...
Philip Posted February 19, 2009 Share Posted February 19, 2009 cool, that generate an array Array ( [0] => Array ( [0] => 2 [EnterID] => 2 [1] => 1 [ComputerID] => 1 [2] => sfdsfsd [From] => sfdsfsd [3] => sdfdsfds [To] => sdfdsfds [4] => 1235063869 [startTime] => 1235063869 [5] => 1235063869 [EndTime] => 1235063869 [6] => fgfgfdgdfgdf [Convosation] => fgfgfdgdfgdf ) [1] => Array ( [0] => 3 [EnterID] => 3 [1] => 1 [ComputerID] => 1 [2] => sdfsdfsdf [From] => sdfsdfsdf [3] => sdfsdfsdfd [To] => sdfsdfsdfd [4] => 1235063869 [startTime] => 1235063869 [5] => 1235063869 [EndTime] => 1235063869 [6] => eferertretet [Convosation] => eferertretet ) ) thats a bit hard to read, so do this: echo '<pre>'; print_r($info); echo '</pre>'; It'll make it easier to read. What you're currently doing should work, but let's see if there is something else. Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766462 Share on other sites More sharing options...
adam291086 Posted February 19, 2009 Author Share Posted February 19, 2009 it gave Array ( [0] => Array ( [0] => 1 [EnterID] => 1 [1] => 1 [ComputerID] => 1 [2] => ad_plowman@hotmail.com [From] => ad_plowman@hotmail.com [3] => dingus_76@hotmail.com [To] => dingus_76@hotmail.com [4] => 1235399556 [startTime] => 1235399556 [5] => 1235043709 [EndTime] => 1235043709 [6] => You smell [Convosation] => You smell ) ) Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766465 Share on other sites More sharing options...
Philip Posted February 19, 2009 Share Posted February 19, 2009 What does echo $info[0]['ComputerID']; show? I think its because your loop starts @ 1, but the array indexes starts @ 0. Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766466 Share on other sites More sharing options...
adam291086 Posted February 19, 2009 Author Share Posted February 19, 2009 it prints "1" Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766469 Share on other sites More sharing options...
adam291086 Posted February 19, 2009 Author Share Posted February 19, 2009 it was because i was starting at 1 not 0 Quote Link to comment https://forums.phpfreaks.com/topic/145977-solved-return-db-results/#findComment-766470 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.