Jump to content

Display SQL data by clicking list


FreakingFrog

Recommended Posts

I am brand new to PHP but, after using W3 Schools,  can retrieve a record from a MySQL database using php & SQLi. 

 

I have a page with a list of between 20 and 30 items down one side and a panel on the other. When a user clicks a list item I want to display the details of the clicked item in the panel. The details are: Program (text), Convenor (text), Dates (text), Times (Text), Location (text), Notes (Text large). 

 

The details are stored in a MySQL Database 'Documents', in a table 'Programs' and I would like to put the details into text boxes in the panel.

 

Could you point me to some info on doing this please?

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/292797-display-sql-data-by-clicking-list/
Share on other sites

You can add GET parameters to the urls to control what content is being viewed

 

http://mysite.com/?location=home

 

retrieve the get query and use it's values

 

if(isset($_GET['location']) && trim($_GET['location']) != ''){

$location = trim($_GET['location']);

} else {

$location = 'home';

}

 

You can include a page using this data or use it dynamic in a database query to change the results in the same script

 

I'll use categories as an example

$sql = "SELECT * FROM table_name WHERE category='$location'";

 

 

 

a php page including scripts within (very basic example)

<?php

//creates the pages array

//make a php script for each item in the array
$pages = array(
    "home",
    "about",
    "contact",
    "links",
    "post"
);

//loop the pages as href links

foreach ($pages as $page) {
    
    echo "<a href='?location=$page'>$page</a> ";
    
}

//GET from address bar

if (isset($_GET['location']) && in_array(trim($_GET['location']), $pages)) {
    
    $location = trim($_GET['location']);
    
} else {
    
    $location = 'home';
    
}

//so can see it work
echo "<h2>".$location."</h2>";

//include a page
$script = dirname(__FILE__) . DIRECTORY_SEPARATOR . $location.".php";
if (file_exists($script)) {
    include($script);
} else {
    echo "That page does not exist.";
}

?>

 

You can add GET parameters to the urls to control what content is being viewed

 

http://mysite.com/?location=home

 

retrieve the get query and use it's values

 

if(isset($_GET['location']) && trim($_GET['location']) != ''){

$location = trim($_GET['location']);

} else {

$location = 'home';

}

 

You can include a page using this data or use it dynamic in a database query to change the results in the same script

 

I'll use categories as an example

$sql = "SELECT * FROM table_name WHERE category='$location'";

 

 

 

a php page including scripts within (very basic example)

<?php

//creates the pages array

//make a php script for each item in the array
$pages = array(
    "home",
    "about",
    "contact",
    "links",
    "post"
);

//loop the pages as href links

foreach ($pages as $page) {
    
    echo "<a href='?location=$page'>$page</a> ";
    
}

//GET from address bar

if (isset($_GET['location']) && in_array(trim($_GET['location']), $pages)) {
    
    $location = trim($_GET['location']);
    
} else {
    
    $location = 'home';
    
}

//so can see it work
echo "<h2>".$location."</h2>";

//include a page
$script = dirname(__FILE__) . DIRECTORY_SEPARATOR . $location.".php";
if (file_exists($script)) {
    include($script);
} else {
    echo "That page does not exist.";
}

?>

Thanks for your efforts QOC but this does not mean much to me. I would prefer some targetted reading.

The W3 schools are excellent & I have worked though a lot of it but have not found how to pass a link into the database (I can do it manually) and display the data in a panel on the same page.

I can find a record in the database & retrieve the required record but I am after how to put it back on the same page.

Thx

I can find a record in the database & retrieve the required record but I am after how to put it back on the same page.

 

 

I don't understand what you want to do.

 

Put what back on the same page?

 

Do you mean to echo out results from the while loop in a divider?

mysqli_fetch_assoc

Post your code here and try to explain where the issue is.

Use the <> button to post code

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.