problem with fetching data from mysql using two file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bluestar
Forum Newbie
Posts: 13
Joined: Thu Mar 17, 2011 7:19 am

problem with fetching data from mysql using two file

Post 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>";
?>
User avatar
getmizanur
Forum Commoner
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: problem with fetching data from mysql using two file

Post 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
Post Reply