Help with PHP enums (not exactly enums but..)
#1

The thing is that there is this thing in pawn:
PlayerInfo[playerid][pAdmin]
or
PlayerInfo[i][pAdmin]
And I guess you got the point.
So I want to know how do I make this thing in PHP, it would be very appreciated if someone can give me the code and explain it to me, so variable values will be taken from the mySQL.. I was trying to do some array thingy for ages which didn't work, something like this:

Код:
$pData = array();
$user = $_SESSION['user'];
if($user)
{
	$withdraw = mysql_query("SELECT * FROM `users` WHERE `id`='$user'");
	if(!mysql_num_rows($withdraw)) continue;
	while($acc = mysql_fetch_assoc($withdraw))
	{
		$pData[$user] = array(
		"Username" => $acc['username'],
		"Admin" => $acc['alevel'],
		"Cellphone" => $acc['phone'],
		"Tester" => $acc['tester'],
		"Money" => $acc['cash'],
		"Job" => $acc['job'],
		"JobRank" => $acc['jobrank'],
		"Faction" => $acc['faction'],
		"Job" => $acc['job'],
		"Rank" => $acc['rank'],
		"Paycheck" => $acc['paycheck'],
		"Job" => $acc['job'],
		"Accepted" => $acc['accepted'],
		"Level" => $acc['level'],
		"Experience" => $acc['exp']
		);
	}
}
So I'd appreciate if someone can show me how to do the thing I said above, thanks!
Reply
#2

Maybe you mean something like this

PHP код:
$pData = array();
$user $_SESSION['user'];
if(
$user)
{
    
$result mysql_query("SELECT * FROM `users` WHERE `id`='"$user ."'");
    if(
mysql_num_rows ($result) > 0)
    {
        while(
$row mysql_fetch_array($result))
        {
            
$pData[$user] = array(
            
"Username" => $row['username'],
            
"Admin" => $row['alevel'],
            
"Cellphone" => $row['phone'],
            
"Tester" => $row['tester'],
            
"Money" => $row['cash'],
            
"Job" => $row['job'],
            
"JobRank" => $row['jobrank'],
            
"Faction" => $row['faction'],
            
"Job" => $row['job'],
            
"Rank" => $row['rank'],
            
"Paycheck" => $row['paycheck'],
            
"Job" => $row['job'],
            
"Accepted" => $row['accepted'],
            
"Level" => $row['level'],
            
"Experience" => $row['exp']
            );
        }
    }

Reply
#3

Doesn't work. I've put it in the config.php file and tried to use it in another one..
Reply
#4

Are you sure all field names and the $user is correct?
Reply
#5

Yes.
Reply
#6

put some echos in it like
echo '1';
echo '2';

so you can debug it and see where it goes wrong.
Reply
#7

It doesn't show this echo:
Код:
 if(mysql_num_rows ($result) > 0) 
    { 
		echo "echo1";
Reply
#8

The whole point of using fetch_assoc is to not use that kind of stuff. Just assign the result to whatever array you need. Then simply access the index you need by the same name that you use for the field in MySQL.
http://be1.php.net/manual/en/functio...etch-assoc.php
Reply
#9

Quote:
Originally Posted by Vince
Посмотреть сообщение
The whole point of using fetch_assoc is to not use that kind of stuff. Just assign the result to whatever array you need. Then simply access the index you need by the same name that you use for the field in MySQL.
http://be1.php.net/manual/en/functio...etch-assoc.php
Totaly true, I know there was a function for that, but I just didn't know it was called like that lol.
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
The whole point of using fetch_assoc is to not use that kind of stuff. Just assign the result to whatever array you need. Then simply access the index you need by the same name that you use for the field in MySQL.
http://be1.php.net/manual/en/functio...etch-assoc.php
Yeah, but I rather do it to make it easier for me to use the array for things in the script such as showing profile details and stuff.. how can I do it?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)