Submenu issue

i was able to convert the menu from mysql to mysqli

it now looks like this

$query = "SELECT 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 . "sports s ON (s.team_id = a.team1)
        LEFT JOIN " . $DBPrefix . "sports ss ON (ss.team_id = a.team2)
        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);
?>

<form name="bid">
    <label for="category">Select Winner</label>
    <select name="willwin" id="menu">
    
    <?php
if ($db->numrows() > 0){
        while ($row = $db->fetch()) { ?>
        <option value=''></option>
        <option value="<?php echo $row["team1"]; ?>"><?php echo $row["teams1"]; ?></option>
        <option value="<?php echo $row["team2"]; ?>"><?php echo $row["teams2"]; ?></option>
        <?php 
}
}
?>

But the submenu isnt budging i had to return it to it original state to be able to connect to it but it isnt perfect

</select>
    <br/><br/><br/>
  
    <label>Tag Bettor</label>
    <select name="sub_cat" id="sub_cat"></select>
    
<?php 

$menu = $_GET['menu'];
$query = mysql_query("SELECT a.id, a.team1, a.title, a.team2, s.team_id, s.teams, u.nick, b.id, b.willwin, b.willlose, b.bidder FROM vs_bids b 
LEFT JOIN " . $DBPrefix . "vs_users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "vs_auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "vs_sports s ON (s.team_id = b.willwin)
WHERE b.willlose = {$menu} and a.id = b.auction and b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder')");

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

i have changed

while($row = mysql_fetch_array($query))

to

while ($row = $db->fetch())

changed

$query = mysql_query

to

$query =

added

$params = array();
        $params[] = array(':auc_id', $id, 'int');
        $db->query($query, $params);

yet noting

Can you explain this a bit more? I don’t really know what you mean. I thought the submenu only appeared when you had selected something in the first menu, using that Ajax code that was working a couple of days ago.

You need to show the second piece of code after you’ve made the changes you described, not before. In particular I can’t see the point of calling the second query using the :auc_id parameter, as that doesn’t appear anywhere in the query. You’d be better off putting a parameter in instead of merging the $menu variable.

yeah it works but not perfect, yeah it only appears when i select a menu, am trying to convert so i can make use of the :auc_id because the vs_auctions a ON (a.id = b.auction) is working well, it shows data from another table wiith the team name.

this is the code i changed but doesnt work

<?php 
$menu = $_GET['menu'];
$query = "SELECT a.id, a.team1, a.title, a.team2, s.team_id, s.teams, u.nick, b.id, b.auction, b.willwin, b.willlose, b.bidder FROM bids b 
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = b.willwin)
WHERE b.willlose = {$menu} and a.id = auc_id and b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder')";
$params = array();
        $params[] = array(':auc_id', $id, 'int');
        $db->query($query, $params)
while ($row = $db->fetch()) {
    echo "<option value=''></option>";
    echo "<option value='$row[team_id]'>$row[nick]...$row[teams]</option>";
}
?>

heres the full code

$query = "SELECT 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 . "sports s ON (s.team_id = a.team1)
        LEFT JOIN " . $DBPrefix . "sports ss ON (ss.team_id = a.team2)
        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);
?>

<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>');
        $.get('loadsubcat.php?menu=' + $(this).val(), function(data) {
            $("#sub_cat").html(data);
            $('#loader').slideUp(200, function() {
                $(this).remove();
            });
        });    
    });

});
</script>
<form name="bid">
    <label for="category">Select Winner</label>
    <select name="willwin" id="menu">
    
    <?php
if ($db->numrows() > 0){
        while ($row = $db->fetch()) { ?>
        <option value=''></option>
        <option value="<?php echo $row["team1"]; ?>"><?php echo $row["teams1"]; ?></option>
        <option value="<?php echo $row["team2"]; ?>"><?php echo $row["teams2"]; ?></option>
        <?php 
}
}
?>
    </select>
    <br/><br/><br/>
  
    <label>Tag Bettor</label>
    <select name="sub_cat" id="sub_cat"></select>
    
    
    
</form>

the one below is in loadsubcat.php

<?php 
include('config.php');

$menu = $_GET['menu'];
$query = mysql_query("SELECT a.id, a.team1, a.title, a.team2, s.team_id, s.teams, u.nick, b.id, b.auction, b.willwin, b.willlose, b.bidder FROM vs_bids b 
LEFT JOIN " . $DBPrefix . "vs_users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "vs_auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "vs_sports s ON (s.team_id = b.willwin)
WHERE b.willlose = {$menu} and a.id = b.auction and b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder')");

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

hi what needs to change?

WHERE b.willlose = {$menu} and a.id = auc_id and b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder')";

You haven’t preceded the auc_id token with a colon - compare it to the same entry in the query that does work with the parameters array and you’ll see what I mean. Once that works, you then need to do the same for {menu} - add a token in the query, and another entry in the $params array for the value.

plz how do i go about that

u mean like this?

$menu = $_GET['menu'];
$query = "SELECT a.id, a.team1, a.title, a.team2, s.team_id, s.teams, u.nick, b.id, b.willwin, b.willlose, b.bidder, b.auction FROM bids b 
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = b.willwin)
WHERE b.willlose = :menu and a.id = :auc_id and b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder')";
$params = array();
        $params[] = array(':auc_id', $id, 'int');
        $params[] = array(':menu', $menu, 'int');
        $db->query($query, $params);
        
while ($row = $db->fetch()) {
    echo "<option value=''></option>";
    echo "<option value='$row[team_id]'>$row[nick]...$row[teams]</option>";
}

That’s the kind of thing. Does it work?

Might need to look at the quotes in these array references:

echo "<option value='$row[team_id]'>$row[nick]...$row[teams]</option>";

though it might be OK. I think I’ve read they’re optional inside a quoted string.

nope it didnt

In what way did it not work? Did the query return anything?

Where are you getting the value of $id from?

auctions table a.id

i put the full code on page here it is please check tru for me if u think u can see the problem maybe cause it on a page now or something

$query = "SELECT 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 . "sports s ON (s.team_id = a.team1)
        LEFT JOIN " . $DBPrefix . "sports ss ON (ss.team_id = a.team2)
        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);
?>

<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>');
        $.get('bid.php?menu=' + $(this).val(), function(data) {
            $("#sub_cat").html(data);
            $('#loader').slideUp(200, function() {
                $(this).remove();
            });
        });    
    });

});
</script>
<form name="bid">
    <label for="category">Select Winner</label>
    <select name="willwin" id="menu">
    
    <?php
if ($db->numrows() > 0){
        while ($row = $db->fetch()) { ?>
        <option value=''></option>
        <option value="<?php echo $row["team1"]; ?>"><?php echo $row["teams1"]; ?></option>
        <option value="<?php echo $row["team2"]; ?>"><?php echo $row["teams2"]; ?></option>
        <?php 
}
}
?>
    </select>
    <br/><br/><br/>
  
    <label>Tag Bettor</label>
    <select name="sub_cat" id="sub_cat"></select>
    
    
    <?php 


$query = "SELECT a.id, a.team1, a.title, a.team2, s.team_id, s.teams, u.nick, b.id, b.willwin, b.willlose, b.bidder, b.auction FROM bids b 
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = b.willwin)
WHERE b.willlose = :menu and a.id = :auc_id and b.bidder NOT IN ('b.tagged') and b.tagged IN ('b.bidder')";
$params = array();
        $params[] = array(':auc_id', $id, 'int');
        $params[] = array(':menu', $menu, 'int');
        $db->query($query, $params);
        
while ($row = $db->fetch()) {
    echo "<option value=''></option>";
    echo "<option value='$row[team_id]'>$row[nick]...$row[teams]</option>";
}
?>
</form>


and thanks alot for all ur assist

I just don’t see where the value of $id comes from in that code. Or $menu for that matter.

You also don’t close the <select> for the second drop-down. And is it correct that, for every row you retrieve from the second query, you create blank option and an option containing the team details?

That can’t be all the code, surely? Where do you connect to the database? Does that code set those variable values?

generally the code works but it has a bug where the submenu keeps displaying other bids from other auctions, this is suppose to correct that issue a.id = :auc_id the value is there, this is just a fragment of its own code, every other codes has what they are doing all connecting to a config and datacheck file.

the code personally works with the menu mysqli and the submenu mysql in another page, but like i said the submenu keeps displaying datas from another column because of the missing a.id = :auc_id thats y am trying to convert it and fix that

but right now i just get blank return nothing else

so what u think

hi, i still havent resolved the issue, i even tried another dropwmenu, same issue also

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.