从数据库中检索一条记录

时间:2014-03-19 06:12:40

标签: php arrays error-handling record fetch

只是尝试从数据库中显示一条记录......但是收到错误(在获取数组时)

$con=mysql_connect("localhost","root","");
mysql_select_db("school");
$iid=$_REQUEST['id2'];   //mysql_fetch_array(): supplied argument is not a valid

$d=mysql_query("select * from notification where noticeid=$iid");
$data=mysql_fetch_array( $d ); 

这是我的显示标准......

<tr> 
<td class=""><?php echo $data['noticeid'] ?></td>  
<td class=""><?php echo $data['notificationtitle'] ?></td>  
<td class=""><?php echo $data['notificationbody'] ?></td>  
</tr>

2 个答案:

答案 0 :(得分:0)

试试这个:noticeid ='“。$ iid。” “

$d=mysql_query("select * from notification where noticeid='".$iid."' ");
$data=mysql_fetch_array( $d ); 

答案 1 :(得分:0)

您可能想引用变量:

  1. 如果noticeid是一个字符串:
    $d=mysql_query("select * from notification where noticeid='".$iid."'");

  2. 如果noticeid是一个数字:
    $d=mysql_query("select * from notification where noticeid=".$iid);