Still submenu issue

Am able to use this code to bind a.id = :auc_id in order to display certain result needed for menu code, but when i introduce it in the submenu i dont get any result below are the codes for menu and submenu’

MENU works fine, display whats need to be showned thanks to a.id = :auc_id

$query = "SELECT s.team_id, s.teams AS teams1, ss.team_id, ss.teams AS teams2, a.id, a.team1, a.team2 FROM " . $DBPrefix . "auctions a
        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";
        $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 
}
}
?>

SUBMENU displays all the details in

bid table
column                     auction    bidder    willwin    willlose
                               38........ 4............3......... 2
                               39.........4............2......... 4
                               39........5............4......... 2

the result should have a display for column ((auction) 38)  willwin (3) but instead i get 3,2,4
<?php 
include('config.php');

$menu = $_GET['menu'];
$query = mysql_query("SELECT a.id, 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 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>";
}
?>

i cant seem to introduce b.auction = :auc_id which will help in displaying the correct result, but have converted it like the menu above but doesnt seem to work, so i converted it back.
please need help with the issue here, thanks.

Does the code you converted back to, work as you want it to? If it does, please show the code you tried to get working. Specifically, show how you pass the value of the id from the main code to the separate script that generates the submenu contents. If you get it from the $_GET array, are you remembering to add it into the javascript that calls that code?

hi thanks for replying, yeah it works below is the code for menu which displays the right result

$query = "SELECT s.team_id, s.teams AS teams1, ss.team_id, ss.teams AS teams2, a.id, a.team1, a.team2 FROM " . $DBPrefix . "auctions a
        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";
        $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>

now this is the SUBMENU code which also works but displays all the result in the willwin column instead of rows that are connected via AUCTIONS(id) and BIDS(auction) like in the menu code, ordinary this is suppose to do that…b.auction = :auc_id… for the submenu but it doesnt work when i introduce it.

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

$menu = $_GET['menu'];
$query = mysql_query("SELECT a.id, 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 willlose='$menu'");

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

i even have a pdo version and it has the same issue

<?php
include('dbconfig.php');
if($_POST['id'])
{
    $id=$_POST['id'];
        
    $stmt = $DB_con->prepare("SELECT a.id, s.team_id, s.teams, u.nick, b.id, b.willwin, b.willlose, b.bidder, b.auction 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 willlose=:id");
    
    $stmt->bindParam(':id', $id);
    $stmt->execute();
    ?><option selected="selected">Select State :</option><?php
    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        ?>
        <option value="<?php echo $row['team_id']; ?>"><?php echo $row['nick']; ?> <?php echo $row['teams']; ?></option>
        <?php
    }
}
?>

What I meant was, can you show the code where you’ve added in the auction-id to the submenu query? All I see there is that you’re looking at the value of willwin, neither submenu query does anything with the auction id.

As I see it, you need to:

  • Modify the Ajax code in the main script to pass the auction id as well as the selection from the main menu
  • Modify the submenu code to extract the auction id, and add it to the query.

hi i dont know how to go about the modifying ajax code not a clue how to start non end below are the mysql code and pdo codes (submenu with the auction-id added

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

$menu = $_GET['menu'];
$query = mysql_query("SELECT a.id, 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 willlose='$menu' and b.auction = auc_id");

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

and pdo

<?php
include('dbconfig.php');
if($_POST['id'])
{
    $id=$_POST['id'];
        
    $stmt = $DB_con->prepare("SELECT a.id, s.team_id, s.teams, u.nick, b.id, b.willwin, b.willlose, b.bidder, b.auction 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 willlose=:id and b.auction = :auc_id");
    
    $stmt->bindParam(':auc_id', $id);
    $stmt->bindParam(':id', $id);
    $stmt->execute();
    ?><option selected="selected">Select State :</option><?php
    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        ?>
        <option value="<?php echo $row['team_id']; ?>"><?php echo $row['nick']; ?> <?php echo $row['teams']; ?></option>
        <?php
    }
}
?>

OK, well at least that tells you why it’s not working properly. Looking at the PDO code, you’re using the same $id value for both the willlose column, and the auction_id column - is that correct? You also seem to have changed to $_POST, and changed the parameter name from menu to id - did you change the calling code to work that way as well? If not, your PDO code just won’t work as the $_POST array is empty.

And looking at the first code using the old MySQL functions, you just don’t seem to have anything for auc_id, so maybe it’s not surprising that doesn’t work. So, forget about that version and concentrate on the PDO code.

In this section of the code, which calls your other script:

 $.get('loadsubcat.php?menu=' + $(this).val(), function(data) {

you pass in the value of the main menu selection, as a parameter called “menu”. So what you need to do is add some code to pass the auction id as well, extract it in loadsubcat.php, and use it in the query.

One easy way to do that might be to have the auction id in a div that you style to be hidden. There’s a better way to do it, and it came up in a fairly recent post about sending multiple values via Ajax, but I can’t find it now. So perhaps in the main code, you’d add a line something like

echo '<div id="auctionid">' . $id . '</div>';

which will create a page element called ‘auctionid’ and stick the value you need in there. In your Ajax, you need to get that value out somehow, so instead of

 $.get('loadsubcat.php?menu=' + $(this).val(), function(data) {

you’d have something like

var auction = $("#auctionid").text();  
 $.get('loadsubcat.php?menu=' + $(this).val() + "&auc=" + auction, function(data) {

so you’re now passing two parameters in the $_GET array, menu and auc, so change the loadsubcat routine to extract those, and use them in the query.

Obviously you’d need to style the div to not show the auction id, or use an alternate method of extracting the second parameter. For your JS to work, the value needs to be somewhere in the page code so it can be accessed and sent across.

hi tried the mysql own didnt work displaying same result, since u said i should drop that one heres the one am using for pdo, it works just like the mysql but same problem with the submenu

<?php
include_once 'dbconfig.php';
?>

<script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
    $(".country").change(function()
    {
        var menu=$(this).val();
        var dataString = 'menu='+ menu;
    
        $.ajax
        ({
            type: "POST",
            url: "get_state.php",
            data: dataString,
            cache: false,
            success: function(html)
            {
                $(".state").html(html);
            } 
        });
    });
    

    
});


<div>
<label>Country :</label> 
<select name="country" class="country">
<option selected="selected">--Select Country--</option>
<?php
    $stmt = $DB_con->prepare("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
    ");
    $stmt->bindParam(':auc_id', $id);
    $stmt->execute();
    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        ?>
        <option value="<?php echo $row['team1']; ?>"><?php echo $row['teams1']; ?></option>
        <option value="<?php echo $row['team2']; ?>"><?php echo $row['teams2']; ?></option>
        <?php
    } 
?>
</select>

<label>State :</label> <select name="state" class="state">
<option selected="selected">--Select State--</option>
</select>
</div>

And heres the submenu code in the get_state.php

<?php
include('dbconfig.php');
if($_POST['menu'])
{
    $menu=$_POST['menu'];
        
    $stmt = $DB_con->prepare("SELECT a.id, s.team_id, s.teams, u.nick, b.id, b.willwin, b.willlose, b.bidder, b.auction 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 willlose=:menu");
    
    $stmt->bindParam(':menu', $menu);
    $stmt->execute();
    ?><option selected="selected">Select State :</option><?php
    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        ?>
        <option value="<?php echo $row['team_id']; ?>"><?php echo $row['nick']; ?> <?php echo $row['teams']; ?></option>
        <?php
    }
}
?>

and i just want to show u this

// tag user name n team
$query = "SELECT b.*, s.team_id, s.teams, u.nick, u.rate_sum FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.bidder)
LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = b.willwin)
WHERE b.auction = :auc_id ";
$params = array();
$params[] = array(':auc_id', $id, 'int');
$db->query($query, $params);

that i use as a standalone user name n team result which display the exact result, sorry for taken ur time, i just cant seem to make it work for the above submenu

But you haven’t done any of the stuff I talked about to pass the second parameter into the code that produces the submenu? If you don’t pass the auction id as a second parameter, how will that code know what you use?

I must admit I’m getting quite confused - you change from mysql to PDO, but also change the calling method and variable names. I thought it was an auction site, but now we’ve got teams and states to contend with, and I’m losing track of exactly what code is where.

My guess would be that you need to add the div that I talked about, so you have the value of the auction id somewhere in the html. Then in your calling ajax code, instead of these lines

var menu=$(this).val();
var dataString = 'menu='+ menu;

you would need to have

var menu=$(this).val();
var auction = $("auctionid").text();  // get the auction id from the div you added with this id
var dataString = 'menu='+ menu + "&auction" + auction;

Then in your get_state.php code, add

$menu=$_POST['menu'];
$auction = $_POST['auction'];

and then add that value into your query.

hi the state.php i didnt change i just started working on the pdo but when realise am getting the same result didnt really bother, i implemented what u gave me am still getting same result. (sigh)

it still showing all the datas i upload images to see what am talking about

Images are good, but need to see the code exactly as it is now.

I think what you need to do is break it down into steps. In get_state or whatever code you call to populate the submenu, drop everything and first concentrate on passing the two parameters that you need for the query. So just extract them from the $_POST array, echo them, and add an alert() in your Ajax calling code to display them. Once that is working, you can build back up to adding the query.

still nothing i just keep getting all d result on the row, was even trying a back up plan and hit another road block there

the code below

<div class="form-group">
                        <label class="col-sm-5 control-label">Select Winner</label>
                        <div class="col-sm-7">
                    <select name="willwin" id="first">
      <option value='1'>{TEAM1}</option>
      <option value='2'>{TEAM2}</option>
</select>
<select name="willlose" id="first_selected">
                    </div>
                    </div>
                <script type="text/javascript">
                    $(document).ready(function() {
    var dropdown1 = {
        1 : ['{TEAM2}'],
        2 : ['{TEAM1}']
    }
    $('#first_selected').html(
            '<option>'+dropdown1[1].join('</option><option>')+'</option>'
        );
    $('#first').on('change',function() {
        $('#first_selected').html(
            '<option>'+dropdown1[$(this).val()].join('</option><option>')+'</option>'
             );     }); });
     </script>    

when ever i submit the form the value get inserted but the value that insert are the numbers <option value='2'> and <option value='3'> instead of what beside them, it a swap code and those values is what been used by the javascript to swap if only the codes could be change to make the javascript use something else instead of val to swap, hope u understand

Oh, another totally different piece of code. I don’t understand why you keep chopping and changing rather than just picking one method and sticking with it. I don’t see anything above that even tries to call the other script to populate the submenu, but maybe I’m just not reading it properly.

Well, that’s exactly correct - the point of the value="x" part of the option tag is to allow you to use a value for submission that isn’t the same as the value you display. So in your case, you’d set the value to the team id or bidder id or state id or whatever we’re doing, but you’d display the team name or bidder name. Sometimes they’re the same, often they’re not. So if you don’t want ‘1’ or ‘2’ in the value that you submit, you need to change it to whatever you do need. I thought your old code had the correct values in it?

I say again, as I see it the only problem with the original code was that you weren’t passing the auction id and the menu / bidder id to the script that generates the submenu, and I gave an example of how to do that.

u mean 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);
?>

<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 = $("#auctionid").text();  
 $.get('loadsubcat.php?menu=' + $(this).val() + "&auc=" + auction, 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>
<?php 
include('config.php');

$menu = $_GET['menu'];
$query = "SELECT a.id, s.team_id, s.teams, u.nick, b.id, b.willwin, b.willlose, b.bidder, b.auction 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 willlose='$menu'";

while ($row = $db->fetch()) {
    echo "<option value=''></option>";
    echo "<option value='$row[team_id]'>$row[auction]...$row[nick]...$row[teams]</option>";
    echo '<div id="auctionid">' . $id . '</div>';
    
}
?>

?

that would have work but these

var dropdown1 = {
        1 : ['{TEAM2}'],
        2 : ['{TEAM1}']
    }

the numbers cant be changed automatically, cause what ever its gonna make the changes is in text form

but th funny thing is notice is the second line is summited without issue but the first one what ever goes into willwin submit the value which is a number

Kind of, but in that code:

  • You don’t show the div where you actually output the auctioned value. Without that, you’ll get a null
  • In the submenu code, you don’t retrieve the value of auc from the parameters. You get menu, but not auc.

sorry but showing div how? how can i do that

That’s because of this

                    <select name="willwin" id="first">
      <option value='1'>{TEAM1}</option>
      <option value='2'>{TEAM2}</option>

Because you specify the values as numbers, that’s what you get when submitted. In the lower code, you don’t specify a value, so it submits whatever is between the <option> and </option> tags. Read up on the basic html for more information on that.