accessing database throuth Array
Posted: Mon Aug 04, 2008 11:28 am
Hi, I have a class for mysql query. It has three funcitons one of them make a query to the table for login detail with the session id and retrieve the data and insert into an array. Then check the condition whether certain codition are true after that it echo the result. But i have separted the files into two layers one for database query and one for GUI (echo). But i can't manage to retrieve the data of the array from different class. Please find my classes given below. I can't find why it's not working. Can anyone please tell me where i am going wrong.
Class Sqlclass{
function Sql_login($UserId,$arr)
{
$vUserId = $UserId;
mysql_select_db('login_db');
$sql = "SELECT first_name, last_name FROM user_acc_tb WHERE sGUID='$UserId'";
$result =mysql_query($sql) or die('Error, query failed');
$arr = array(); // defining new array.
$i = 0;
while(list($firstname1,$lastname1) = mysql_fetch_array($result))
{
//$firstname=$firstname1;
//$lastname=$lastname1;
$arr[$i]["firstname"] = $firstname1;
$arr[$i]["surname1"] = $surname1;
echo $arr[$i];
//echo "($firstname1, $surname1, $upload)";
}
$i++;
} // while
return $arr;
mysql_close();
}
}
this is the GUI php file that i am using to retrive the data.
<?php
session_start();
error_reporting(0);
include 'db_con.php'; // including database connection files
include 'Sqldatabase.php';
/*******************************login related code***********************************************/
mysql_select_db('login_db');
$UserId = $HTTP_COOKIE_VARS['session_id']; // session cookies
// here the code checking
$Vlogin = new Sqldatabase;
$Vlogin->Sql_login($UserId);
$User = $Vlogin->Sql_login();
for ($i = 0; $i<sizeof($User); $i++)
{
echo $User[$i]['Files'];
}
Class Sqlclass{
function Sql_login($UserId,$arr)
{
$vUserId = $UserId;
mysql_select_db('login_db');
$sql = "SELECT first_name, last_name FROM user_acc_tb WHERE sGUID='$UserId'";
$result =mysql_query($sql) or die('Error, query failed');
$arr = array(); // defining new array.
$i = 0;
while(list($firstname1,$lastname1) = mysql_fetch_array($result))
{
//$firstname=$firstname1;
//$lastname=$lastname1;
$arr[$i]["firstname"] = $firstname1;
$arr[$i]["surname1"] = $surname1;
echo $arr[$i];
//echo "($firstname1, $surname1, $upload)";
}
$i++;
} // while
return $arr;
mysql_close();
}
}
this is the GUI php file that i am using to retrive the data.
<?php
session_start();
error_reporting(0);
include 'db_con.php'; // including database connection files
include 'Sqldatabase.php';
/*******************************login related code***********************************************/
mysql_select_db('login_db');
$UserId = $HTTP_COOKIE_VARS['session_id']; // session cookies
// here the code checking
$Vlogin = new Sqldatabase;
$Vlogin->Sql_login($UserId);
$User = $Vlogin->Sql_login();
for ($i = 0; $i<sizeof($User); $i++)
{
echo $User[$i]['Files'];
}