Jump to content

[SOLVED] return db results


adam291086

Recommended Posts

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???

Link to comment
https://forums.phpfreaks.com/topic/145977-solved-return-db-results/
Share on other sites

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;
}

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

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??

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.

it gave

 

Array

(

    [0] => Array

        (

            [0] => 1

            [EnterID] => 1

            [1] => 1

            [ComputerID] => 1

            [2] => [email protected]

            [From] => [email protected]

            [3] => [email protected]

            [To] => [email protected]

            [4] => 1235399556

            [startTime] => 1235399556

            [5] => 1235043709

            [EndTime] => 1235043709

            [6] => You smell

            [Convosation] => You smell

        )

 

)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.