Jump to content

Displaying master details page links in columns


wchamber22

Recommended Posts

Hi,

 

I would like to display my master details page links to the details pages in three columns rather than a single column.

 

Below is the do-while code I have thus far, and I am stuck.  Could someone please mock up this code quick, because I know it is a simple syntax error somewhere.

 

<?php do {

echo "<table border='0'>";

for ($y=1; ; $y++) {

echo "<tr>";

for ($x=1; $x<=3; $x++) {

echo "<td align='left'><a href="plantdetails.php?recordID=echo $row_rsBotanicalA['PlantID'];">; echo $row_rsBotanicalA['BotanicalName']; </a></td>"

}

echo "</tr>";

}

}

while ($row_rsBotanicalA = mysql_fetch_assoc($rsBotanicalA));

echo "</table>";

?>

Link to comment
Share on other sites

<?php

$columns = 3;
$recCount = 0;
$plantDetailsHTML = '';
while ($row = mysql_fetch_assoc($rsBotanicalA))
{
    $recCount++;
    //Open row if needed
    if($recCount%$columns==1)
    {
        $plantDetailsHTML .= "<tr>\n";
    }
    
    //Display record
     $plantDetailsHTML .= "<td align=\"left\">";
     $plantDetailsHTML .= "<a href=\"plantdetails.php?recordID={$row['PlantID']}\">{$row['BotanicalName']}</a>";
     $plantDetailsHTML .= "</td>\n";
    
    //Close row if needed
    if($recCount%$columns==0)
    {
        $plantDetailsHTML .= "</tr>\n";
    }
}
//Close last row if needed
if($recCount%$columns!=0)
{
    $plantDetailsHTML .= "</tr>\n";
}
?>
<table>
<?php echo $plantDetailsHTML; ?>
</table>

Link to comment
Share on other sites

MJ,

 

Almost there! It is displaying the plants names in columns just as I pictured via your code, except that it is not displaying the first result of the query.  Every other database result thereafter displays perfectly!

 

MAN, my code was way off earlier!

 

I am a landscaper trying to showcase plant information on our website to become a leader in the area of plant expertise. If you are in or around the Central IL area I will get you some plants for your garden if you would like.

 

Nice work, and I am sure I'll have more questions. 

Link to comment
Share on other sites

You must search your script, Dreamweaver is horrible about fetching the results before you actually need them, thereby moving the array_pointer one index (which makes it seem that you are missing a row).

 

So, look for:

mysql_fetch_assoc($rsBotanicalA)

 

And delete it, (as long as it is above the code that Mj gave you above.

 

Or, you can post your entire script here, inside the proper [ code ] blocks, and we will strip it out for you.

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.