Passing php variables through pages / sql -
i have following information displayed
<?php $my_query="select * games"; $result= mysqli_query($connection, $my_query); if (mysqli_num_rows($result) > 0) while ($myrow = mysqli_fetch_array($result)) { $description = $myrow["game_description"]; $image = $myrow["gamepic"]; $game_id = $myrow["game_id"]; $gamename = $myrow["game_name"]; echo "<div class='cover'> <a href='game_details.php?gameid={$game_id}'> <img src=\"games/$image\" class=\"thumbnail\" width=\"200\" height=\"200\"> </a> </div>"; } ?>
as can see have created game_details page display specific game_id when image clicked
im having trouble understanding how pull data out game_id in sql on other page.
here attempt on game_details page
<?php if (!isset($_get['$game_id']) || empty($_get['game_id'])) { echo "invalid category id."; exit(); } $game_id = mysqli_real_escape_string($connection, $_get['game_id']); $sql1 = "select * games game_id={$game_id}'"; $res4 = mysqli_query($connection, $sql1); if(!$res4 || mysqli_num_rows($res4) <= 0) { while ($row = mysqli_fetch_assoc($res4)) { $gameid = $row['$game_id']; $title = $row['game_name']; $descrip = $row['game_description']; $genre = $row['genretype']; echo "<p> {$title} </p>"; } } ?>
this attempt giving me "invalid category id" error
would appreciate
there few issues code.
let's start top.
['$game_id']
need remove dollar sign in $_get['$game_id']
then, $row['$game_id']
same thing; remove dollar sign.
then, game_id={$game_id}'
throw syntax error.
in first body of code; should use proper bracing conditional statements.
this 1 has none if (mysqli_num_rows($result) > 0)
, cause potential havoc.
rewrites:
<?php $my_query="select * games"; $result= mysqli_query($connection, $my_query); if (mysqli_num_rows($result) > 0){ while ($myrow = mysqli_fetch_array($result)) { $description = $myrow["game_description"]; $image = $myrow["gamepic"]; $game_id = $myrow["game_id"]; $gamename = $myrow["game_name"]; echo "<div class='cover'> <a href='game_details.php?gameid={$game_id}'> <img src=\"games/$image\" class=\"thumbnail\" width=\"200\" height=\"200\"> </a> </div>"; } } ?>
sidenote where game_id='{$game_id}'
in below. if doesn't work, remove quotes it.
where game_id={$game_id}
2nd body:
<?php if (!isset($_get['game_id']) || empty($_get['game_id'])) { echo "invalid category id."; exit(); } $game_id = mysqli_real_escape_string($connection, $_get['game_id']); $sql1 = "select * games game_id='{$game_id}'"; $res4 = mysqli_query($connection, $sql1); if(!$res4 || mysqli_num_rows($res4) <= 0) { while ($row = mysqli_fetch_assoc($res4)) { $gameid = $row['game_id']; $title = $row['game_name']; $descrip = $row['game_description']; $genre = $row['genretype']; echo "<p> {$title} </p>"; } } ?>
use error checking tools @ disposal during testing:
Comments
Post a Comment