Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 26th, 2004, 04:46 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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!

Reply With Quote
  #2  
Old January 26th, 2004, 06:15 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
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):
php Code:
Original - php Code
  1.  
  2. list($min, $max) = split(',', $_GET['range']);

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.

Reply With Quote
  #3  
Old January 26th, 2004, 06:58 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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.

Reply With Quote
  #4  
Old January 28th, 2004, 06:10 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
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.

Reply With Quote
  #5  
Old January 28th, 2004, 06:39 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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)


Reply With Quote
  #6  
Old January 28th, 2004, 08:09 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: Passing a number-ranged variable

try:
php Code:
Original - php Code
  1.  
  2. list($min_lumens, $max_lumens) = split(',', $HTTP_POST_VARS['lumens']);
  3. $where = array();
  4. if($min != '') $where[] = "lumens >= '$min_lumens'";
  5. if($max != '') $where[] = "lumens <= '$max_lumens'";
  6. if(!empty($where))
  7. {
  8.     $query_Recordset1 = "SELECT * FROM projectors WHERE ".join(' AND ', $where)."' ORDER BY list_price ASC";
  9. } else {
  10.     $query_Recordset1 = "SELECT * FROM projectors ORDER BY list_price ASC";
  11. }

Reply With Quote
  #7  
Old March 19th, 2004, 01:24 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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


Reply With Quote
  #8  
Old March 19th, 2004, 02:14 AM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: Passing a number-ranged variable

Since you're including the comparision operator in the select's option values, just remove the equal sign from your query:
php Code:
Original - php Code
  1.  
  2. $query .= " WHERE state='$state' AND loan_type='$loan_type' AND volume$volume ";

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Passing a number-ranged variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT