|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Passing a number-ranged variable
This is what I am trying to do. I want a user to be able to pick a general number range within a drop down menu - and then pass that variable so that when the recordset is pulled up dynamically on the next page - it will pull up products only within that general number range.
For example: I want one variable to pull up anything less than or equal to 1500 - I named the variable 1500 I want one variable to pull up anything between 1500 and 3000 - I named that variable 2000 I want the last variable to pull up anything equal to or above 3000 - I named that variable 3000 So, on the page that the variables I sent to - I need to assign those variables those numbers right? I'm just not sure how to do that. This is what I thought I would need: $1500 = ($1500 <= 1500); $2000 = ($2000 > 1500 && $2000 < 3000); $3000 = ($3000 >= 3000); But that isn't working - so obviously something is wrong. Can anyone help me with this? Thanks! |
|
#2
|
||||
|
||||
|
RE: Passing a number-ranged variable
Let me suggest you do this slightly differently:
Your drop down should look like this: Code:
<select name="range">
<option value=",1500">less than 1500</option>
<option value="1500,3000">1500 - 3000</option>
<option value="3000,">3000 and above</option>
</select>
Now, your PHP can simply access the min and max amounts like this (I'm assuming the form uses GET and not POST, but it's an easy change): If $min or $max == '', then there is no limit. The advantage of doing it like this is that your data (i.e., what the split ranges are) is only stored in one location, making for much eaiser maintenence. |
|
#3
|
|||
|
|||
|
RE: Passing a number-ranged variable
I'm still trying to get through the PHP coding - this is the recordset coding I have on a similar page:
<?php $colname_Recordset1 = "JVC"; if (isset($HTTP_POST_VARS['qbrand'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['qbrand'] : addslashes($HTTP_POST_VARS['qbrand']); } mysql_select_db($database_tvspec, $tvspec); $query_Recordset1 = sprintf("SELECT * FROM projectors WHERE manufacturer = '%s' ORDER BY list_price ASC", $colname_Recordset1); $Recordset1 = mysql_query($query_Recordset1, $tvspec) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> So, is this correct is I change the coding to this? <?php list($min, $max) = split(',', $HTTP_POST_VARS['lumens']); } mysql_select_db($database_tvspec, $tvspec); $query_Recordset1 = "SELECT * FROM projectors ORDER BY list_price ASC"; $Recordset1 = mysql_query($query_Recordset1, $tvspec) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> Yes, I am using the POST method, and the variable is lumens. - I'm getting errors with this when I test is though. |
|
#4
|
||||
|
||||
|
RE: Passing a number-ranged variable
I'm not quite sure how to help you with this since you don't seem to be using the info stored in $_POST['lumens'].
I presume you want to limit the query: "SELECT * FROM projectors ORDER BY list_price ASC" somehow by the min and max values from the dropdown, but I can't guess what your database looks like or what your intent is. If you provide more information, maybe I can help more. |
|
#5
|
|||
|
|||
|
RE: RE: Passing a number-ranged variable
Yes, I do want to use the info from the 'lumens' stored info.
Your presumption was right. I want to limit the query to the information they selected (variable lumens)- we can take off the ORDER BY line completely. Maybe the min and max go somewhere where it describes the recordset - but not knowing much about PHP I have no idea how to write it in there: $query_Recordset1 = "SELECT * FROM projectors ORDER BY list_price ASC"; (This recordset right now pulls up ALL records from projectors - where I only want it to pull up the projectors limited by the range they select) |
|
#6
|
|||||
|
|||||
|
RE: Passing a number-ranged variable
try:
php Code:
|
|
#7
|
|||
|
|||
|
RE: Passing a number-ranged variable
Hi,
Newbie here! I am trying the same thing but need to send the results via query to postgre db. Using php, the form needs to ask (dropdown) >= 1 as the first option < 50000 as the second option and >= 50000 as the third choice Here is the php code.... I have so far... echo "<form action='admin_display_pipeline-test.php' method='post' name='form_location'>"; echo "<input type='hidden' name=$volume value=$id>"; echo "Volume: <select name=volume onchange='document.form_location.submit();'>"; echo "<option value='>= 1'> All"; echo "<option value='< 50000'> < 50000"; echo "<option value='>= 50000'> >= 50000"; //fillinselectelement(volume,0); echo "</select><input type=submit value=go>"; if ($volume=='') { echo "<script language='javascript'> document.form_location.submit();</script>"; } **************** **************** Here is the query for that section... $query .= " WHERE state='$state' AND loan_type='$loan_type' AND volume='$volume' ***** Note this is related to $volume The query does not like the =< symbols within the option tag. Been working on this for days Any help appreciated Thanks Marc |
|
#8
|
||||
|
||||
|
RE: Passing a number-ranged variable
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Passing a number-ranged variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|