Jump to content

post an id so i can grab it a use it to display page content accordingly


dazz_club

Recommended Posts

firstly, apologises from the long winded subject header.

 

ok, I have been trying to get one of my links to, when pressed, pass the id (from the case study link) so the page it lands on (case-studies.php) can use it to get the correct content to display it.

 

I have a menu called case studies, with the case study links underneath eachother, like this

 

CASE STUDY MENU

-----------------

case study 1

case study 2

case study 3

----------------

 

This is how i have set up its table in my database;

 

casestudiesmenu

----------------

id

case_name

title

---------------

 

I have a script that is retrieving the case studies from the table above with this;

 

<?php

$casestudy = "SELECT * FROM casestudiesmenu";

$result = mysqli_query($connection, $casestudy);

 

While ($row = mysqli_fetch_array($result)){

$case_name = $row["case_name"];

$title = $row["title"];

$id=$row["id"];

 

 

echo '

<li><a href="case-studies.php=' .$row["id"]. '" title="'. $row["title"].'" class="class4">' . $row["case_name"]. '</a></li>';

 

}

?>

 

When i hover my curser over any of the case studies, the link displays  this case-studies.php=5

 

I then went ahead and created a case-studies.php file. The reason i created this file is to display the case study in accordance to what case study number is passed across from the original link.

 

here is my script for case-studies.php

 

------------------------

<?php require_once("includes/connection.php"); ?>

<?php

$id = $_GET['id'];

if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { //correctly accessed

$id = $_GET['id'];

} else {

$errors[] = 'You have accessed this page incorrectly.';

}

 

 

{

$sql = "SELECT * FROM case_studies WHERE id = $id";

 

If ($r = mysqli_query ($connection, $sql)) {

//sending the query to the mySQL server

While ($row = mysqli_fetch_array($r)) {

//inputs the data into the table

 

$id = $row['id'];

$title = $row['title'];

$content = $row['content'];

$download = $row['download'];

$image = $row['image'];

}

}

}

?>

<html>

<head>

<title>Game cards & Labels</title>

<link rel="stylesheet" type="text/css" href="css/style.css" />

<script type="text/javascript" src="javascript/lightbox.js"></script>

</head>

<body>

<div id="container">

<div id="holder">

<div id="header"><?php include("includes/top-inlcude.php"); ?></div>

<div id="topNav"><?php include("includes/main-nav.php"); ?></div>

<div id="content">

<div id="left"><?php include("includes/left-hand-coloumn.php"); ?></div>

<div id="middle">

<h2><?php echo $title; ?></h2>

<ul style="list-style-type:none;margin:0px;padding:0px;color:red;float:right;font-size:8pt;">

<li><img src="images/close-up/Bud Exposure.jpg" style="height:200px;width:240px;border:1px solid black;margin:5px;"/></li>

<li style="padding:4px;text-align:center;">Download | Print</li>

</ul>

<p><?php echo $content; ?></p>

 

</div>

<div id="right"><?php include("includes/right-hand-coloumn.php"); ?></div>

<div id="footer"><?php include("includes/footer.php"); ?></div>

</body>

</html>

------------------------

 

Currently, as you might have guessed its not working.

 

If anyone can help me that would be great.

 

kind regards

Dazzclub

Hi, I have done that, also some tweaking.

 

 

When you now press one of the case study links it goes the case-studies.php page (orginally it didnt even show) and now displays some content from the correct table (within the case_studies table). But when i press any of ther other links the content doesnt change.

 

hmmm, i'll do more research on this.

 

 

 

kind regards

 

 

Hi, I have managed to sort it out.

 

I had to change case-studies.php a bit.

 

Originaly i had used lower case id like this

 

if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { //correctly accessed

$id=$_GET['id'];

} else {

 

I then chose to change them to UPPERCASE like this

 

if ( (isset($_GET['ID'])) && (is_numeric($_GET['ID'])) ) { //correctly accessed

$id=$_GET['ID'];

} else { ....

 

I then had to change my query from

 

$sql = "SELECT * FROM case_studies WHERE id = $id";

     

      to

 

$sql = "SELECT * FROM case_studies WHERE ID = $id";

 

And it now works.

 

Below is my working script

 

<?php

if ( (isset($_GET['ID'])) && (is_numeric($_GET['ID'])) ) { //correctly accessed

$id=$_GET['ID'];

} else {

$errors[] = 'You have accessed this page incorrectly.';

}

 

 

{

$sql = "SELECT * FROM case_studies WHERE ID = $id";

 

If ($r = mysqli_query ($connection, $sql)) {

//sending the query to the mySQL server

While ($row = mysqli_fetch_array($r)) {

//inputs the data into the table

 

 

$id = $row['ID'];

$case_title = $row['case_title'];

$content = $row['content'];

$download = $row['download'];

$image = $row['image'];

}

}

}

?>

 

 

Thanks for all your help.

 

kind regards

Dazzclub

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.