Same page, different content?

Asked

Viewed 458 times

1

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

I’m working on a web based project that I have:

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

One of the categories is called FPS.PHP, on this page there are several table games coming from the database with the fields Name, Type and Platform. What I wanted was basically to be able to click on the name of each game and open a page called DESCRIPTION.PHP where would be the details of the game that we clicked. Since there could be lots of games 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 that? 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>
  • Voce created a table for each category ?

  • yes @Rovannlinhalis

  • =( complicated in, have to rethink this modeling your

  • Thank you! I just didn’t want to go to so much trouble to make huge pages for every game..... that’s very @Rovannlinhalis

  • Just as you don’t need to make a page for each game, you don’t need a table for each category... because then you wouldn’t need a database for that. Try to open a question first for modeling your program, what you need to do, then things will flow more easily.

  • @That’s what Leocaracciolo is all about!! How he did it!?

  • i did not understand your tables. can explain better, table such columns, table talequal taisequais columns, etccc

  • I have in mysql imagine a category fps that contains games and the fields of the games in the category page are just name, type and platform. When clicking on such game the description should be name, category, type, platform, publisher, release and description.

  • simplify as follows: TABLE fps COLUMNS name, type, platform TABLE xxxxx COLUMNS xx yy ... TABLE zzz COLUMNS aaa bbb ccc

  • TABLE fps COLUMNS name, category, type, platform, publisher, release and description.

  • It’s just a table?

  • so same release with ç and description with ç ?

  • without you and without my apologies

  • look, I know it’s already solved, but from a look at the friendly url and regular expressions with php and htaccess, Thiago Belem has a blog that helped a lot at the beginning and I wanted to do exactly what you want to do, today, with these tips, I create much better apps, you can use the URI to search the database and create a dynamic page without opening another, spending less of the connection

  • @flourigh does not necessarily use two pages, it was done so because it is in question. The two response pages can merge into one by making only one connection and one select.

  • @leo-Caracciolo yes, indeed, it was just a suggestion

  • @Leocaracciolo thinks he can help me with this question ? https://answall.com/questions/216221/como-fazer-simulador-de-cliques-num-link-e-por-cada-clique-adicionar-1-centimo

Show 12 more comments

1 answer

0

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

From what I understand, you only need 2 or 3 tables.

Making with 2:

Table of Categories:

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

Table of Games:

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

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

viewCategoria.php? id=2

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

viewGame.php? id=2

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

  • Ah! So what about this viewGame.php? id=2 is inserted where I have to say "href='Description.php' ?" @rovannLinhalis

  • yes, in the link to that game, it will have to be something like href='description.php?id=2'. ?id=2 is a parameter passed by GET that you will be able to get inside php, something like $id = $_GET["id"]; and then select the game with that id, Select * from jogos where id = $id;

  • @Joyana recommend watching some video lessons, about simple php entries. It may not be games, but the principle is the same: https://www.google.com/search?q=criando+um+cadastro+em+php&rlz=1C1NHXL_pt-BRBR728BR728&oq=criando+um+umcadastro+emphp&aqs=chrome..69i57.52j0j7&sourceid=chrome&ie=UTF-8

Browser other questions tagged

You are not signed in. Login or sign up in order to post.