Hyperlinks in drop down menu

I need some help with making hyperlinks work when someone clicks a drop down menu item. I am cycling through mysql table using php to populate the menu dropdown. But my hyperlinks don’t work. Any ideas would be appreciated. Started new topic here since it is a different subject than my original drop down menu issue. Thanks.
Here is the code that won’t work. Won’t display anything at all on the page.
[php]echo “<option onClick=”‘index.php?content=buyproducts&cat=$catid’">’.$name.’’;[/php]

The statement needs to be between and

If it’s not producing anything, likelihood is that it’s something in a different part of your code. Could you post the code in full in order for us to evaluate it properly.

I have tried moving the select around to no avail. Thanks!

[php]<?php

$query = “SELECT catid, name from categories ORDER BY catid ASC”;
$result = mysql_query($query);
echo “

\n”;

echo “”;

while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
$catid = $row[‘catid’];
$name = $row[‘name’];

  echo '<option onClick=\"'index.php?content=buyproducts&cat=$catid'\">$name</option>';

  echo '<option value=\"'.$catid.'\">'.$name.'</option>';

}
echo “”;
echo “

\n”;
echo “\n”;

?>[/php]

TrayDavid,

I’m going to delete your new topic, since it’s the same as this one. Can you paste the html output you get from your code in the last sample you posted here with the onClick method.

I’ll be at my PC for the next few hours, I should be able to get it working for you.

Thanks.

MOBILE Device Homepage

title goes here

JOIN FREE!
AmericanMexicanThaiFrenchItalianJapaneseIndianChinese

Thank you for any help.

Any luck? Thanks.

Sorry about that, I got caught up redesigning phphelp.com.

Here’s your solution…

[php]

<?php $query = "SELECT catid, name from categories ORDER BY catid ASC"; $result = mysql_query($query); echo "\n"; echo ""; while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $catid = $row['catid']; $name = $row['name']; echo '$name'; } echo ""; echo "\n"; echo "\n"; ?>[/php]

Here is my code now, with the script part you gave in the index page, not on this page.

[php]

\n"; echo "\n"; ?>
<?php $query = "SELECT catid, name from categories ORDER BY catid ASC"; $result = mysql_query($query); echo "
\n"; echo ""; while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $catid = $row['catid']; $name = $row['name']; echo '$name'; } echo ""; echo "
[/php]

And here is the index page that now does not work. Can’t even pull any drop down or the footer. I can’t figure out if it is syntax for the html tables or what. I have tried several different combinations to no avail. Thanks for any help. It only shows the header area and the rest of the page is blank. And thanks for the help so far.

[php]<?php
session_start();
?>

<?php include("mylibrary/login.php"); include("mylibrary/showproducts.php"); include("mylibrary/showproducts2.php"); include("mylibrary/showproducts3.php"); include("mylibrary/showproducts4.php"); include("mylibrary/showproducts5.php"); login(); ?>
<?php include("mobileheader.inc.php"); ?>
<?php include("mobilenav.inc.php"); ?>
<?php include("footer.inc.php"); ?>
[/php]

It’s my fault, try the code below. Just a few misplaced Quotes and Single Quotes. I did test the code in just regular HTML markup so it does works. I just can’t test everything with your database connection and while loop.

[php]

<?php $query = "SELECT catid, name from categories ORDER BY catid ASC"; $result = mysql_query($query); echo '\n'; echo ''; while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { $catid = $row['catid']; $name = $row['name']; echo '$name'; } echo ''; echo '\n'; echo '\n'; ?>[/php]

Sorry for the late response…crazy work schedule lately. I tried this again and can’t make it work. Should the script part be in the head section or just above the rest of the code? Neither way works for me. Maybe I’m putting things in the wrong place on the page? Thanks.

Is it possible to provide me a link so I can see it running?

I can’t yet due to sensitive nature of beta project. I do appreciate your help though. I have an index page that pulls in the nav page, header page, etc. One of those pages is the page that pulls items into the dropdown menu. I don’t know if I should put the script part in the index page or somehow in the actual page that the dropdown menu php is on. Thanks again.

You can email me what you have and I’ll take a look at it tomorrow, if I get time. Just use the mail icon next to my name to send it to me.

By the way, the new redesign of phphelp.com looks pretty good!

Here is the code for the index page (that pulls in the linked page with the problem):

[php]<?php
session_start();
?>

thankyou <?php include("mylibrary/login.php"); include("mylibrary/showproducts.php"); include("mylibrary/showproducts2.php"); include("mylibrary/showproducts3.php"); include("mylibrary/showproducts4.php"); include("mylibrary/showproducts5.php"); login(); ?>
<?php include("mobileheader.inc.php"); ?>
<?php include("nav.inc.php"); ?>
<?php include("footer.inc.php"); ?>
[/php]

And the issue is on the nav page. I list the departments now in a column with hyperlinks. This long list runs off the page. I’m trying to convert this list of departments into a dropdown menu list with hyprlinks. Here is the code for the nav page that I have working as a column:

[php] <?php
$query=“SELECT catid,name from categories ORDER BY catid”;
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$catid = $row[‘catid’];
$name = $row[‘name’];
$query2=“SELECT count(prodid) FROM products WHERE catid = $catid”;
$result2 = mysql_query($query2);
$row=mysql_fetch_array($result2);
$total = $row[0];
echo “<a href=“index.php?content=buyproducts&cat=$catid”>$name ($total)
\n”;
}
?>
[/php]

Any help is appreciated. If you will, let me know where to put any edits. For example, I have tried to put scripting in the head section of the index page as well as just prior to the php on the nav page. None seems to work right for me. I have researched this on the Internet and in my php/mysql/apache book but can’t seem to find a solution that works. Thanks again.

Give this a try…

[php]

<?php $query="SELECT catid,name from categories ORDER BY catid"; $result=mysql_query($query); echo ''; while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $catid = $row['catid']; $name = $row['name']; $query2="SELECT count(prodid) FROM products WHERE catid = $catid"; $result2 = mysql_query($query2); $row=mysql_fetch_array($result2); $total = $row[0]; echo '' . $name . '(' . $total . ')'; } echo ""; ?>[/php]

Thank you very much. That’s the look I wanted. Thanks again!

So it looks great but I can’t get the hyperlink part to work. I click on an item in the dropdown and nothing happens…back to the same page with the dropdown. Any advice? Thx

Make sure you have the Javascript I posted in your code. If you are using Chromr or FireFox access developer tools java console and take a look to make sure their are no errors.

Sponsor our Newsletter | Privacy Policy | Terms of Service