Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-mysql获取数组(如%)_Php_Mysql - Fatal编程技术网

php-mysql获取数组(如%)

php-mysql获取数组(如%),php,mysql,Php,Mysql,我有一个php文件,可以从mysql表中获取和打印数据。 这是密码 <?php { $username = 'root'; $bookid = "GCK"; $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("library", $con); $query3 = "SELE

我有一个php文件,可以从mysql表中获取和打印数据。 这是密码

<?php
{
$username = 'root';
$bookid = "GCK";
$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("library", $con);

$query3 = "SELECT * FROM GCKcatalogue WHERE BookID LIKE'%$bookid%'";
$numresults=mysql_query($query3);
$numrows=mysql_num_rows($numresults);

$result3 = mysql_query($query3);
($info3 = mysql_fetch_array($result3));

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="en-us" http-equiv="Content-Language">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Results</title>

</head>
<body>

<table align="center" style="width: 80%" class="style4" cellpadding="1px" cellspacing="1px">
<tr>
<td class="style19">Resource ID</td><td class="style19">ISBN</td><td class="style19">Title</td><td class="style19">Author</td><td class="style19">Publisher</td><td class="style19">Year</td><td class="style19">Edition</td><td class="style19">Language</td><td class="style19">Type</td><td class="style19">Price</td><td class="style19">Location</td><td class="style19">Abstract</td><td class="style19">Availability</td><td class="style19">Last Issued</td><td class="style19">Last Received</td><td class="style19">Loan To</td>
</tr>

<?php
while($info3 = mysql_fetch_array($result3)){
$RID = $info3["BookID"];
$ISBN = $info3["ISBN"];
$Title = $info3["Title"];
$Author = $info3["Author"];
$Publisher = $info3["Publisher"];
$Year = $info3["Year"];
$Edition = $info3["Edition"];
$Language = $info3["Language"];
$Type = $info3["Type"];
$Price = $info3["Price"];
$Location = $info3["Location"];
$Abstract = $info3["Abstract"];
$Availability = $info3["Availability"];
$Issue = $info3["IssueDate"];
$Receive = $info3["ReceiveDate"];
$User = $info3["User"];


 echo '
 <tr>
 <td class="style20">' . $RID . '</td>
 <td class="style20">' . $ISBN . '</td>
 <td class="style20">' . $Title . '</td>
 <td class="style20">' . $Author . '</td>
 <td class="style20">' . $Publisher . '</td>
 <td class="style20">' . $Year . '</td>
 <td class="style20">' . $Edition . '</td>
 <td class="style20">' . $Language . '</td>
 <td class="style20">' . $Type . '</td>
 <td class="style20">' . $Price . '</td>
 <td class="style20">' . $Location . '</td>
 <td class="style20">' . $Abstract . '</td>
 <td class="style20">' . $Availability . '</td>
 <td class="style20">' . $Issue . '</td>
 <td class="style20">' . $Receive . '</td>
 <td class="style20">' . $User . '</td>
 </tr>
 ';
}

?>

</table>

</body>

</html>

问题是,, 查询正在跳过(或不提供)第一行中的数据。其他一切都很好

我正在使用

Apache/2.2.13(Win32)PHP/5.3.0


MySQL客户端版本:mysqlnd 5.0.5-dev-081106-$Revision:1.3.2.27$

这是因为行:

($info3 = mysql_fetch_array($result3));
您正在获取第一行,但没有对其执行任何操作:)

另外,围绕第一个PHP块的
{
}
没有任何作用

编辑:

如果它以前工作过,除了第一行之外,如果将第一个PHP块更改为:

<?php
$username = 'root';
$bookid = "GCK";
$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("library", $con);

$query3 = "SELECT * FROM GCKcatalogue WHERE BookID LIKE'%$bookid%'";
$numresults=mysql_query($query3);
$numrows=mysql_num_rows($numresults);

$result3 = mysql_query($query3);
?>

这是因为您正在使用此行获取第一行:

($info3=mysql\u fetch\u数组($result3))

这会将数组指针移动到第二项

此外,您不必执行两次查询来获得行数和数据。就这样做吧:

$result = MySql_Query ( 'QUERY HERE' );
$numOfRows = MySql_Num_Rows ( $result );
while ( $row = MySql_Fetch_Array ( $result ) ) {
  ...
}
我还建议您不要使用MySql扩展,请使用新的或。

还可以尝试以下操作:

$result=MySql_Query('queryhere'); $numorrows=MySql\u Num\u Rows($result); while($row=MySql\u Fetch\u数组($result)){ $arrData[]=$row; }


打印数据

如果我删除该行,我如何获取数据?您正在while循环中检索数据:
while($info3=mysql\u fetch\u array($result3)){
如果我删除该行,我如何获取数据?您已经在
while($info3=mysql\u fetch\u array($result3)){
行中获取数据了。您能为我修改脚本吗?我卡住了..:p