Sub menu issue revisit

i have this menu with dependant sub menu

MENU CODE

//MENU 
$query = "SELECT u.id, u.nick, s.team_id, s.teams AS teams1, ss.team_id, ss.teams AS teams2, 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)
        LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
        LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = a.team1)
        LEFT JOIN " . $DBPrefix . "sports ss ON (ss.team_id = a.team2)
        WHERE b.auction = :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" id="menu">' . "\n";
if ($db->numrows() > 0){
        while ($row = $db->fetch())
        {
            $TPL_team_list .= "\t" . '
            <option value="' . $row[''] . '" ' . $selected . '>' . $row[''] . '</option>
            <option value="' . $row['team1'] . '" ' . $selected . '>' . $row['teams1'] . '</option>
            <option value="' . $row['team2'] . '" ' . $selected . '>' . $row['teams2'] . '</option>
            ' . "\n";
        }
        
        $TPL_team_list .= '</select>' . "\n";

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

            ));
    $i++;
}
}



?>
<script type="text/javascript" src="../js/dropdownjquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    
    $("#menu").change(function() {
        $(this).after('<div id="loader"><img src="../images/loading.gif" alt="loading subcategory" /></div>');
        var auction = $("#auc_id").text();  
 $.get('loadsubcat.php?menu=' + $(this).val() + "&auc_id=" + auction, function(data) {
            $("#sub_cat").html(data);
            $('#loader').slideUp(200, function() {
                $(this).remove();
            });
        });    
    });

});
</script>
    </select>

SUBMENU CODE found in loadsubcat.php

<?php 
include('../config.php');
ini_set('display_errors',0);

$menu = $_GET['menu'];
$query = mysql_query("SELECT a.id, s.team_id, s.teams, u.nick, ut.nick_tag, b.id, b.willwin, b.willlose, b.bidder, b.tagged, b.bid, b.auction FROM vs_bids b 
LEFT JOIN " . $DBPrefix . "vs_users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "vs_users_tag ut ON (ut.id = b.tagged)
LEFT JOIN " . $DBPrefix . "vs_auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "vs_sports s ON (s.team_id = b.willwin)
WHERE willwin='$menu' and b.tagged != '0' order by b.tagged desc");

while($row = mysql_fetch_array($query)) {
    echo "<option value=''></option>";
    echo "<option value='$row[team_id]'>$row[auction]...$row[nick]...$row[bid]...$row[teams]...$row[nick_tag]</option>";
    
}


?>


so i need

  1. is there a way i make it a one page thing?
  2. the menu code works fine but the submenu display result from both the actual data and from all over if the user name is found in other column what am i doing wrong here

Why do you pass auc_id into the submenu code, but never retrieve it and never use it?

You also need to stop using the old mysql functions - use the more modern method that you use in the main code.

I don’t know of a way to merge it all into a single page, but it would be interesting if someone with more knowledge can comment. As I see it, your Ajax call needs to connect to a separate php script to generate the submenu each time the selection in the main menu changes. I guess you could pre-load the submenus for each selection in the main menu and then just assign the appropriate one on selection, but that might be an issue if there are a lot of data items in each menu. It would also pose a problem if the contents of the submenu changes from the time the page is first loaded.

1 Like

hi have tried recoding to look model like i did the first menu part, but it doesnt display result once done.
where do i include the auc_id so as to make use of it?

Well, I don’t know because I don’t know your tables. Don’t you need to put it in the query to ensure that only the results for that specific auction appear? If you do, copy the line you have to extract the value of “menu” and get it from the parameters you pass in, and add it in to the query.

1 Like
table  auctions
column      id         team1         team2
                 56          2                5
                 72          1                8


table  bids
column         auction     willwin     willlose    bidder

                       56           5               2         23
                       56           2               5         12        
                       56           2               5         19
                       72           1               8         12
                       72           8               1         14

this is example of the table, you see in bidder row theres two 12 that ends up making bidder appears in both data, well u know the rest.

hi morning all still on the issue thanks

Good to hear. How is it coming on?

still not getting the actual result:pensive:
and is there any other way apart from drop menu one can display certain result ?

I thought the point was that you needed this information in a menu, though? You have a first-level menu, and depending on what the user selects in that menu, you then populate the contents of the submenu? Or have I forgotten the original question?

yeap still is, like i select liverpool from menu and it should display users who selected liverpool or i select real maldrid n it shows those who selected real maldrid eg

jacobnini Liver Pool
mikelobi Real maldrid
cyclops Liver Pool
moneymaker Real maldrid
steveable Liver Pool
johnuered Real maldrid

nothing yet same issue damm

Post the latest version of the code.

i simple retun back to the way it was since the changes werent doing anything heres the code again

//MENU TEAM
$query = "SELECT u.id, u.nick, s.team_id, s.teams AS teams1, ss.team_id, ss.teams AS teams2, 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)
        LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
        LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = a.team1)
        LEFT JOIN " . $DBPrefix . "sports ss ON (ss.team_id = a.team2)
        WHERE b.auction = :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" id="menu">' . "\n";
if ($db->numrows() > 0){
        while ($row = $db->fetch())
        {
            $TPL_team_list .= "\t" . '
            <option value="' . $row[''] . '" ' . $selected . '>' . $row[''] . '</option>
            <option value="' . $row['team1'] . '" ' . $selected . '>' . $row['teams1'] . '</option>
            <option value="' . $row['team2'] . '" ' . $selected . '>' . $row['teams2'] . '</option>
            ' . "\n";
        }
        
        $TPL_team_list .= '</select>' . "\n";

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

            ));
    $i++;
}
}



?>
<script type="text/javascript" src="../js/dropdownjquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    
   $("#menu").change(function() {
        $(this).after('<div id="loader"><img src="img/loading.gif" alt="loading subcategory" /></div>');
        $.get('loadsubcat.php?menu=' + $(this).val(), function(data) {
            $("#sub_cat").html(data);
            $('#loader').slideUp(200, function() {
                $(this).remove();
            });
        });    
    });

});
</script>
    </select>

loadsubcat.php

<?php 
include('../config.php');
ini_set('display_errors',0);

$menu = $_GET['menu'];
$query = mysql_query("SELECT a.id, s.team_id, s.teams, u.nick, ut.nick_tag, b.id, b.willwin, b.willlose, b.bidder, b.tagged, b.bid, b.auction FROM vs_bids b 
LEFT JOIN " . $DBPrefix . "vs_users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "vs_users_tag ut ON (ut.id = b.tagged)
LEFT JOIN " . $DBPrefix . "vs_auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "vs_sports s ON (s.team_id = b.willwin)
WHERE willwin='$menu' and b.tagged != '0' order by b.tagged desc");

while($row = mysql_fetch_array($query)) {
    echo "<option value=''></option>";
    echo "<option value='$row[team_id]'>$row[auction]...$row[nick]...$row[bid]...$row[teams]...$row[nick_tag]</option>";
    
}




?>

I must admit I’ve lost track of what the problem is, what is not working the way you want it to. That just seems to be the same code as you posted at the start of the thread, not the code you’ve been trying to get working, so it’s no wonder it doesn’t work any differently.

Can you explain exactly what the problem is please? How does Liverpool and Real Madrid relate to the tables you described in post #5?

oh ok no problem the 5th post shows the two tables where the connection is made those teams are collected from auctions table team1 and team2, the two tables connect with id for auctions table and auction for bids table as u can see for example auction row has 56 showing three times which means bidders 23, 12 and 19 placed a bid on auction(56) .

now with the drop menu it suppose to show those who selected team1 or team2 for auction 56 only, instead it shows those data and sometimes collect data from other rows like might take 1 or two from auction 72 and i notice this happens if a bidder who place a bid on 56 also place a bid on 72 will be shown all over, hope u understand now, thank you.

Right, so that’s why you were needing to pass the auction id into the submenu code. You do this (presuming you also added the div to contain the auction id, so you now need to modify the submenu code to:

  1. Retrieve the auction id. You see how you get the ‘menu’ variable? Do the same, but for the auction ID.
  2. Use the auction id to limit the results in the query.

hmm dont wanna be too demanding can u just do it abit here for me so when i integrate it i know its not coming from me it something else

hi there morning

I’m not sure where you’re struggling - you’ve got some reasonably complex code there, but you can’t add another line to grab the auction id from the parameters? Just copy the line where you get the menu value, and change the names.

Sorry if this comes across as unhelpful, I could see how it might be read that way. But you keep saying you’ve tried loads of things, and I was hoping you’d show what you had tried so that people could suggest what might be wrong. I’m also not sure of how much PHP you know - from the code you’ve written so far it seems you have good knowledge of PHP and SQL, but these are really basic things IMO.

This is the line that gets the menu value:

$menu = $_GET['menu'];

So, can you see how you might duplicate that line to recover the auction id as well?

hi u mean something like this?

$menu = $_GET['menu'];
$auction = $_GET['auction'];
$query = mysql_query("SELECT  a.id, s.team_id, s.teams, u.nick, ut.nick_tag, b.id, b.willwin, b.willlose, b.bidder, b.tagged, b.bid, b.auction FROM vs_bids b 
LEFT JOIN " . $DBPrefix . "vs_users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "vs_users_tag ut ON (ut.id = b.tagged)
LEFT JOIN " . $DBPrefix . "vs_auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "vs_sports s ON (s.team_id = b.willwin)
WHERE willwin='$menu' and auction='$auction' and b.tagged != '0' order by b.tagged desc");

if yeah didnt work