Jump to content

Relationship with master/detail?


Cassie_au

Recommended Posts

hey guys! :D

 

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! :D

Link to comment
Share on other sites

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']
?>

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

Thanks a lot guys!!

 

With your help i got those pages done! :D

 

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!  :)

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.