I on my drop down boxes it keeps on selecting more than one option I just want it to select out of one row... for some reason this won't work

nothing shows -

$query["cost1"] = "SELECT ourprice as text, ourprice as value FROM `fruitinventory` WHERE seeddescription='%s' AND fruitdescription='%s'";

Something shows but mulpilte items -

$query["cost1"] = "SELECT ourprice as text, ourprice as value FROM `fruitinventory` WHERE fruitdescription='%s'"; 
Member Avatar for diafol

Are you using sprintf or similar? I don't understand %s otherwise. Could you show your code?

Yes Im using sprintf

here are my drop down boxes -

<p>
    itemnumber<select id='stocknum1' name='stocknum1'>
    </select>
  </p>
  <p>
    Description<select id='description1' name='description1'>
    </select>
  </p>
  <p>
    Cost<select id='cost1' name='cost1'>
    </select>
  </p>
  <p>
    list price<select id='list1' name='list1'>
    </select>
  </p>
  <script>jQuery(function(){db_relational_list([{id:'stocknum1', default_value:'itemnumber'}, {id:'description1', default_value:null}, {id:'cost1', default_value:null}, {id:'list1', default_value:null}], 'dbstuff.php')});</script>

here is dbstuff.php

<?php  $hostname = "localhost"; $database = "dbname"; $username = "dbuser"; $password = "passawiki"; $query = array(); 
$query["stocknum1"] = "SELECT itemnumber as text, itemnumber as value FROM `fruitinventory` WHERE stock > '0' ORDER BY itemnumber ASC"; 
$query["description1"] = "SELECT description as text, description as value FROM `fruitinventory` WHERE itemnumber='%s'"; 
$query["cost1"] = "SELECT ourprice as text, ourprice as value FROM `fruitinventory` WHERE description='%s'"; 
$query["list1"] = "SELECT list as text, list as value FROM `fruitinventory` WHERE ourprice='%s'"; include "db_manager.php"; ?>
Member Avatar for diafol

Sorry, I don't get this. I can't see your sprintf anywhere.
Also why the jQuery? Are you doing ajax?
Can't you use php?

What I'm trying to create is a drop down menu

Fruit number > Fruit description > fruit cost > fruit list price

Pretty much you select your fruit number and then everything else magically appears... Yes there may be a better way of doing this... but Im not sure exactly....

What I get with the code above is... it pulls from the incorrect row.. in other words.. it pulls anything from fruit cost that is = to anything in the column... then it will display all same options in fruit list when it should only be displaying from the row of fruit number

Member Avatar for diafol

I'm afraid this doesn't make sense to pull data out of the tables as you seem to be in the dbstuff page. You're pulling data from the same row, so why do you need a separate dropdown? Confused.

Whats a better way of doing it then? I'm always open to suggestions.. I may not use the suggestion but I will glady listen to ideas..

What would make more sense?

Member Avatar for diafol

If I could understand what you are trying to do, I'd suggest something.
I'm struggling.

$query["stocknum1"] = "SELECT itemnumber as text, itemnumber as value FROM `fruitinventory` WHERE stock > '0' ORDER BY itemnumber ASC"; 
$query["description1"] = "SELECT description as text, description as value FROM `fruitinventory` WHERE itemnumber='%s'";

I'm thinking that you want the selected value in the first query to return all records with hat itemnumber (selected value) and place them in the second dropdown. This in itself is a bit odd as all (i'm assuming) the relationship will be 1:1.

And so on for the other two dropdowns. It's all the same row of data from what I can see.

for the last two or even second one I wouldn't be able to change the value. The values are being submited into a database

$query["description1"] = "SELECT description as text, description as value FROM `fruitinventory` WHERE itemnumber='%s'";


$query["description1"] = "SELECT description as text, description as value FROM `fruitinventory` WHERE itemnumber='%s'";

i was thinking  -

something along the lines of

$query["description1"] = "SELECT description as text, description as value FROM `fruitinventory` WHERE itemnumber='%s' AND fruitdescription=itemnumber ????";
Member Avatar for diafol

Anybody else?

I found out what I was doing incorrectly.. I just forgot a few apostrophes. But I also need to completely redo my java too.

> $query["description1"] = "SELECT description as text, description as value FROM `fruitinventory` WHERE itemnumber='%s'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.