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
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.";
}

?>
Edited by QuickOldCar
Link to comment
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.";
}

?>

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

Link to comment
Share on other sites

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

Edited by QuickOldCar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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