SQL语法错误[检查手册对应MySQL服务器]

时间:2015-08-19 03:26:04

标签: php html sql

  

您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在'附近使用。 product_code,product_name,product_desc,price FROM products'在第1行



<?php

include('include/conn.php');

$per_page = 5;
$adjacents = 5; 

$pages_query = mysql_query("SELECT COUNT(id), , product_code, product_name, product_desc, price FROM products") or die(mysql_error());

//get total number of pages to be shown from  total result
$pages = ceil(mysql_result($pages_query, 0) / $per_page);

//get current page from URL ,if not present set it to 1
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1 ;

//calcuproduct_namee actual start page with respect to Mysql 
$start = ($page - 1) * $per_page;

//execute a mysql query to retrieve  all result from current page by using LIMIT keyword in mysql
//if  query  fails stop further execution and show mysql error

$query = mysql_query("SELECT id, name, product_code, product_name, product_desc, price FROM products LIMIT $start, $per_page") or die(mysql_error());

$pagination="Pagination";
//if current page is first show first only else reduce 1 by current page
$Prev_Page = ($page==1)?1:$page - 1;

//if current page is last show last  only else add  1 to  current page
$Next_Page = ($page>=$pages)?$page:$page + 1; 

//if we are not on first page show first link
if($page!=1) $pagination.= '<a href="?page=1">First</a>';
//if we are not on first page show previous link
if($page!=1) $pagination.='<a href="?page='.$Prev_Page.'">Previous</a>';

//we are going to display 5 links on pagination bar
$numberoflinks=5;

//find the number of links to show on right of current page
$upage=ceil(($page)/$numberoflinks)*$numberoflinks;
//find the number of links to show on left of current page
$lpage=floor(($page)/$numberoflinks)*$numberoflinks;
//if  number of links on left of current page are zero we start from 1
$lpage=($lpage==0)?1:$lpage;
//find the number of links to show on right of current page and make sure it must be less than total number of pages
$upage=($lpage==$upage)?$upage+$numberoflinks:$upage;
if($upage>$pages)$upage=($pages-1);
//start building links from left to right of current page
for($x=$lpage; $x<=$upage; $x++){
//if current building link is current page we don't show link,we show as text else we show as linkn 
$pagination.=($x == $page) ? ' <strong>'.$x.'</strong>' : ' <a href="?page='.$x.'">'.$x.'</a>' ;
}
//we show next link and last link if user doesn't on last page
if($page!=$pages) $pagination.=  '  <a href="?page='.$Next_Page.'">Next</a>';
if($page!=$pages) $pagination.=  ' <a href="?page='.$pages.'">Last</a>';


?>

<!DOCprice html>
<html lang="en">

<head>
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>How To Display Data From Database Using Bootstrap Responsive Table With Pagination
</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

<div class="container-fluid">
 <h3>Display Location product_code</h3>
 <div class="table-responsive">
   <table class="table">
     <tr>
      <th>Location</th>
      <th>product_code</th>
      <th>product_nameitude</th>
      <th>Longtitude</th>
      <th>price</th>
     </tr>
     <?php  
    while($row = mysql_fetch_array($query))
    {  
    $f1 = $row['name'];           
    $f2 = $row['product_code'];
    $f3 = $row['product_name'];
    $f4 = $row['product_desc'];
    $f5 = $row['price'];
  ?>
   <tr>
    <td><?php echo $f1 ?></td>
    <td><?php echo $f2 ?></td>
    <td><?php echo $f3 ?></td>
    <td><?php echo $f4 ?></td>
    <td><?php echo $f5 ?></td>
	<?php
	echo"<td> <a href ='view.php?BookID=$f1'>Edit</a>";
	echo"<td> <a href ='del.php?BookID=$f1'><center>Delete</center></a>";
	?>
   </tr>
  <?php
    } //while
  ?>
   </table>
 </div>
 <nav>
   <ul class="pager">
     <li><a href="#"><?php echo $pagination; ?></a></li>     
   </ul>
 </nav>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>

</body>
</html>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

SQL中有两个连续的逗号:

SELECT COUNT(id), , 

删除其中一个。

答案 1 :(得分:0)

实际上在你的代码的第4行有两个逗号,我的朋友都删除了其中一个,一切都会好的 &安培; 快乐编码