0% found this document useful (0 votes)
29 views2 pages

'Includes/db - PHP' 'SELECT Id, Title, Release - Date, Publisher, Rating, System, Num - Players FROM Videogames ORDER BY Title ASC'

This PHP code connects to a MySQL database called "mygames" on localhost. It queries the "videogames" table to retrieve game data ordered by title, then loops through the results to display the title, release date, publisher, system, rating, and number of players for each game. It also includes links to edit or delete each game entry.

Uploaded by

ahmad saifullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

'Includes/db - PHP' 'SELECT Id, Title, Release - Date, Publisher, Rating, System, Num - Players FROM Videogames ORDER BY Title ASC'

This PHP code connects to a MySQL database called "mygames" on localhost. It queries the "videogames" table to retrieve game data ordered by title, then loops through the results to display the title, release date, publisher, system, rating, and number of players for each game. It also includes links to edit or delete each game entry.

Uploaded by

ahmad saifullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

<?

php

$dbinfo = 'mysql:dbname=mygames;host=localhost';

$user = 'root';

$pass = 'root';

//If you need to change database information, just change values

above.

$db = new PDO($dbinfo, $user, $pass);

$db->exec('SET CHARACTER SET utf8');

require_once 'includes/db.php';

$sql = $db->query('SELECT id, title, release_date, publisher, rating,

system, num_players FROM videogames ORDER BY title ASC');

$results = $sql->fetchAll(PDO::FETCH_OBJ);

<?php foreach($results as $entry): ?>


<tr>
<td><?php echo $entry->title; ?></td>
<td><?php echo $entry->release_date; ?></td>
<td><?php echo $entry->publisher; ?></td>
<td><?php echo $entry->system; ?></td>
<td><?php echo $entry->rating; ?></td>
<td><?php echo $entry->num_players; ?></td>
<td><a href="edit.php?id=<?php echo $entry->id; ?
>">Edit</a> <a href="delete.php?id=<?php echo $entry->id; ?
>">Delete</a></td>
</tr>
<?php endforeach; ?>
$sql = $db->prepare('DELETE FROM games WHERE id = :id');
$sql->bindValue(':id', $_GET['id'], PDO::PARAM_INT);
$sql->execute();

$sql = $db->prepare('UPDATE games SET title = :title, release_date


= :release_date, publisher = :publisher, system = :system, rating
= :rating, num_players = :num_players WHERE id = :id');
$sql->bindValue(':id', $id, PDO::PARAM_INT);
$sql->bindValue(':title', $title, PDO::PARAM_STR);
$sql->bindValue(':release_date', $release_date,
PDO::PARAM_STR);
$sql->bindValue(':publisher', $publisher,
PDO::PARAM_STR);
$sql->bindValue(':system', $system, PDO::PARAM_STR);
$sql->bindValue(':rating', $rating, PDO::PARAM_INT);
$sql->bindValue(':num_players', $num_players,
PDO::PARAM_INT);

You might also like