php示例代码之使用list函数和mysql_fetch_row函数

时间:2022-09-25 16:21:24
12345678910111213141516171819202122232425262728293031323334353637383940 <?php  //连接参数  $host="localhost";  $user="root";  $pwd="111111";  $db="test";     $linkID =mysql_connect($host,$user,$pwd); //创建一个mysql连接     if(!$linkID){    echo "<font color='red'>unable to connect!</font>";  }     mysql_select_db($db)or die("unable to select database"); //选择一个数据库     $SQL_SELECT_SYMBOLS="select * from symbols";     $result=mysql_query($SQL_SELECT_SYMBOLS)or die("error in query :$query. ".mysql_errno()); //执行SQL语句     if(mysql_num_rows($result)>0){    echo '<table cellpadding="10" border="1">';    echo '<tr><th>id</th><th>country</th><th>animal</th><th>cname</th></tr>';     while(list($id,$country,$animal,$cname)=mysql_fetch_row($result)){        echo "<tr>";        echo "<td>".$id."</td>";        echo "<td>".$country."</td>";        echo "<td>".$animal."</td>";        echo "<td>".$cname."</td>";        echo "</tr>";     }     echo "</table>";  }  else{    echo "记录未找到!";  }     mysql_free_result($result); //释放记录集所占用的内存     mysql_close($linkID); //关闭数据库连接?>

 php示例代码之使用list函数和mysql_fetch_row函数