Same page, different content?

1

All links have the same url but the data is different.

I'm working on a web based project where I have:

  • game categories:
  • games (table with games in each category)
  • description of each game (more details)

One of the categories is called FPS.PHP, on this page there are several table games coming from the database with the Name, Type and Platform fields. What I wanted was basically able to click on the name of each game and open a page called DESCRIPTION.PHP where the details of the game that we clicked would be.  Since games can be huge and making a page for each game would be exhausting, I wanted to be able to make a page that would serve as a description page for everyone.

PS: Each category has a table in the mysql database that contains games.

Does anyone know how to do this? FPS.PHP (First)

<?php

$servername = "localhost";
$username = "root";
$password = "Estagiarios2017#";
$dbname = "ricardo";

 // Create connection
 $conn = new mysqli($servername, $username, $password, $dbname);
 // Check connection
 if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

 $sql = "SELECT  name, tipo, plataforma FROM fps";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "<table><tr><th>Name  </th><th>Type  </th><th>Platform  </th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td><a href='description.php?idfps=".$row['name']."'</a>" . $row["name"]. "</td><td>" . $row["tipo"]. " </td><td>" . $row["plataforma"]. "</td></tr>";



}
echo "</table>";
} else {
echo "0 results";


}
?>

FPS.php EDITED

    <tr>
 <td  valign="top">
<div class="feed_title" ><?php echo $fps["name"]; ?></div>
<div id="fps-<?php echo $fps["idfps"]; ?>">
<input type="hidden" name="rating" id="rating" value="<?php echo $fps["rating"]; ?>" />
<ul onMouseOut="resetRating(<?php echo $fps["idfps"]; ?>);">
  <?php
  for($i=1;$i<=5;$i++) {
  $selected = "";
  if(!empty($fps["rating"]) && $i<=$fps["rating"]) {
    $selected = "selected";
  }
  ?>
  <li class='<?php echo $selected; ?>' onmouseover="highlightStar(this,<?php echo $fps["idfps"]; ?>);" onmouseout="removeHighlight(<?php echo $fps["idfps"]; ?>);" onClick="addRating(this,<?php echo $fps["idfps"]; ?>);">&#9733;</li>  
  <?php }  ?>
<ul>
</div>
<div><?php echo $fps["descricao"]; ?></div>

<?php echo"<a href='description.php?idfps=".$row['name']."'>Ver mais</a>"?>
</td>
</tr>
    
asked by anonymous 27.06.2017 / 21:09

2 answers

-1

On the FPS.php page, change the following line

echo "<tr><td><a href='description.php'</a>" . $row["name"]. ---------

Why will contain an idfps parameter with name value.

echo "<tr><td>". $row["name"]. "</td><td>" . $row["tipo"]. " </td><td>" . $row["plataforma"]. "</td><td><a href='description.php?idfps=".$row['name']."'>Ver mais</a></td></tr>";

Description.php This page takes the value of the idfps parameter to search the table where name is equal to the value of the parameter (in this case the name)

include('top.php');
$idfps = $_GET['idfps'];

 // Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

 $sql = "SELECT  * FROM fps where name='$idfps'";
 $result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "<table class='chart'><tr><th>Name</th><th>Categoria</th><th>Tipo</th><th>Plataforma</th><th>Editora</th><th>Lançamento</th><th>Descrição</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td width=80>" . $row["name"]. "</td><td width=80>" . $row["categoria"]. " </td><td width=80>" . $row["tipo"]. " </td><td width=80>" . $row["plataforma"]. " </td><td width=80>" . $row["editora"]. " </td><td width=80>" . $row["lancamento"]. " </td><td>" . $row["descricao"]. " </td></tr>";
 }
 echo "</table>";
 } 
 else 
 {
 echo "0 results";
 }
include('footer.php');
  

top.php and footer.php contains the html, css, etcc top-of-page script and rodape.

    
28.06.2017 / 01:54
0

It is not the answer to your question, but it is to help solve the problem with the modeling I told you:

As I understand it, you only need 2 or 3 tables.

Doing with 2:

Categories table:

id   |  nome
1    |  FPS
2    |  Corrida
3    |  RPG
4    |  Puzzle

Game Table:

id   |  nome        | categoria
 1   |  CS          | 1
 2   |  GRID        | 2
 3   |  Battlefield | 1
 4   |  DIRT        | 2

Then when you're going to make the pages, have one to see all the games in the category:

viewCategoria.php? id = 2

Run select on all games that have category 2 (Race) ... and list.

viewGame.php? id = 2

Run select in game 2 (GRID) and display its details

    
27.06.2017 / 21:26