当前位置:Gxlcms >
mysql >
Howtofetchdatafrommysqltableusingmysql_fetch_associ_MySQL
Howtofetchdatafrommysqltableusingmysql_fetch_associ_MySQL
时间:2021-07-01 10:21:17
帮助过:13人阅读
Game_ID | Category | Title | php mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('new') or die(mysql_error());
$query=mysql_query('select * from table1') or die(mysql_error());
while($res=mysql_fetch_assoc($query))
{
echo'
'.$res['game_ID'].' | '.$res['category_Name'].' | '.$res['game_Title'].' |
'; }
echo'
'; ?>
Now you'll get output like this:
Where,
the result of array should be like this:
Array(
[game_ID] => 1
[category_Name] => Adventures
[game_Title] => Achilles
)
Suppose you'll use
echo''.$res[0].' | '.$res['category_Name'].' | '.$res['game_Title'].' |
';
That means you use numeric index instead associative, then you will get undefined offset error like as follows as:
人气教程排行