Jump to content

Create a list PHP/mySQL


gal87

Recommended Posts

Hi there!

 

I want to create a website about consoles & console games. Right now I'm at the very early stages of it, you can see it on this address:

http://www.gal87.tarhely.biz/szakdolgozat

 

As you can see, on the site there's 5 menu point: Kezdőlap (Home), Xbox 360, Playstation 3, Wii, Közösség (Community/Forum).

 

Each console menu contains a drop down menu, "A konzolról" = 'About console' and "Játékok" = 'Games'.

 

I've already created a database for the xbox games that contains the gameid (primary key), gameTitle, gameGraphic, gameDescription. First of all I need to list the Xbox games by title or by the graphics (cover of the games). Then if somebody clicks any of the title/covers then it show the detailed info of the game on a new page or something like that.

 

I hope you understand, what I mean, guys. Is is possible to do this? /*Sorry for my grammar, I'm from Hungary.*/

 

Thanks for ANY help/advice/suggestion in advance!

Link to comment
Share on other sites

Well, I know how to connect to the mysql database.

 

Here's my code:

<?php require_once('Connections/szakdolgozat.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_szakdolgozat, $szakdolgozat);
$query_rs_xboxgames = "SELECT gameTitle, gameGraphic, gameDesc FROM xbox ORDER BY gameId ASC";
$rs_xboxgames = mysql_query($query_rs_xboxgames, $szakdolgozat) or die(mysql_error());
$row_rs_xboxgames = mysql_fetch_assoc($rs_xboxgames);
$totalRows_rs_xboxgames = mysql_num_rows($rs_xboxgames);
?>

 

And in the body part:

<?php include("_includes/header.php"); ?>
  <h1> </h1>
    <h2><?php echo $row_rs_xboxgames['gameTitle']; ?></h2>
    <p><img src="_images/<?php echo $row_rs_xboxgames['gameGraphic']; ?>" width="195" height="262" /></p>
    <p><?php echo $row_rs_xboxgames['gameDesc']; ?></p>

 

With this method I can display a game's name, cover, and description from the database. But I don't know how to display in one page only the cover/title of the games, then on an other page the full detailed infos (with description) of the game.  I'm really confused. :confused: I'm using Adobe Dreamweaver CS5, the whole code above was made by that program.

Link to comment
Share on other sites

1. in your query also include getting the game id, you will need that to know which game to display on your 'second page'.

 

2. In the body part

<?php 
include("_includes/header.php"); 
?>  
<h1> </h1>    
<h2><?php echo $row_rs_xboxgames['gameTitle']; ?></h2>    
<p><a href="details.php?id=<?PHP echo $GAME_ID; ?>" target= "_BLANK"><img src="_images/<?php echo $row_rs_xboxgames['gameGraphic']; ?>" width="195" height="262" /></a></p>    
<p><?php echo $row_rs_xboxgames['gameDesc']; ?></p>

 

3. In the details.php file

<?PHP
$id = $_GET['id'];
/* then use that $id to query the db for the details of the game and display them */

 

Make sense?

Link to comment
Share on other sites

/* then use that $id to query the db for the details of the game and display them */

 

Now, if I click any xbox games cover, it doesn't load the details, and the link looks like this:

http://localhost/szakdolgozat/xbox_games_details.php?id=

 

I assume the problem is, that the number is missing after the "id=".  So long story short, I don't know how to "use the $id to query the db". Sorry, if this is a lame question, but I'm just started to learn to create dynamic websites.

Link to comment
Share on other sites

Yes, the details file is xbox_games_details.php.

 

Code from that details file:

<?php require_once('Connections/szakdolgozat.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_szakdolgozat, $szakdolgozat);
$query_Recordset1 = "SELECT gameId, gameTitle, gameGraphic, gameDesc FROM xbox";
$Recordset1 = mysql_query($query_Recordset1, $szakdolgozat) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

 

Then i put the

<?PHP
$id = $_GET['id'];

in the body part.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.