>  기사  >  데이터 베이스  >  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
WBOY원래의
2016-06-01 13:07:451145검색

        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'].'
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.