Cassie_au Posted May 21, 2008 Share Posted May 21, 2008 hey guys! i am looking to display items from a mysql database onto a page where each item has a link to a more detailed page (on the item). I understand this is called 'Master/Detail' in Dreamweaver however doing this using script, i can't find any tutorials :s (is it much harder than just displaying data onto a page from the db?) also, if i only want to display a certain amount of information from the description field, how would i go about culling the rest of the displayed data? (usually replaced on sites with '...Read More') Thanks a lot guys! Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 21, 2008 Share Posted May 21, 2008 basic example of your search results: <?php /* Enter your DB stuff here */ $sql = "SELECT `id`, `name` FROM `table`;"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result){ $id = $row['id']; $name = $row['name']; print "<a href='detail.php?id={$id}'>{$name}</a><br />"; } Basic detail page: <?php /* Enter your DB stuff here */ $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM `table` WHERE `id`='{$id}' LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); //output your HTML, including all your rows as $row['row_name'] ?> Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted May 21, 2008 Share Posted May 21, 2008 The master detail is not too bad... You just need to list the results on the first page, at the same time, for each row create a link to the detail page and append the unique id for each row like: <a href="detail.php?id=<?php echo your_unique_id ?>">Details</a> That would generate a link like details.php?id=1234 Then on the detail page, use $_GET to grab the id and query the database for that specific record and redisplay it. for part two, I'm sure there are other ways, but I use substr() to get the amount of the string I want for instance: $fieldtoshrink = substr($fieldtoshrink, 0, 50); $fieldtoshrink .= "... "; Then add you link. Hope that helps to get you started, Matt Quote Link to comment Share on other sites More sharing options...
Cassie_au Posted May 22, 2008 Author Share Posted May 22, 2008 Thanks Jonsjava you did all the scripting so fast! and thanks a lot Matt for explaining it all too!! ill try this out tonight, thanks guys! Quote Link to comment Share on other sites More sharing options...
vozzek Posted May 22, 2008 Share Posted May 22, 2008 A few months back I came here just like you... a snot-nosed Master/Detail rookie mired up to my knees in gooey, superfluous DreamWeaver code. Yuck. The advice you've received so far is good, and you should start with that. I'd advise you not to use the DreamWeaver wizards to generate any code for you... while it might eventually work it will be sloppy and overly coded. Even worse, you won't understand what any of the code does... which will come back to bite you in the ass when you're ready to convert your pages to DIV tags, CSS, or whatever else you want to do. www.Tizag.com has some awesome tutorials. Learn how mySQL works first, and then spend some time messing around with it. Learn how to SELECT fields from your database all by yourself, without DreamWeaver walking you through it. Once you understand database interaction, Master/Detail will become easy to master (pun intended) and your code will be a hell of a lot cleaner too. Quote Link to comment Share on other sites More sharing options...
Cassie_au Posted May 27, 2008 Author Share Posted May 27, 2008 Thanks a lot guys!! With your help i got those pages done! I was thinking, if i have 3 tables (3 diff categories of products), how would i go about making only 1 detail page which will collect the id from whichever link is clicked? ($sql = "SELECT * FROM `table`..) sort of bars me down to one table on the detail page :s thanks in advanced for your help! Quote Link to comment 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.