Page 1 of 1

problem with fetching data from mysql using two file

Posted: Sat May 14, 2011 1:08 am
by bluestar
i am trying to fetch some information from database and show it in some other page , i know scope of a variable limited within function if its not global and superglobal....but how to pass the info outside .... here is my code..the function showingdata is in xyz class...similarly dblink(database connection and selection here) and realescapestring


function showingdta($cuid) /*user info*/
{
$table2="member_info";
if($this->dblink()==TRUE)
{
$query='SELECT * FROM '. $table2 .' WHERE EMAIL= "'.$this->realescapestring($cuid).'"';
$result=mysql_query($query,$this->conn_link) or die("prob");
$info=mysql_fetch_array($result);

if (mysql_error())
{ print "Database ERROR: " . mysql_error(); }

header("Content-type: $info");
echo $info;

}
else
{return FALSE;}
}



in show.php file

<?php
session_start();
include_once("info.php");
$biglife= new xyz;
$cuid=100011;
$biglife->showingdta($cuid);
echo "<table>";
echo "<tr>";
echo "<td>Name:</td>";
echo "<td> " . $info['FIRST_NAME']. " </td>";
echo "</tr>";
echo "</table>";
?>

Re: problem with fetching data from mysql using two file

Posted: Sun May 15, 2011 1:57 pm
by getmizanur
is this what you are looking for (look for upper case CHANGED comments)

Code: Select all

function showingdta($cuid) /*user info*/
{
$table2="member_info";
if($this->dblink()==TRUE)
{
$query='SELECT * FROM '. $table2 .' WHERE EMAIL= "'.$this->realescapestring($cuid).'"';
$result=mysql_query($query,$this->conn_link) or die("prob");
$info=mysql_fetch_array($result);

if (mysql_error())
{ print "Database ERROR: " . mysql_error(); }

return $info; //CHANGED

}
else
{return FALSE;}
}

in show.php file

<?php
session_start();
include_once("info.php");
$biglife= new xyz;
$cuid=100011;
if($info = mysql_fetch_assoc($biglife->showingdta($cuid))) { // CHANGED
echo "<table>";
echo "<tr>";
echo "<td>Name:</td>";
echo "<td> " . $info['FIRST_NAME']. " </td>";
echo "</tr>";
echo "</table>";
} // CHANGED