Page 1 of 2

Multiple values for <option> tag

Posted: Tue Aug 12, 2003 4:57 pm
by kanshou
I am just trying to figure out how to pass mutiple values in an option tag i.e.

Code: Select all

<option value="value1&value2">

or something like that. I want to pass them both through the same option and not 2 seperate ones. Is there any way to do this?

Thanks
Kanshou

Posted: Tue Aug 12, 2003 5:06 pm
by qartis
Can you be tricky, and do something like "value1|||value2", and then explode it by "|||" on the next page?

Posted: Tue Aug 12, 2003 5:09 pm
by kanshou
One other question...
I have a link that is being generated that looks like:

Code: Select all

http://www.myurl.com/myprogram/main.php?menuAction=htmlMyDCL.show?id=6&DPN_row_num=0"
and I need to figure out how to get the 2nd query string to tack on to the first one. I have tried to do it with the ? and the & character, but neither one has worked. All they do is generate an error or show the same page after I click it.
Any ideas would be greately appreciated!
Thanks!

Posted: Tue Aug 12, 2003 5:16 pm
by qartis
Try ";"

EDIT: Without quotes.. :)

Posted: Tue Aug 12, 2003 5:44 pm
by kanshou
Ok, now a little more specific

Code: Select all

&lt;option value="value1-value2"&gt;blah

Code: Select all

<?php
$GLOBALS['which'] = explode("-", $GLOBALS['which']);

switch ($GLOBALS['which'])
     case "value1":
if blah blah blah

     case "value2":
if blah blah blah

?>
Now heres the problem. Value 1 and value 2 are both table definitions for mySql, and I need both value 1 and value 2 in the same case, but I don't know how to pull that from the explode.

Posted: Tue Aug 12, 2003 5:46 pm
by kanshou
qartis wrote:Try ";"

EDIT: Without quotes.. :)
that didn't work either... I got a parse error

Posted: Tue Aug 12, 2003 6:03 pm
by qartis
Now heres the problem. Value 1 and value 2 are both table definitions for mySql, and I need both value 1 and value 2 in the same case, but I don't know how to pull that from the explode.
So, let's pretend you have the value "username-password", and you want to retreive "username" and "password" separately, to reference them as table names? Try this code:

Code: Select all

$string = "username-password";
$array = explode("-",$string);

// Now we've got $array[0], which equals "username", and $array[1], which equals "password".

Posted: Tue Aug 12, 2003 6:27 pm
by kanshou
Right, I have that already, but the problem isn't really that anymore. The problem is the switch statement in the prior post. I need both values to be accounted for in the fist case because whatever $GLOBALS['which'] is, becomes a table query. so I need both value1 and value2 to appear be in the same case argument, AND they also have to function properly in a mysql query statement. That is my real question.

Posted: Tue Aug 12, 2003 9:30 pm
by JAM
Dunno if I got to understand it correctly either, but...

Code: Select all

<?php
// <option> is username-password and send from a form...
// put them in array...
$foo = explode("-", $_POST['which']); 
// use the two to get selections...
$clause = " username = '$foo[0]' and password = '$foo[1]'";
// add it to a query...
$queryexample = 'select * from users'.$clause;

// merge the two, and test the statement...
switch ($foo[0].$foo[1]) {
     case "usernamepassword": 
// code
//...
}
?>

Posted: Tue Aug 12, 2003 11:57 pm
by kanshou
Well, thats getting closer to what I'm lookin for. let me specify a little better what I have... and I'll try to explain it a little better.

Code: Select all

&lt;select name="which"&gt;&lt;option value="workorders-timecards"&gt;both&lt;/option&gt;&lt;/select&gt;

Code: Select all

<?php
$passedVars = explode("-", $GLOBALS['which']); 
// gets variables and puts them into an array.
$storedVars = $passedVars[0] ."AND". $passedVars[1];
// gets vars from array and puts them into a db compatible form.
print($storedVars); // This is for Error Checking only
$this->oView->table = $storedVars;
   switch($passedVars[0].$passedVars[1])
     {
       case 'workorderstimecards':
         //code to execute
     }

?>
Now the problem is, when I try to execute it, I get "error" as the error message, or messing with it in other ways I get "unknown table workorders AND timecards". I need the query to look in both the tables workorders and timecards.

I can get it to do one at a time by making them both individual options and setting a case for each... and making the table call

Code: Select all

$this-&gt;oView-&gt;table = $GLOBALS&#1111;'which'];
but I can't get them to work at the same time.

Posted: Wed Aug 13, 2003 12:08 am
by qartis
Why don't you just use:

Code: Select all

&lt;option value="1"&gt;Work Orders&lt;/option&gt;
&lt;option value="2"&gt;Time Cards&lt;/option&gt;
&lt;option value="3"&gt;Both&lt;/option&gt;

And then to parse it..

Code: Select all

<?
//$var is 1, 2 or 3

switch ($var){
    case 1:
        //They selected "Work orders"
        break;
    case 2:
        //They selected "Time Cards"
        break;
    case 3:
        //They selected "Both"
        break;
    default:
        //They didn't select anything
}
?>

Posted: Wed Aug 13, 2003 12:29 am
by kanshou
umm...When I think of a good answer as to why I didn't do it that way, I'll tell ya. Until then, I got it to sorta work, now the problem is that I am getting a sql syntax error in one of the calls.. and I'm not quite sure as to what the problem is, but its doing half of what I wanted, which is better than where I was a few hours ago. Thanks for the help, and I might be back later ^_^

Posted: Wed Aug 13, 2003 5:47 pm
by kanshou
I need to know one more thing.
in a sql query I am trying to call more than one table, I have a function that is something like this

Code: Select all

<?php
function searchWorkorders()
{
$this->oView->table = 'workorders';
//code
}

function searchTimecards()
{
$this->oView->table .= 'timecards';
//code
}
?>
What do I need to put before the 'timecards' to make it query that table as well as the workorders table. I have tried 'AND timecards', and ',timecards'. Neither of these worked. Any other ideas.
Thanks

Posted: Wed Aug 13, 2003 6:26 pm
by qartis
Multi-table queries are structured like this:

Code: Select all

SELECT a.foo1, b.bar FROM `table1` as a, `table2` as b WHERE a.feild = b.feild2 AND b.feild3 = 'value'
With limits, orders and groupings following that. Basically, you're calling table1 'a', and table2 'b', and then referencing them via table.feild.


If you wanted to retreive a username based on a user id from the table "user_data", AND retreive an email address from "user_details" with that username, you would use..

Code: Select all

SELECT a.username, b.email_address FROM user_info as a, user_details as b WHERE a.user_id = '$id' AND a.username = b.username LIMIT 1

Posted: Wed Aug 13, 2003 7:21 pm
by kanshou
is it possible to do something like

Code: Select all

<?php
function blah()
{
$this->table = 'workorders, timecards';
$this->addDef('filterlike', 'workorders.id', $seachText);
$this->addDef('filterlike', 'timecards.id', $seachText);
}

?>
and have it query from each table like that. because as it stands right now I'm getting an "unknown table timecards" error.