FreakingFrog Posted November 30, 2014 Share Posted November 30, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/292797-display-sql-data-by-clicking-list/ Share on other sites More sharing options...
QuickOldCar Posted November 30, 2014 Share Posted November 30, 2014 (edited) 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 November 30, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/292797-display-sql-data-by-clicking-list/#findComment-1498067 Share on other sites More sharing options...
QuickOldCar Posted November 30, 2014 Share Posted November 30, 2014 BTW, stop by php.net if you want to learn php Quote Link to comment https://forums.phpfreaks.com/topic/292797-display-sql-data-by-clicking-list/#findComment-1498068 Share on other sites More sharing options...
FreakingFrog Posted November 30, 2014 Author Share Posted November 30, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/292797-display-sql-data-by-clicking-list/#findComment-1498081 Share on other sites More sharing options...
QuickOldCar Posted November 30, 2014 Share Posted November 30, 2014 (edited) 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 November 30, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/292797-display-sql-data-by-clicking-list/#findComment-1498138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.