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 ! (CRITERIA)
here's an image of what I'm looking for: http://img76.imageshack.us/my.php?image=criteriafz2.jpg 18 3128
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 !! ..
Heya, coool.
To actually create the inputs, you'll need to use JavaScript.
But if you name them criteria[], field[], etc., then PHP will automatically create arrays so that you don't have to keep track of individual variable names.
For more information, check out this page: http://php.net/manual/en/language.va....php#id2536797
well, I've tried the technique of hidden elements
because I only want 10 criteria rows
so I displayed one.. and make 9 rows hidden using CSS
now when user click on "ADD CRITERIA ROW"
there should be a javascript function that change the element to display
my problem now with this javascript function :(
i'm using <tr> not <div> ----- becuase with <div> i couldn't hide using css - i don't know why !
so do you have any javascript function that change <tr> to show !
CSS works on <tr> and <div>. Changing the class of a <tr> or <div> with JavaScript is done the same way. - element.className = 'foo';
Heya coool.
Check this out: -
<form id="thePfhorm" ...>
-
</form>
-
-
<div id="dolly" style="display:none">
-
<input name="criteria[]" ... />
-
.
-
.
-
.
-
<input type="button" value="Remove" onclick="this.parentNode.parentNode.removeChild(this.parentNode);" />
-
</div>
-
-
<input type="button" value="Add" onclick="addInput();" />
-
-
<script type="text/javascript">
-
// <![CDATA[
-
// Add the first set of inputs.
-
addInput();
-
// ]]>
-
</script>
-
-
function addInput()
-
{
-
var $newElement = document.getElementById('dolly').cloneNode(true);
-
$newElement.id = '';
-
$newElement.style.display = '';
-
-
document.getElementById('thePfhorm').appendChild($newElement);
-
}
-
Instead of creating all the inputs up front (which clutters up your form values when submitting and limits the total number of inputs), you instead can clone a template and dynamically create exactly as many or as few as you need.
what do you think of this code? - it's not working what's wrong with it ! -
<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');">
-
-
#criteria1
-
{
-
display: none;
-
}
-
when i click on the button.. nothing appear !
Heya, coool.
Try removing the conditional from your Show() function.
P.S. instead of using '<?', consider using '<?php', as that will make your code more portable. "Short tags", as they are called, have been deprecated; not all servers recognize them, and they will be removed from PHP in a future release.
You are really SMART
It's WORKING
I feel I wonna CRY ...... THAAAAAAAAANKS VeRy MuCh :)
Heya, coool.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
oh I've a little question..
why the if statement didn't work ! .. I really need to use it
because I'm going to hide 9 <tr>s
and with every click I need to show one of them
------
I tried this code.. and i know it's wrong ! ..
[html]
<tr id='row2'>
<?php echo newRow(); ?>
</tr>
<tr id='row3'>
<?php echo newRow(); ?>
</tr>
<tr id='row4'>
<?php echo newRow(); ?>
</tr>
<input type="button" value="Add Row" onClick="Show('row');">
[/html]
[php]
<script>
function Show(e)
{
var i;
i = 2;
while(document.getElementById(e+i).style.display != 'none')
{
document.getElementById(e+i).style.display = 'block';
else if(document.getElementById(e+i).style.display == 'block')
i++;
}
}
</script>
[/php]
Heya, coool.
The display property of a visible element is not always 'block', but it will always be 'none' for an invisible element.
But in reality, if you know that the element is supposed to end up with a display of 'block', it does no harm to set it anyway, even if that element is already visible.
Consider: -
function Show(e)
-
{
-
var i = 2;
-
while(var element = document.getElementById(e+i))
-
{
-
element.style.display = 'block';
-
++i;
-
}
-
}
-
Thanks for your help :)
things are working just as i want :D
Heya, coool.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
pbmods,
Thanks for that excellent script, just wanted to add though, there were two bits with extra spaces in it that stopped it working, drove me nuts before checking with the javascript console!!
Here's a working version below for anyone else who comes across this: -
<html>
-
<head>
-
<script type="text/javascript">
-
function addInput(){
-
var $newElement = document.getElementById('dolly').cloneNode(true);
-
$newElement.id = '';
-
$newElement.style.display = '';
-
document.getElementById('thePfhorm').appendChild($newElement);
-
}
-
</script>
-
</head>
-
<body>
-
<form id="thePfhorm">
-
</form>
-
-
<div id="dolly" style="display:none">
-
<input type="text" name="criteria[]">
-
<input type="button" value="Remove" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">
-
</div>
-
<br>
-
<input type="button" value="Add" onclick="addInput();">
-
-
<script type="text/javascript">
-
// <![CDATA[
-
// Add the first set of inputs.
-
addInput();
-
// ]]>
-
</script>
-
</body>
-
</html>
-
JM
Sorry guys, could I ask a follow up question on this.
Once you've got this working, how do you harvest the entered info to post to a database?
I've been playing around with some different php ideas to do it but no luck so far.
Sorry guys, could I ask a follow up question on this.
Once you've got this working, how do you harvest the entered info to post to a database?
I've been playing around with some different php ideas to do it but no luck so far.
Hi BigM
Taking the code you posted above, you see you named your textfield "criteria[]"
as you know the field's values can normally be collected with $_POST or $_GET. This is actually still the case, the only thing is that when you put in the square brackets, your result will be an array :)
if you wanted to gather all the inputfields you would use something like -
<?php
-
foreach($_POST['criteria'] as $value)
-
{
-
echo $value;
-
}
-
?>
-
if you try to print out $_POST['criteria'] you will most likely see "Array".
@BigM again :)
you need to put your formfields inside the form tag, also if you wrap a div or table tag around them, if you don't, nothing will get send with the form :)
and make sure to set the method attribute too, cause the GET method might not always be the browser default :)
Thanks very much ronnil, working perfectly now. :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mr_burns |
last post by:
hi,
is it possible to change the contents of a combo box when the contents
of another are changed. for example, if i had a combo box called
garments containing shirts, trousers and hats, when...
|
by: Jack |
last post by:
Hi,
I am trying to test a sql statement in Access which gives me
the error as stated in the heading.
The sql statement is built as a part of asp login verification,
where the userid and password...
|
by: Nathan Bloomfield |
last post by:
Does anyone know if there is any documentation which relates to Access2k + ?
or can anyone help adjust the code?
I am having trouble converting the DAO references.
TITLE :INF: How to...
|
by: Peter Bailey |
last post by:
Could someone please tell me how to pass criteria as if it were a parameter.
I have a routine now that creates the sql string (well almost). at present
the parameter is so I can pass one item ie...
|
by: starace |
last post by:
I have designed a form that has 5 different list boxes where the
selections within each are used as criteria in building a dynamic
query. Some boxes are set for multiple selections but these list...
|
by: deejayquai |
last post by:
Hi
I'm trying to produce a report based on a dynamic crosstab. Ultimately
i'd like the report to actually become a sub report within a student
end of year record of achievement. The dynamic...
|
by: Erland Sommarskog |
last post by:
I've uploaded a new version of my article on Dynamic Search Conditions
on http://www.sommarskog.se/dyn-search.html. I've revised the article to
cover SQL 2005, and made a general overhaul of the...
|
by: 6afraidbecause789 |
last post by:
Hi - I'm trying to make a Where statement but can't. I''ve put
multiple yes/no fields in a listbox as a field list according Don
Leverton's comments in the thread "query by field heading options"...
|
by: ollyb303 |
last post by:
Hi,
I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor.
I have one crosstab query (Query1) which...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |