Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Drop Down Navigation in Php...
Old 12-25-2011, 07:55 PM Drop Down Navigation in Php...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Hi All,

Merry Christmas to everyone!

I would like to know how to create a drop down navigation (html form) that lists some text like link1 link2 link3 etc..And each one of those 'links' in the drop down navigation would link to the result of a mysql query.

For example here is my query:
PHP Code:
$query="select ad_type, banner from amp_ads WHERE ad_type=1"
$result=mysql_query($query);

while (
$row=mysql_fetch_array($result)) { 

echo 
"<img src='$row[banner]'>";


I would like to take the results of the query and have that as the link to each of the text links in the drop down menu.

How is that accomplished? Sorry if that seems so basic, I've been having php nightmares lately...Trying to get through them with as little pain as possible.

The idea would be to have each link in the drop down goto a different ad_type as the query currently shows the Where clause as ad_type=1, but the other text in the drop down list would go to ad_type=2 3 4 5 etc without having to code a separate query for each link in the drop down. Note: The ad_type part may not be in the order as shown, maybe like link 1 maybe ad_type=1 and link 2 might be ad_type=5 as an example.

Here's the basic idea of the drop down menu: Note: I quickly copied/pasted the code below.

HTML Code:
<html>
<body>
<form action="dummy" method="post"><select name="choice" size="1" onChange="jump(this.form)"><option value="">Choose a Link</option><option value="#">Standard Banners</option><option value="#">Half Size Banners</option><option value="">------</option><option value="#">Standard Buttons</option><option value="#">Mini Buttons</option></select></form>
</body>
</html>
Thank you!
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 12-25-2011 at 08:48 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-26-2011, 05:00 AM Re: Drop Down Navigation in Php...
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
First, select the id's of all the banners with one query, to be able to show the links.
PHP Code:
$query 'select ad_type from amp_ads';
$result mysql_query($query);
while (
$row mysql_fetch_array($result)) {
    echo 
'<a href="somewhere.php?ad_type=' $row['ad_type'] . '">Banner</a>';

Then on "somewhere.php" (which could be the same page, of course) you check if the ad_type is set, and fetch the corresponding banner.

PHP Code:
if (isset($_GET['ad_type']) && is_numeric($_GET['ad_type'])) {
    
$id mysql_real_escape_string($_GET['ad_type']);
    
$query 'select ad_type,banner from amp_ads WHERE ad_type=' $id;
    
$result=mysql_query($query);

    while (
$row mysql_fetch_array($result)) { 
        echo 
'<img src="' $row['banner'] . '" alt="banner">';
    }

} else {
    
// some error handling of some sort...

__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 12-26-2011 at 05:02 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Drop Down Navigation in Php...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.24740 seconds with 12 queries