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'];
}
accessing database throuth Array
Moderator: General Moderators
Re: accessing database throuth Array
I dont know but I shouldn't it be that your $i is inside your While loop? cause from what i see it doesn't increment.. orr was that just a typo? cause of the brackets of while loop
Re: accessing database throuth Array
actually i have fixed that at last. That wasn't a typo as i was declaring a two dimentional array. I required to assign the $i value to be incremented. THe problem was in my GUI class where i was making a for loop and was calling the array but was providing the wrong name of the reference array. Answer should be as below.
for ($i = 0; $i<sizeof($User); $i++)
{
echo $User[$i]['Files'];
}
instead it should have been
for ($i = 0; $i<sizeof($User); $i++)
{
echo $User[$i]['firstname'];
echo $User[$i]["surname1"];
}
Hope this make sence..
thanks..
for ($i = 0; $i<sizeof($User); $i++)
{
echo $User[$i]['Files'];
}
instead it should have been
for ($i = 0; $i<sizeof($User); $i++)
{
echo $User[$i]['firstname'];
echo $User[$i]["surname1"];
}
Hope this make sence..
thanks..