Problems with mysql query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
like_duh44
Forum Commoner
Posts: 63
Joined: Sat Jul 26, 2003 6:57 pm

Problems with mysql query

Post by like_duh44 »

I have a simple script to get a row in a mysql database and put it into an array like this:

Code: Select all

<?php

$sql = 'SELECT `username`, `posts`, `theme` FROM `'.$prefix.'chat_prefs` WHERE `username` = '''.$_GET[userinfoname].''' LIMIT 1';

$result = mysql_query($sql) or die("Query 1 Failed ". mysql_error());

$userinfo[] = mysql_fetch_array($result);

mysql_free_result($result);

?>
But it gives me this error: [] Operator not supported blablabla. I had it echo $sql and I did the query via phpMyAdmin and it got the whole table fine. But if I tried to do mysql_result() i would get the first cell in the row. Any ideas?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

do you really need $userinfo to be an array of arrays?

Code: Select all

<?php

$sql = 'SELECT `username`, `posts`, `theme` FROM `'.$prefix.'chat_prefs` WHERE `username` = '''.$_GET[userinfoname].''' LIMIT 1';
$result = mysql_query($sql) or die("Query 1 Failed ". mysql_error());

$userinfo = array();
$userinfo = mysql_fetch_array($result);
print_r($userinfo);

mysql_free_result($result);

?>
does this work?
Post Reply