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
danharibo
Forum Commoner
Posts: 76 Joined: Thu Aug 17, 2006 8:56 am
Post
by danharibo » Thu Aug 17, 2006 1:10 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 17, 2006 1:20 pm
Add some error checking..
Code: Select all
mysql_query(...) or die(mysql_error());Consider looking at what $games is:
var_dump($games) ;
danharibo
Forum Commoner
Posts: 76 Joined: Thu Aug 17, 2006 8:56 am
Post
by danharibo » Thu Aug 17, 2006 1:32 pm
Ahha, it seems Name isnt being added to the array :/
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Aug 17, 2006 1:44 pm
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>';
}
danharibo
Forum Commoner
Posts: 76 Joined: Thu Aug 17, 2006 8:56 am
Post
by danharibo » Thu Aug 17, 2006 3:47 pm
i fixed it
, but now i need to get all of the collum? how do i so that with Aquery?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 17, 2006 3:58 pm
while loop + mysql_fetch_assoc() + $foo[] = $row['var']
danharibo
Forum Commoner
Posts: 76 Joined: Thu Aug 17, 2006 8:56 am
Post
by danharibo » Thu Aug 17, 2006 4:35 pm
according to php.net mysql_fetch_assoc() is only availaable for php5
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Aug 17, 2006 4:48 pm
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>';
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.