RaiN3772 Posted November 15, 2021 Share Posted November 15, 2021 hello there, im not sure how to explain this, also tried googling it, but nothing shows up. so basically im searching for a method or a function, lets say i have multiple items in the database (item id, item_name, item description, item_price...etc) so basically i want to create a page lets say its called "view.php" basically i'll put everything in it, connected it to the database etc, and display an item depends on the item id, so the url could be "view.php?item-id" or "view/item-id" or any other method that is available, if someone could refer me to something. not sure. thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/ Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 Have you used your programming skills to attempt to build a web page? Even just the html portion? Something at all? Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592107 Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 Here's an example of the html you may need. Study it if you don't already know it. Look up what you don't know. <?php $code=<<<heredocs <!DOCTYPE html> <html> <head> <title>Untitled</title> <style type='text/css'> body { background-color:#c0c0c0; font-family:'Segoe UI','Trebuchet MS',Tahoma,Arial,Sans-serif; } #form_box { position:relative; float:left; width:50%; padding:15px; margin:1% 5%; border:1px solid blue; } .sz5 {width:5em;} .sz6 {width:5em;} .sz15 {width:12em;} .sz35 {width:30em;} </style> </head> <body> <div id='form_box'> <form method='POST' action='' autocomplete='off'> <label>Item id.: <input type='text' name='item_id' value="$item_id" class='sz5'> </label> <label>Name: <input type='text' name='item_name' value="$item_name" class='sz15'> </label> <br><br> <label>Desc.:<br> <textarea rows=4 cols=70 name='item_desc'>$item_desc</textarea> </label> <br><br> <label>Price.: <input type='text' name='item_price' value="$item_price" class='sz6'> </label> <center> <input type='submit' name='btn' value='Submit'> <center> </form> </div> </body> </html> heredocs; echo $code; exit(); Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592108 Share on other sites More sharing options...
RaiN3772 Posted November 15, 2021 Author Share Posted November 15, 2021 Hey @ginerjm, yes i already know html, css, long time experience with it actually, but lately i been learning php, so far, i already created listing all items as cards (bootstrap cards) from the database, also submitting a new item (insert into database) but i want to create a page where i can see item details, but i dont think the right method is to create each page for each item, so thats why im asking here, i think it has to do with $_GET or something and the url should be "view.php?=item-$item_id" Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592109 Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 I have no idea what your vision is. Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592111 Share on other sites More sharing options...
RaiN3772 Posted November 15, 2021 Author Share Posted November 15, 2021 8 minutes ago, ginerjm said: I have no idea what your vision is. simple, one file multiple pages, example "website.com/page.php?id=1", real life example "youtube.com/watch?v=610XM39EE1o" where the page is v and the id is the video id, how do i do this, thats the question Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592112 Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 So you have a set of records and you want to show all of their data elements on one scrolling page? Why not an html table then? Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592114 Share on other sites More sharing options...
mac_gyver Posted November 15, 2021 Share Posted November 15, 2021 (edited) 2 hours ago, RaiN3772 said: i think it has to do with $_GET or something and the url should be "view.php?=item-$item_id" yes. you would create one page that accepts a $_GET variable as an input. you would test if the variables is set (see isset()), trim, validate that the value is an integer greater than zero, then securely use the value in an sql query to get the matching data to display on the page. Edited November 15, 2021 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592115 Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 But he wants to see each item on one page as opposed to seeing one page with one item. I think anyway. That's why I suggested a table view. Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592116 Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 How about you take the div and form code and turn it into a php function. Run a query to get your data and then fetch it row by row and call the function, passing in the row data which will output a div/form for each record. If you don't need the form construct and just want to display the data, change it to an html table instead of a form and dump the div too. Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592117 Share on other sites More sharing options...
RaiN3772 Posted November 16, 2021 Author Share Posted November 16, 2021 23 hours ago, ginerjm said: How about you take the div and form code and turn it into a php function. Run a query to get your data and then fetch it row by row and call the function, passing in the row data which will output a div/form for each record. If you don't need the form construct and just want to display the data, change it to an html table instead of a form and dump the div too. <?php // Include Database Configuration File require_once "inc/config.php"; try { // Select Statement // $sql = "SELECT * FROM items WHERE item_status = 'Approved'"; $sql = "SELECT * FROM items inner Join users ON items.uid = users.uid WHERE item_status = 'Approved'"; $statement = $pdo->query($sql); // Get all items as associative array $items = $statement->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } $pdo = null; //close PDO connection function index_getItems() { global $items; foreach ($items as $items) { echo "<div class='d-flex align-items-sm-center mb-7'>"; echo "<div class='symbol symbol-60px symbol-2by3 me-4'>"; echo "<div class='symbol-label' style='background-image: url(" . $items["item_thumbnail"] . ")'></div>"; echo "</div>"; echo "<div class='d-flex flex-row-fluid flex-wrap align-items-center'>"; echo "<div class='flex-grow-1 me-2'>"; echo "<a href='#' class='text-gray-800 fw-bolder text-hover-primary fs-6'>" . $items["item_name"] . "</a>"; echo "<span class='text-muted fw-bold d-block pt-1'>" . $items["username"] . "</span>"; echo "</div>"; echo "<span class='badge badge-light-success fs-8 fw-bolder my-2'>$" . $items["item_price"] . "</span>"; echo "</div>"; echo "</div>"; } } ?> already did that to get all items, now i want to create page for item details, and pretty that the practical way to do so is not by creating each page for each item, "item-1.php" this way is efficient for alot of records, so i want a way to create a single page, and show item details depends on the $_GET method, so basically, if i go to item-1.php it should show me all the details on item ID = 1, same as 2 if go to item-2, it should show me the details about item 2...etc that is the question if you get what i'm talking about Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592167 Share on other sites More sharing options...
ginerjm Posted November 16, 2021 Share Posted November 16, 2021 I see that you have done something here. Don't know what is wrong with it so I guess you are happy. Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592169 Share on other sites More sharing options...
gizmola Posted December 6, 2021 Share Posted December 6, 2021 Quote already did that to get all items, now i want to create page for item details, and pretty that the practical way to do so is not by creating each page for each item, "item-1.php" this way is efficient for alot of records OR........... perhaps you just make a page call item.php, and you pass the id as a url parameter, query the data you need and present it. You can also use rewrites to make it look like a static url like /item/3. That used to be a benefit for SEO, but at this point search engines don't penalized you for having url parameters like item.php?id=3. Quote Link to comment https://forums.phpfreaks.com/topic/314235-how-do-i-create-a-template-page-for-multiple-items/#findComment-1592475 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.