Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all actually i want to know how to extract id values from database table and pass id value from one page to another without using form in php. actually i have a index.php page and in there i had a div where i have shown some titles from the same table abstract from database but what i want is that i want to make those title as a link and after clicking that link i want it to pass its id values from database in another page say description.php which can grab that id value and show the title description on that description.php page which also belongs to same tables from database.
Posted
Updated 21-Jan-19 23:50pm

1 solution

You can use HTTP GET method without form(Generate links manually):

index.php:
PHP
$connect = mysqli_connect('127.0.0.1', 'root', '', 'db');

$query = mysqli_query($connect, "SELECT id, title FROM items");

//List items
while($row = mysqli_fetch_array($query))
{
	echo '<a href="description.php?id='.$row['id'].'">'.$row['title'].'</a>';
}

?>


description.php
PHP
if(isset($_GET['id']))
{
$item_id = $_GET['id'];

$connect = mysqli_connect('127.0.0.1', 'root', '', 'db');

$query = mysqli_query($connect, "SELECT * FROM items WHERE id='$item_id'");

if(mysqli_num_rows($query) != 0)
{
	
//Show item description
while($row = mysqli_fetch_array($query))
{
	echo '<a href="description.php?id='.$row['id'].'">'.$row['title'].'</a>';
	echo $row['description'];
}


}
else
{
	//Error item does not exist
}

}
else
{
	//Error
}

?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900