0

I have made a search function that works as I want. When I search, I get the results as a link, but when I click on the link I want to generate a unique page for the row (link) that I click. When I click, the URL changes to; search.php?id=1, search.php?id=2.... but I'm still on the same page, I'm stuck here. Can someone help me?

 <?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>"; 
  } 

  }

  } 
?> 
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • You're using `search.php?id=2` yet your column is `ID`, could be it. – Funk Forty Niner Jun 19 '14 at 17:20
  • Plus this `if(isset($_GET['go'])){ ` where's that variable coming from, another page (undoubtedly)? – Funk Forty Niner Jun 19 '14 at 17:22
  • 1
    I think we need to back up a bit. There's `isset($_POST['submit'])` and an `isset($_GET['go'])` a little odd, but can work if you know what you're doing. What is the code in search.php? I don't see the query to get the page info. Questions: Do you want to reload the page to show the page? Or do you want to use an XHR object (AKA AJAX) to grab the info off the server? – bloodyKnuckles Jun 19 '14 at 17:27
  • this is a page with a list of games. if you search for example far cry 3, i want click on the result, and there is all the info abouth the game. – user3752656 Jun 19 '14 at 17:31

0 Answers0