PHP kilistázás, részletesen
Sziasztok!
Egy kis PHP-s segítségre lenne szükségem. Adott egy php fájl, "xbox_games.php", aminek a következő a tartalma:
Ezzel elértem azt, hogy az adatbázisból kilistázza a játékok borítóját a lapra.
Azonban lenne még egy "xbox_games_details.php", ami megjelenítené a játékok címét, borítóját, és rövid leírását, csak azt nem tudom, hogy ezt miképp tudnám elérni.
$id = $_GET['id'] <- ezt kellene használni, illetve a mysql_fetch_assoc-ot valahogy?
Előre is köszönöm, ha valaki szán egy kis időt a kódom átnézésére, és esetleg segítséget is nyújtana. Nagyon fontos lenne.
■ Egy kis PHP-s segítségre lenne szükségem. Adott egy php fájl, "xbox_games.php", aminek a következő a tartalma:
<?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_xboxgames = "SELECT gameId, gameTitle, gameGraphic, gameDesc FROM xbox ORDER BY gameTitle ASC";
$xboxgames = mysql_query($query_xboxgames, $szakdolgozat) or die(mysql_error());
$row_xboxgames = mysql_fetch_assoc($xboxgames);
$totalRows_xboxgames = mysql_num_rows($xboxgames);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Konzoljátékok bemutatása</title>
<style type="text/css">
<!--
h1 {
font-size: 18px;
color: #2F9F73;
}
h2 {
font-size: 16px;
color: #28B980;
}
a:link {
text-decoration: none;
color: #48A5CC;
}
a:visited {
text-decoration: none;
color: #477AAD;
}
a:hover {
text-decoration: underline;
color: #6CB596;
}
a:active {
text-decoration: none;
}
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
color: #000;
background-image: url(images/bkgd.jpg);
background-attachment: fixed;
background-position: center top;
}
/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
padding: 0;
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
margin-top: 0; /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
padding-right: 15px;
padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
border: none;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
text-decoration: none;
}
/* ~~ this fixed width container surrounds the other divs ~~ */
.container {
width: 900px;
margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
}
/* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
.header {
}
/* ~~ This is the layout information. ~~
1) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.
*/
.content {
padding: 10px 0;
background-image: url(images/bkgdContent.jpg);
}
/* ~~ The footer ~~ */
.footer {
padding: 10px 0;
background-color: #7295AF;
text-align: center;
}
/* ~~ miscellaneous float/clear classes ~~ */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
-->
</style>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include("_includes/header.php"); ?>
<h1> </h1>
<h1>
</h1>
<p>
<?php do { ?>
<a href="xbox_games_details.php?id=<?php echo $row_xboxgames['gameId']; ?>" target= "_BLANK"> <img src="_images/<?php echo $row_xboxgames['gameGraphic']; ?>" width="195" height="262" />
<?php } while ($row_xboxgames = mysql_fetch_assoc($xboxgames)); ?>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><br />
<br />
<br />
</p>
<!-- end .content --></div>
<?php include("_includes/footer.php"); ?>
<!-- end .container --></div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>
<?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_xboxgames = "SELECT gameId, gameTitle, gameGraphic, gameDesc FROM xbox ORDER BY gameTitle ASC";
$xboxgames = mysql_query($query_xboxgames, $szakdolgozat) or die(mysql_error());
$row_xboxgames = mysql_fetch_assoc($xboxgames);
$totalRows_xboxgames = mysql_num_rows($xboxgames);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Konzoljátékok bemutatása</title>
<style type="text/css">
<!--
h1 {
font-size: 18px;
color: #2F9F73;
}
h2 {
font-size: 16px;
color: #28B980;
}
a:link {
text-decoration: none;
color: #48A5CC;
}
a:visited {
text-decoration: none;
color: #477AAD;
}
a:hover {
text-decoration: underline;
color: #6CB596;
}
a:active {
text-decoration: none;
}
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
color: #000;
background-image: url(images/bkgd.jpg);
background-attachment: fixed;
background-position: center top;
}
/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
padding: 0;
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
margin-top: 0; /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
padding-right: 15px;
padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
border: none;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
text-decoration: none;
}
/* ~~ this fixed width container surrounds the other divs ~~ */
.container {
width: 900px;
margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */
}
/* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
.header {
}
/* ~~ This is the layout information. ~~
1) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.
*/
.content {
padding: 10px 0;
background-image: url(images/bkgdContent.jpg);
}
/* ~~ The footer ~~ */
.footer {
padding: 10px 0;
background-color: #7295AF;
text-align: center;
}
/* ~~ miscellaneous float/clear classes ~~ */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
-->
</style>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include("_includes/header.php"); ?>
<h1> </h1>
<h1>
</h1>
<p>
<?php do { ?>
<a href="xbox_games_details.php?id=<?php echo $row_xboxgames['gameId']; ?>" target= "_BLANK"> <img src="_images/<?php echo $row_xboxgames['gameGraphic']; ?>" width="195" height="262" />
<?php } while ($row_xboxgames = mysql_fetch_assoc($xboxgames)); ?>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><br />
<br />
<br />
</p>
<!-- end .content --></div>
<?php include("_includes/footer.php"); ?>
<!-- end .container --></div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>
Ezzel elértem azt, hogy az adatbázisból kilistázza a játékok borítóját a lapra.
Azonban lenne még egy "xbox_games_details.php", ami megjelenítené a játékok címét, borítóját, és rövid leírását, csak azt nem tudom, hogy ezt miképp tudnám elérni.
$id = $_GET['id'] <- ezt kellene használni, illetve a mysql_fetch_assoc-ot valahogy?
Előre is köszönöm, ha valaki szán egy kis időt a kódom átnézésére, és esetleg segítséget is nyújtana. Nagyon fontos lenne.
?
2. Mi a kérdésed?
Létre kell hoznod az xbox_games_details.php fájl és, mint ebben is, kell csinálnod egy sql select-et amivel lekérdezed a kiválasztott elemhez tartozó infókat.
Mivel semmi több infót nem adtál meg, hogy milyen táblákban tárolod az adatokat és még mindig nem vagyunk médiumok, ezért csak általánosságban:
Köszi!
Mysql adatbázis úgy néz ki (egyelőre), hogy van egy 'szakdolgozat' nevű adatbázis, abban van egy 'xbox' tábla. Ebben van 4 db mező: gameId [int(11), auto_increment, primary key], gameTitle [varchar(50)], gameGraphic [varchar(50)], gameDesc [text].
Egy ilyet csináltam az xbox_games_details.php fájlba:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.
hát
Nem tudom, hogy ezt látja-e hibának, minden esetre, amit látok:
Akkor
Meg tudod mutatni valahol az
Vagy akkor szúrd be ide, egymás alá az xbox_games.php és xbox_games_details.php jelenlegi tartalmát.
Az xbox_games.php
Nincs Id a táblában, csak
Köszi
Az intval-ra nincs szükség,