Can't Make a Dynamically Built Menu Wrap to 2nd line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azrazorback
Forum Newbie
Posts: 2
Joined: Thu Sep 04, 2008 1:27 am

Can't Make a Dynamically Built Menu Wrap to 2nd line

Post by azrazorback »

I am trying to modify a code written by someone else and can't figure it out. The site builds menu buttons based on makes of cars. Client has added more makes and now the menu buttons stretch across on 1 line causing the scrolling. I would like to be able to have the buttons wrap to the next line, based on the browser window size. I've tried modifying the style sheet but with no luck.

The code for the function that creates the buttons is:

<php>function fnMakeButtons()
{
global $oDB;
// 9/26/03 9:18PM
// This is the function that will display distinct Makes at the top of the page

$strSQL = $oDB->executeSQL("select distinct(strMake) as strMake from tblCarList");
$strWidth= 100/mysql_num_rows($strSQL);

?>
<?
while($objMake=mysql_fetch_object($strSQL))
{
?>
<td ><a href="search.php?strMake=<?=$objMake->strMake?>&btnSearch=5" title="Click here to see our <?=$objMake->strMake?> vehicles">
<?=$objMake->strMake?>
</a></td>
<?
}
?>
<?
}
</php>
The page code to where the menu is built is:
<php><table class="TABLEmain" border="0">

<tr>

<td style="width:100%;" colspan="0">

<div id="vehMenu">

<table class="vehMenu">

<tr>

<?fnMakeButtons()?>

</tr>

</table>

</div></td>

</tr>

<tr >

<th style="text-align:center;width:100%;" align="center"> <div style="font-size18px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#000066; ">SEARCH OUR LOT</div>

Click on a vehicle make above to start your search.

<div style="font-size18px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#000066; ">HAVEN'T MADE UP YOUR MIND?</div>

<div id="vehMenu" align="center" style="width:225px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px "> <a title="Click Here To View Our Entire Lot" href="type.php">View Our Entire Lot</a> </div>

OR

<div id="vehMenu" align="center" style="width:350px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px ">

<form action="search.php?btnSearch=5" method="post" name="frmStock" id="frmStock" style="text-align:left">

<fieldset>

<legend>Search By Stock Number</legend>

<label for="strStock"> Stock Number:</label>

<input type="text" name="strStock" size="16"/>

<input name="btnSearch" type="submit" onclick="MM_validateForm('strStock','','R');return document.MM_returnValue" value="Search" />

</fieldset>

</form>

</div></th>

</tr>

</table>
</php>

Thanks for your help.
paperplate
Forum Newbie
Posts: 16
Joined: Thu Sep 04, 2008 12:15 pm

Re: Can't Make a Dynamically Built Menu Wrap to 2nd line

Post by paperplate »

Your no-wrapping problem is because you keep making new cells on a single row. What you need to do is limit a row to X cells.
For example,

Code: Select all

 
<?
    $rcount = 0;
    $cells_per_row = 4;
    while($objMake=mysql_fetch_object($strSQL))
    {
        if ($rcount % $cells_per_row == 0) {
            //need to start a new row, but if $rcount > 0, we need to close the previous row
            if ($rcount > 0)
                echo "</tr>";
            echo "<tr>";
        }
 
        ?>
<td ><a href="search.php?strMake=<?=$objMake->strMake?>&btnSearch=5" title="Click here to see our <?=$objMake->strMake?> vehicles">
    <?=$objMake->strMake?>
    </a></td>
<?
        $rcount++;
    }
    if ($rcount > 0)        //need to close last row
        echo "</tr>";
    ?>
 
You then would only need:

Code: Select all

 
<table class="vehMenu">
 
<?fnMakeButtons()?>
 
</table>
 
azrazorback
Forum Newbie
Posts: 2
Joined: Thu Sep 04, 2008 1:27 am

Re: Can't Make a Dynamically Built Menu Wrap to 2nd line

Post by azrazorback »

Thanks. That works great!! :D
Post Reply