Page 1 of 1

problem with mysql_fetch_array

Posted: Thu Aug 17, 2006 1:10 pm
by danharibo
When i do this:

Code: Select all

$titleq = "SELECT name FROM ".TBL_GAMES.";";
$title = mysql_query($titleq);
$games = mysql_fetch_array($title, MYSQL_ASSOC);
echo "<td>.{$games['name']}.";
I get this:

Notice: Undefined index: name in c:\program files\easyphp1-8\www\cms\games.php on line 39
But The desctipt Value of my array works fine :?

Posted: Thu Aug 17, 2006 1:20 pm
by feyd
Add some error checking..

Code: Select all

mysql_query(...) or die(mysql_error());
Consider looking at what $games is: var_dump($games);

Posted: Thu Aug 17, 2006 1:32 pm
by danharibo
Ahha, it seems Name isnt being added to the array :/

Posted: Thu Aug 17, 2006 1:44 pm
by volka
Maybe it's no array at all.

Code: Select all

$titleq = 'SELECT name FROM '.TBL_GAMES;
$title = mysql_query($titleq) or die(mysql_error());

if ( $games = mysql_fetch_array($title, MYSQL_ASSOC) ) {
	echo '<td>', $games['name'], '</td>';
}
else {
	echo '<td>---</td>';
}

Posted: Thu Aug 17, 2006 2:01 pm
by danharibo
there is an array, Description is added fine
http://danharibo.dyndns.org/cms/games.php See, the description bit loads

Posted: Thu Aug 17, 2006 3:47 pm
by danharibo
i fixed it :D, but now i need to get all of the collum? how do i so that with Aquery?

Posted: Thu Aug 17, 2006 3:58 pm
by feyd
while loop + mysql_fetch_assoc() + $foo[] = $row['var']

Posted: Thu Aug 17, 2006 4:35 pm
by danharibo
according to php.net mysql_fetch_assoc() is only availaable for php5

Posted: Thu Aug 17, 2006 4:48 pm
by s.dot
Not true.
PHP.net wrote:mysql_fetch_assoc
(PHP 4 >= 4.0.3, PHP 5)
Will work with PHP 4.

Or if you don't have PHP 4, you could do this on PHP 3 with mysql_fetch_array($result, MYSQL_ASSOC)

an example of getting all values of a column into an array.

Code: Select all

$my_array = array();

$result = mysql_query($sql) or die(mysql_error());

while($array = mysql_fetch_assoc($result))
{
   $my_array[] = $array['column_name'];
}

echo '<pre>';
print_r($my_array);
echo '</pre>';