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 3130
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 !! ..
pbmods 5,821
Recognized Expert Expert
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 !
kovik 1,044
Recognized Expert Top Contributor
CSS works on <tr> and <div>. Changing the class of a <tr> or <div> with JavaScript is done the same way. - element.className = 'foo';
pbmods 5,821
Recognized Expert Expert
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 !
pbmods 5,821
Recognized Expert Expert
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 :)
pbmods 5,821
Recognized Expert Expert
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]
pbmods 5,821
Recognized Expert Expert
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
pbmods 5,821
Recognized Expert Expert
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.
ronnil 134
Recognized Expert New Member
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".
ronnil 134
Recognized Expert New Member
@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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |