Dynamic Conditions in PHP form
Moderator: General Moderators
Dynamic Conditions in PHP form
I have this:
SELECT $items FROM $table WHERE $conditions
in my form I'm asking the user to select items from a list - multible selections
and I'm asking the user to select from which table he/she would like to extract the data
now my problem with the conditions selection !
I'm going to divide this problem to smaller ones and solve each one then relate it to the other
I've already created a list that have all the fields available (user can only select one item)
and I've already created a list with the values (multible selection is available)
example:
item1 is being chose___user can choose the relation(In/Not In..etc)___list of unique values of item1
should i use java to remember the first selection then i can use this selection in my second list sql so i can get the values that are related to this selection ?
do you know any java script that will save selection then read it later and use it as a variable in my second sql ?
SELECT $items FROM $table WHERE $conditions
in my form I'm asking the user to select items from a list - multible selections
and I'm asking the user to select from which table he/she would like to extract the data
now my problem with the conditions selection !
I'm going to divide this problem to smaller ones and solve each one then relate it to the other
I've already created a list that have all the fields available (user can only select one item)
and I've already created a list with the values (multible selection is available)
example:
item1 is being chose___user can choose the relation(In/Not In..etc)___list of unique values of item1
should i use java to remember the first selection then i can use this selection in my second list sql so i can get the values that are related to this selection ?
do you know any java script that will save selection then read it later and use it as a variable in my second sql ?
feyd | Please use
the problem is
when i choose item2 in the first list
values of item2 appear in the second list
then
when i select few values from second list
and select a new field in first list ( let's say item5 )
form is submitted ! I get as an output
list1 = item 5
list2 = values of item2
what i need is the match to appear.. item 2 with its values
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
There's something I don't understand here !
in order in use $_POST, you need to submit the form, right ?
look at this:Code: Select all
<?
$firstQry = mysql_query("SHOW FIELDS FROM table1") or die(mysql_error()); // table 1
?>
<form name="check" method="post">
<select name="first" onchange="this.form.submit()">
<?
while($res = mysql_fetch_row($firstQry))
{?>
<option value="<? echo $res[0]?>"><? echo $res[0]?></option>
<? }
unset($firstQry,$res);?>
</select>
<? if(isset($_POST["first"]))
{
$sql2 = "Select ".$_POST['first']." FROM table1 GROUP BY ".$_POST['first'];
$secondQry = mysql_query($sql2) or die(mysql_error());
?> <select size="3" multiple name="second[]">
<? while($row = mysql_fetch_row($secondQry)){?>
<option value="<? echo $row[0]?>"><? echo $row[0]?></option>
<? }
} unset($secondQry,$row);?>
</select>
</form>
<?
echo "<br/>";
echo "first: ".$_POST['first'];
echo "<br/>";
echo "second: ".implode($_POST['second'],",");when i choose item2 in the first list
values of item2 appear in the second list
then
when i select few values from second list
and select a new field in first list ( let's say item5 )
form is submitted ! I get as an output
list1 = item 5
list2 = values of item2
what i need is the match to appear.. item 2 with its values
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]okay let me forget for now doing the dependent lists
first this is what i'm planning to have
http://img76.imageshack.us/my.php?image=criteriafz2.jpg
I'm wondering how can i by a click have a new criteria line
then all criteria lines should be saved to thier variables ! so i can use them later inside a sql query statement after the word "WHERE"
do i have to use java script ! .. or do i have to use php functions ! or multiple forms submitions !! ..
first this is what i'm planning to have
http://img76.imageshack.us/my.php?image=criteriafz2.jpg
I'm wondering how can i by a click have a new criteria line
then all criteria lines should be saved to thier variables ! so i can use them later inside a sql query statement after the word "WHERE"
do i have to use java script ! .. or do i have to use php functions ! or multiple forms submitions !! ..
feyd | Please use
when i click on the button.. nothing appear !
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
what do you think of this code? - it's not working what's wrong with it !Code: Select all
<script type="text/javascript">
function Show(e)
{
if(document.getElementById(e).style.display == 'none')
{
document.getElementById(e).style.display = 'block';
}
}
</script>
<tr id='criteria1'>
<?echo CriteriaRow();?>
//this function have some form elements/html similar to the picture in one of my posts
</tr>
<input type="button" value="Display Criteria" onClick="Show('criteria1');">Code: Select all
#criteria1
{
display: none;
}
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Your problem is checking if the display attribute is equal to 'none.' JavaScript and CSS cannot communicate with each other, so as far as JavaScript s concerned, style.display is an empty value. Try this instead:coool wrote:Code: Select all
if(document.getElementById(e).style.display == 'none') { document.getElementById(e).style.display = 'block'; }
Code: Select all
var elem = document.getElementById(id);
if(elem.style.display != 'block')
{
elem.style.display = 'block';
}