Heim  >  Artikel  >  Datenbank  >  How to fetch data from mysql table using mysql_fetch_assoc i_MySQL

How to fetch data from mysql table using mysql_fetch_assoc i_MySQL

WBOY
WBOYOriginal
2016-06-01 13:07:451148Durchsuche

        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'

';

         }

        echo'

Game_ID Category Title
'.$res['game_ID'].' '.$res['category_Name'].' '.$res['game_Title'].'
';

 ?>

 

           Now you'll get output like this:

mysql_fetch_assoc in php

Where,

            the result of array should be like this:

      Array(

                  [game_ID] => 1

                  [category_Name] => Adventures

                  [game_Title] => Achilles

               )

Suppose you'll use

echo'

';


That means you use numeric index instead associative, then you will get undefined offset error like as follows as:

mysql_fetch_assoc at phponwebsites

'.$res[0].' '.$res['category_Name'].' '.$res['game_Title'].'
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn