Forum Moderators: coopster
I would like to know how i would pass an id number from a link to a new page, where by this page is looking at what id number has been passed to display that specific content.
Heres a little more info.
I currently have a menu called "case studies" and underneath this, is yes you guessed it, a list of case studies on certain products (which are links).
Here is how i have set the table out in my database. That holds the case study links
casestudiesmenu
--------------
id
case_name
title
--------------
Here is my php script that is pulling out my data from this table;
<?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="index.php?case-studies=' .$row["id"]. '" title="'. $row["title"].'" class="class4">' . $row["case_name"]. '</a></li>';
}
?>
So what i would like to happen here is, when i press any of the case studies, say for example case study 4, which is also the id number. This number 4 will be sent over to my case-studies.php where it grabs that id number then displays the content accordingly.
I have written a script in my case-studies.php which is trying but failing to get the id number that is being sent;
<?php
$id='';
if(!empty($_GET['id']))
{
$id = (int)$_GET['id'];
}
if($id >=1 && $id <=13)
{
$sql = "SELECT * FROM case_studies WHERE id = $id";
If ($r = mysqli_query ($connection, $query)) {
//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'];
}
}
}
?>
If anyone can lend a hand or even post an url on say dynamic url tutorials, i will be most pleased.
kind regards
Dazzclub
For your URL, the only bit of info you really need to pass is the ID number... Then run a script on the next page to gather all the desired info related to that ID.
To start with... here is the variation I use for gathering an ID or any other info from a URL
Where the URL is: somepage.php?id=1
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { //correctly accessed
$id=$_GET['id'];
} else {
$errors[] = 'You have accessed this page incorrectly.';
}
then run your SELECT script on your database
$query = "SELECT* FROM table WHERE id=$id";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if ($num > 0) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
}
$title = $row['title'];
etc. etc.
Hope that helps...
Russ
<li><a href="case-studies.php?id=' .$row["id"]. '" title="'. $row["title"].'" class="class4">' . $row["case_name"]. '</a></li>';