• Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~
skyhighweb

php drop down sub menu

37 posts in this topic

hi programmers how u doing? i need help creating a sub menu but with a twist

MENU
Submenu- team1 on click will display dropdown list of team2 lists
team2 on click will display dropdown list of team1 lists

if a user select (team1) it should drop down list of [team2] and if the user select (team2) it should drop list of [team1].

the code below is only a menu without submenu need ur assistance, thanks alot

 

// team select
		$query = "SELECT a.id, a.team1, a.team2, b.auction, b.bidder, b.tagged, b.willwin FROM " . $DBPrefix . "auctions a
		LEFT JOIN " . $DBPrefix . "bids b ON (b.auction = a.id)
		WHERE a.id = :auc_id and a.id = a.id group by a.id";
		$params = array();
		$params[] = array(':auc_id', $id, 'int');
		$db->query($query, $params);

		$TPL_team_list = '<select name="willwin" class="form-control">' . "\n";
		while ($row = $db->fetch())
		{
			$TPL_team_list .= "\t" . '
			<option value="' . $row[''] . '" ' . $selected . '>' . $row[''] . '</option>
			<option value="' . $row['team1'] . '" ' . $selected . '>' . $row['team1'] . '</option>
			<option value="' . $row['team2'] . '" ' . $selected . '>' . $row['team2'] . '</option>
			' . "\n";
		}
		
		$TPL_team_list .= '</select>' . "\n";

{
	$template->assign_block_vars('tag_bidder', array(
	'TEAM' => $TPL_team_list,

			));
	$i++;
}

Tables : auctions

columns: id(int), team1, team2
3 chelsea ajax

Tables : bids
columns: auction(int) bidder willwin
3 9 chelsea
3 5 ajax
3 7 chelsea
3 2 ajax
3 6 chelsea
3 4 chelsea

Share this post


Link to post
Share on other sites

if a user select (team1) it should drop down list of [team2] and if the user select (team2) it should drop list of [team1].

I don't know what that means.

If you're trying to make dropdowns which depend on other dropdowns, the basic way to do that is to have the form submit when you pick from the parent list, PHP gets the submitted value for that list, and writes out the child list based on the parent value.  You could also use ajax to submit the value to the server and have it return the options for the child list, then update the page with that.

Share this post


Link to post
Share on other sites
6 minutes ago, justsomeguy said:

 

 

I don't know what that means.

If you're trying to make dropdowns which depend on other dropdowns, the basic way to do that is to have the form submit when you pick from the parent list, PHP gets the submitted value for that list, and writes out the child list based on the parent value.  You could also use ajax to submit the value to the server and have it return the options for the child list, then update the page with that.

yeah am trying to make a dropdown that depends on other drop down but no idea how to go about it

Share this post


Link to post
Share on other sites

Well, there's 2 options I mentioned.  Either have a normal form submit where you get the parent value and use it to build the child dropdown with PHP, or get the parent value with Javascript and send it to the server using ajax to get the list of options for the child dropdown.

Share this post


Link to post
Share on other sites
19 minutes ago, justsomeguy said:

Well, there's 2 options I mentioned.  Either have a normal form submit where you get the parent value and use it to build the child dropdown with PHP, or get the parent value with Javascript and send it to the server using ajax to get the list of options for the child dropdown.

i totally understand wwhat u saying my friend but i just dont know how to start about it thats y i posted the menu code am using, can u plz take a look at it for me n help out, will b grate ful

Share this post


Link to post
Share on other sites

Do you know how to get form data?  That would be the first step to getting the options for the second dropdown.  If you don't know how to do that, I would suggest starting with some of the beginning PHP tutorials.  Getting data from a form is one of the more basic things you should understand.

Share this post


Link to post
Share on other sites
11 hours ago, justsomeguy said:

Do you know how to get form data?  That would be the first step to getting the options for the second dropdown.  If you don't know how to do that, I would suggest starting with some of the beginning PHP tutorials.  Getting data from a form is one of the more basic things you should understand.

hi jsg thanks for ur reply, have been over it again n again cant even seem to get it to work, please help me out with it, i will b glad n have a good nite sleep today, thanks

Share this post


Link to post
Share on other sites

You need to start with something.  I'm here to help people learn, not write code for them.  Go look at the PHP form tutorials and start there.  Start with a form that has your dropdown in it where you can submit it and get the value that was selected.

Share this post


Link to post
Share on other sites

Posted (edited)

the code above is a form with drop down n also can submit i just need it to have a submenu

Edited by skyhighweb

Share this post


Link to post
Share on other sites

So get the submitted value, and use it to look up whatever database records correspond to that, and build the other dropdown.  I'm not sure what you're missing.  If you know how to process a form, and you know how to use the database, and you know how to build a dropdown, which part are you having problems with?

Share this post


Link to post
Share on other sites
4 hours ago, justsomeguy said:

So get the submitted value, and use it to look up whatever database records correspond to that, and build the other dropdown.  I'm not sure what you're missing.  If you know how to process a form, and you know how to use the database, and you know how to build a dropdown, which part are you having problems with?

hi am having problem on the drop down part if i knew what to do i would have stopped posting questions n do it

Share this post


Link to post
Share on other sites

I'm not sure what else to say.  You have code to create a dropdown already based on information in the database.  You've said that you know how to get data from a form.  So, get the data from the form for the parent dropdown, and use it to get the data from the database and build the child dropdown almost exactly like the code you showed in the first post.

If you're just copying and pasting code without understanding how it works, then that's the problem.  If that's the case you need to start with the PHP tutorials to learn how this stuff works before expecting that you'll be able to change or add to it.

Share this post


Link to post
Share on other sites
13 hours ago, justsomeguy said:

I'm not sure what else to say.  You have code to create a dropdown already based on information in the database.  You've said that you know how to get data from a form.  So, get the data from the form for the parent dropdown, and use it to get the data from the database and build the child dropdown almost exactly like the code you showed in the first post.

If you're just copying and pasting code without understanding how it works, then that's the problem.  If that's the case you need to start with the PHP tutorials to learn how this stuff works before expecting that you'll be able to change or add to it.

i am trying something hopefully that works also posted a issue about it

Share this post


Link to post
Share on other sites

hello programmers again really need your help with this, i Need a menu linked to a sub menu

i have a menu code and a submenu code but they arent linked, both i select manually, so i need help linking both of them.
the menu consist of two values team1 and team2 i want when i select team1 it should drop down a menu of users who selected team1 and vice versa.

for the MENU we got two tables they are

auctions: with column: id             team1      team2  
bids:       with column: auction     bidder      willwin


and for the sub menu we also have two tables
bids     with:  column: auction     bidder      willwin
users  with:  column:  nick

 

MENU CODE

// MENU team select
		$query = "SELECT a.id, a.team1, a.team2, b.auction, b.bidder, b.tagged, b.willwin, b.willlose FROM " . $DBPrefix . "auctions a
		LEFT JOIN " . $DBPrefix . "bids b ON (b.auction = a.id)
		WHERE a.id = :auc_id and a.id = a.id group by a.id";
		$params = array();
		$params[] = array(':auc_id', $id, 'int');
		$db->query($query, $params);

		$TPL_team_list = '<select name="willwin" class="form-control">' . "\n";
		while ($row = $db->fetch())
		{
			$TPL_team_list .= "\t" . '
			<option value="' . $row[''] . '" ' . $selected . '>' . $row[''] . '</option>
			<option class="team1" value="' . $row['team1'] . '" ' . $selected . '>' . $row['team1'] . '</option>
			<option class="team2" value="' . $row['team2'] . '" ' . $selected . '>' . $row['team2'] . '</option>
			' . "\n";
		}
		
		$TPL_team_list .= '</select>' . "\n";

{
	$template->assign_block_vars('tag_bidder', array(
	'TEAM' => $TPL_team_list,

			));
	$i++;
}

SUBMENU CODE   

// SUBMENU user name
        $query = "SELECT b.*, u.nick, u.rate_sum FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
WHERE b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder') and b.auction = :auc_id order by b.willwin";
$params = array();
$params[] = array(':auc_id', $id, 'int');
$db->query($query, $params);

        $TPL_team_list = '<select name="tagged" class="form-control">' . "\n";
        while ($row = $db->fetch())
        {
            $TPL_team_list .= "\t" . '
            <option value="' . $row[''] . '" ' . $selected . '>' . $row[''] . '</option>
            <option value="' . $row['bidder'] . '" ' . $selected . '>' . $row['nick'] . '...' . $row['willwin'] . '</option>
            ' . "\n";
        }
        
        $TPL_team_list .= '</select>' . "\n";

{
    $template->assign_block_vars('tag_bidder', array(
    'NAME' => $TPL_team_list,

            ));
    $i++;
}


really looking forward to ur help thanks.

Share this post


Link to post
Share on other sites

Let's keep the discussion about the same issue in a single thread.

The explanation for how to do this is still the same, so what's different?  You still need to get the value from the first dropdown, and use to build the second dropdown, however they relate?  Which part are you stuck on?

Share this post


Link to post
Share on other sites

Posted (edited)

hi, am stuck on linking the sub menu to the menu, as u can see from the codes i manually select them, i just need em link, thanks

Edited by skyhighweb

Share this post


Link to post
Share on other sites

Do you know how to get the value of the first dropdown?  You can either submit it regularly with a form, or get it with Javascript and send it with ajax.  I've already asked you these questions though, you seemed to indicate that you know how to get the value from the form.  If you don't, you need to hit the PHP tutorials to learn the basics.

Share this post


Link to post
Share on other sites

Posted (edited)

13 minutes ago, justsomeguy said:

Do you know how to get the value of the first dropdown?  You can either submit it regularly with a form, or get it with Javascript and send it with ajax.  I've already asked you these questions though, you seemed to indicate that you know how to get the value from the form.  If you don't, you need to hit the PHP tutorials to learn the basics.

i can get the first value wwith a form but getting the sub menu is the issue for me else would have done that,  just look tru for me n assist me, that wwill b great thanks, either JavaScript or ajax cant seem to get it to connect.

Edited by skyhighweb

Share this post


Link to post
Share on other sites

When the form is submitted,OR the select dropdown triggers a onchange event that uses AJAX, it should pass the value of selection using $_POST[] or $_GET to the second dropdown.

It usually uses this value to filter and access the related records, but I currently do not see any fields that would possibly do that? All I see is filtering by 'auc_id', is this relative value passed through by team1 or team2?

Share this post


Link to post
Share on other sites
9 hours ago, dsonesuk said:

When the form is submitted,OR the select dropdown triggers a onchange event that uses AJAX, it should pass the value of selection using $_POST[] or $_GET to the second dropdown.

It usually uses this value to filter and access the related records, but I currently do not see any fields that would possibly do that? All I see is filtering by 'auc_id', is this relative value passed through by team1 or team2?

hi, i am no where near a submenu drop down linked to menu, all i have is  a field for the menu and a field for the submenu seperately, auc_id is used to display only data being viewed at the moment.

Share this post


Link to post
Share on other sites

The array is treated as tables, the value from first dropdown is used to show other related info from related array/table info.

The way the second dropdown is processed can be placed in another php file, which is called by using ajax.

This is a rough guide on how to send info from first to second dropdown, the principle is the same, I did not reproduce the effect using your code, as you seem to want us to do it for you, as you keep saying  you tried this and that! But! don't actually show us what code you tried, just the repeated showing of the same code.

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        if (isset($_POST['willwin'])) {
            $teamRec = $_POST['willwin'];
        }


        $team_array = [];
        $team_array['Team1'] = ['Team #1 dropdown1', 'Team #1 dropdown2', 'Team #1 dropdown3', 'Team #1 dropdown4'];
        $team_array['Team2'] = ['Team #2 dropdown1', 'Team #2 dropdown2', 'Team #2 dropdown3', 'Team #2 dropdown4'];
        ?>

        <form id="myform" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
            <select name="willwin" class="form-control">
                <option value="">Select Team </option>
                <?php
                $optioncount = 0;
                foreach ($team_array as $key => $value) {
                    $optioncount++;
                    if ($key === $teamRec) {
                        echo '<option class="team' . $optioncount . '" value="' . $key . '" selected="selected">Team #' . $optioncount . '</option>';
                    } else {
                        echo '<option class="team' . $optioncount . '" value="' . $key . '">Team #' . $optioncount . '</option>';
                    }
                }
                ?>


                <!--<option class="team1" value="Team1">Team #1</option>
                <option class="team2" value="Team2">Team #2</option>-->

            </select><br>
            <?php
            if (isset($_POST['willwin'])) {


                echo '<select name="tagged" class="form-control">';
                echo '<option value="">Select Team Info </option>';
                $team_array_item = $team_array[$teamRec];

                foreach ($team_array_item as $key => $value) {
                    echo '<option value="' . $value . '">' . $value . '</option>';
                }
                echo '</select><br>';
            }
            ?>


            <input type="submit">
        </form>


    </body>
</html>

 

Share this post


Link to post
Share on other sites
36 minutes ago, dsonesuk said:

The array is treated as tables, the value from first dropdown is used to show other related info from related array/table info.

The way the second dropdown is processed can be placed in another php file, which is called by using ajax.

This is a rough guide on how to send info from first to second dropdown, the principle is the same, I did not reproduce the effect using your code, as you seem to want us to do it for you, as you keep saying  you tried this and that! But! don't actually show us what code you tried, just the repeated showing of the same code.


<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        if (isset($_POST['willwin'])) {
            $teamRec = $_POST['willwin'];
        }


        $team_array = [];
        $team_array['Team1'] = ['Team #1 dropdown1', 'Team #1 dropdown2', 'Team #1 dropdown3', 'Team #1 dropdown4'];
        $team_array['Team2'] = ['Team #2 dropdown1', 'Team #2 dropdown2', 'Team #2 dropdown3', 'Team #2 dropdown4'];
        ?>

        <form id="myform" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
            <select name="willwin" class="form-control">
                <option value="">Select Team </option>
                <?php
                $optioncount = 0;
                foreach ($team_array as $key => $value) {
                    $optioncount++;
                    if ($key === $teamRec) {
                        echo '<option class="team' . $optioncount . '" value="' . $key . '" selected="selected">Team #' . $optioncount . '</option>';
                    } else {
                        echo '<option class="team' . $optioncount . '" value="' . $key . '">Team #' . $optioncount . '</option>';
                    }
                }
                ?>


                <!--<option class="team1" value="Team1">Team #1</option>
                <option class="team2" value="Team2">Team #2</option>-->

            </select><br>
            <?php
            if (isset($_POST['willwin'])) {


                echo '<select name="tagged" class="form-control">';
                echo '<option value="">Select Team Info </option>';
                $team_array_item = $team_array[$teamRec];

                foreach ($team_array_item as $key => $value) {
                    echo '<option value="' . $value . '">' . $value . '</option>';
                }
                echo '</select><br>';
            }
            ?>


            <input type="submit">
        </form>


    </body>
</html>

 

i have been trying, for example have been working on the below code it doing what i want but problem with it is it displays all data in a table instead of whats been viewed at the moment

<?php
require_once('conn.php');
ini_set('display_errors',0);

$query = "SELECT b.auction, b.bidder, b.tagged, b.willwin, b.willlose, a.id, a.team1, a.team2  FROM " . $DBPrefix . "vs_auctions a
LEFT JOIN " . $DBPrefix . "vs_bids b ON (b.auction = a.id) 
LEFT JOIN " . $DBPrefix . "vs_sports s ON (s.team_id = b.id) 
WHERE a.id = b.auction and a.id = a.id group by b.auction";
$country_result = $conn->query($query);

?>


<select name="country" id="vs_sports-list" onchange="changeSelect( this.value )">
<option value="1">Select Team</option>
<?php
if ($country_result->num_rows > 0) {
// output data of each row
while($row = $country_result->fetch_assoc()) {
?>
<option value="<?php echo $row["willwin"]; ?>"><?php echo $row["team1"]; ?></option>
<option value="<?php echo $row["willlose"]; ?>"><?php echo $row["team2"]; ?></option>
<?php
}
}
?>
</select>
</br></br></br><div id="subcats">
<select name="bidder" id="vs_bids-list">
<option value='1'>Select Number</option>

</select></div>
<?php

$willlose = mysql_real_escape_string($_POST['willlose']);
if($willlose!='')
{


$vs_bids_result = $conn->query('select b.auction, b.bidder, b.tagged, b.willwin, b.willlose from vs_bids b where willlose='.$willlose.' ');
$options = "<option value=''>Select Name</option>";
while($row = $vs_bids_result->fetch_assoc()) {
$options .= "<option value='".$row['id']."'>".$row['bidder']."</option>";
}
echo $options;
}

?>

<script src="js/dropdown/jquery-1.3.0.min.js"></script>

<script>
$('#vs_sports-list').on('change', function(){
var willlose = this.value;
$.ajax({
type: "POST",
data:'willlose='+willlose,
success: function(result){
$("#vs_bids-list").html(result);
}
});
});

</script>

in my existing code i am using this

$query = "SELECT a.id, a.team1, a.team2, b.auction, b.bidder, b.tagged, b.willwin FROM " . $DBPrefix . "auctions a
		LEFT JOIN " . $DBPrefix . "bids b ON (b.auction = a.id)
		WHERE a.id = :auc_id and a.id = a.id group by a.id";
		$params = array();
		$params[] = array(':auc_id', $id, 'int');
		$db->query($query, $params);

thats display only what been viewed at the moment

Share this post


Link to post
Share on other sites

IS $willlose = mysql_real_escape_string($_POST['willlose']); returning a value?

Just make sure it returns a value first, and this

</select></div>

should be UNDER the php outputted options.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now