使用PHP为mySQL表中的每一行创建唯一页面

时间:2014-06-19 17:18:19

标签: php html mysql database mysqli

我已经制作了一个可以按照我想要的方式运行的搜索功能。当我搜索时,我将结果作为链接,但是当我点击链接时,我想为我点击的行(链接)生成一个唯一的页面。单击时,URL将更改为; search.php?id=1, search.php?id=2.... 但我仍然在同一页上,我被困在这里。有人能帮助我吗?

 <?php 
  if(isset($_POST['submit'])){ 
  if(isset($_GET['go'])){ 
  if(preg_match('/^[a-z0-9 .\-]+$/i', $_POST['name'])){ 
  $name=$_POST['name']; 

  $db=mysqli_connect  ("localhost", "root",  "", "games") 
   or die ('I cannot connect      to the database  because: ' . mysqli_error()); 

  $sql="SELECT  ID, name, release_year, publisher, genre 
  FROM gamelist WHERE name LIKE '%" . $name .  "%' OR publisher LIKE '%" . $name ."%'"; 

  $result=mysqli_query($db, $sql); 

  while($row=mysqli_fetch_array($result)){ 
          $name=$row['name']; 
          $publisher=$row['publisher']; 
          $release_year=$row['release_year'];
          $ID=$row['ID']; 


  echo "<ul>\n"; 
  echo "<li>" . "<a  href=\"search.php?id=$ID\">"   .$name . " - 
      " . $publisher .  " - " . $release_year .  "</a></li>\n"; 
  echo "</ul>"; 
  }

  if (mysqli_num_rows($result) == 0) {
    echo "<p>No results. Try another keyword.</p>"; 
  }    
  else { 
  }

  }

  else{ 
  echo  "<p>Please enter a search query</p>"; 
  } 

  }

  } 
?> 

0 个答案:

没有答案