Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > Looking for help with forms/variables and an array!
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
11 16th March 22:17
mrsquash2
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!



Wouldn't a little javascript solve this problem??

Have your first dropdown menu, then when an option is selected use a
javascript Onchange function to refresh (post) the page to itself. This
would set the selected option as your "form1" value. Then just write a
simple query using that value to return the options you want for dropdown
#2.

Something like this:

<select name="states" onchange="this.submit();">
<option value="AL" > Alabama
<option value="FL" >Florida
<option value="WA" >Washington
<option value="MI" >Michigan
</select>

if (!isset($_POST['submit'])) {
$state = $_POST['states'];

Then put your result in an array and populate your second dropdown.

<td width="43" align="right">City:</td>
<td width="135" align="left" class="tblcell_sm">
<SELECT name="city">
<?php
$database = mssql_select_db("database", $connection) or die ('DB selection
failed');
// Query the table and load all of the records into an array.
$q_cities = "SELECT * FROM cities WHERE state_name = '$state'";
$r_cities = mssql_query($q_cities) or die(mssql_error());
while ($rec_cities = mssql_fetch_assoc($r_cities)) $c_city[] =
$rec_cities;

echo "<OPTION value=\"\">--SELECT--</OPTION>\n";
foreach ($c_city as $s_city)
{
if ($s_city['state_name'] == $_POST['states'])
echo "<OPTION value=\"{$s_city['city_code']}\"
SELECTED>{$s_city['city_name']}</OPTION>\n";
else
echo "<OPTION
value=\"{$s_city['city_code']}\">{$s_cc['city_name']}</OPTION>\n";
}
?>
</SELECT>
</td>

Hope that helps?? lol
  Reply With Quote


  sponsored links


12 16th March 22:18
ceo
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!



AJAX simply creates an HTTP dialog between the browser and a server
(probably your server) for an ongoing interactive user experience.

There is nothing specific to Microsoft about it, other than that
Microsoft actually did first create the XmlHttpRequest object for some
other stupid purpose, before people realized how cool it would be for
AJAX, and re-purposed it.


--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
  Reply With Quote
13 16th March 22:18
ceo
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


Actually, this is not at all true.

And, really, fixing the example before you run it to not need
register_globals is the way to go.

Not EXACTLY the same miserable error.

You're still writing invalid SQL, but it's invalid in different ways
each time.

echo out your query, and see how it looks, and compare it to how the
query should look.

echo $query_Recordset1;

PS
extract($_POST) is just as bad as register_globals, so don't do that.


Maybe you want something more like:

$price_minimum = (int) $_POST['select1'];
$price_maximum = (int) $_POST['select2'];
$price_minimum_sql = mysql_real_escape_string($price_minimum); $price_maximum_sql = mysql_real_escape_string($price_maximum);
$query = "select * from whatever where price >= $price_minimum_sql and
price <= $price_maximum_sql";

Though it looks like you've set up price "brackets" so maybe it won't
be quite like that... Still it's closer than what you have now.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
  Reply With Quote
14 17th March 01:35
brads
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


Wow,
Thank you!

You appear to have gotten me 90% towards my mission final.

mysql_select_db($database_ftn, $ftn);
@extract($_POST);
$query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range =
'$select1'";
echo $query_Recordset1;
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1,
$startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $ftn) or
die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

<form id="form1" name="form1" method="post" action="index_dev.php">
<label>market
<select name="select1">
<OPTION value="1">Indiana</OPTION>
<OPTION value="2">Wisconsin</OPTION>
<OPTION value="3">Illinois</OPTION>
<OPTION value="4">Michigan</OPTION>
<OPTION value="5">Ge****a</OPTION>
<OPTION value="6">Florida</OPTION>
</select>
<input name="submit" type="submit" value="post"/>
</label>
</form>


Works!!!!!!!!!!!!!

Thank you!
Thank you!
Thank you!

Sincerely,
Brad

-----Original Message-----
From: Jim Lucas [mailto:lists@cmsws.com]
Sent: Tuesday, June 12, 2007 1:57 PM
To: BSumrall
Cc: php-general@lists.php.net
Subject: Re: [php] Looking for help with forms/variables and an array!

if this is within PHP, the '{' and '}' are within double quotes (which they
seem to be),

These examples should all do the same thing.

$query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range =
'$select1'";
$query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range =
'{$select1}'";
$query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range =
'".$select1."'";

echo $query_Recordset1;

place an echo just after including the variable and see if you see the
brackets in the statement.


--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Reply With Quote
15 17th March 01:35
brads
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


I, I, sir!
I changed it back!

)

Point noted!

-----Original Message-----
From: Robert ***mings [mailto:robert@interjinn.com]
Sent: Tuesday, June 12, 2007 1:24 PM
To: BSumrall
Cc: php-general@lists.php.net
Subject: RE: [php] Looking for help with forms/variables and an array!


That's no excuse... and you're wrong.


Ok... and magic_quotes? You don't seem to be escaping your data that
goes into the query either. You don't seem very "aware of the security risk".

Why do it twice? Why risk forgetting something after the fact? Coding
securely requires that you practice coding securely and not just hope
you can apply a coat of armorall afterwards.


The same tools I have, if not then you have more.


I gave you an example at the bottom of my post. Are you passing the
$query string directly to the mysql_query() function? Maybe do the
following just before running the query:

echo $query."\n";

Then check it to see that it's what you expect.

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
  Reply With Quote
16 17th March 01:35
brads
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


Oops, I spoke to soon.

It was switching records but the wrongs ones.

My bad

Here is what I am dealing with

The whole code!

<?php require_once('connections/ftn.php'); ?>

<?php

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 1;

$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {

$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_ftn, $ftn);

@extract($_POST);

$query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range='$region1'";

echo $query_Recordset1;

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1,
$startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $ftn) or
die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {

$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

} else {

$all_Recordset1 = mysql_query($query_Recordset1);

$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

}

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";

if (!empty($_SERVER['QUERY_STRING'])) {

$params = explode("&", $_SERVER['QUERY_STRING']);

$newParams = array();

foreach ($params as $param) {

if (stristr($param, "pageNum_Recordset1") == false &&

stristr($param, "totalRows_Recordset1") == false) {

array_push($newParams, $param);

}

}

if (count($newParams) != 0) {

$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

}

}

$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s",
$totalRows_Recordset1, $queryString_Recordset1);

?>

</head>

<body>

<form id="form1" name="form1" method="post" action="index_dev.php">

<label>market

<select name="select1">

<OPTION value="1">Indiana</OPTION>

<OPTION value="2">Wisconsin</OPTION>

<OPTION value="3">Illinois</OPTION>

<OPTION value="4">Michigan</OPTION>

<OPTION value="5">Ge****a</OPTION>

<OPTION value="6">Florida</OPTION>

</select>

<input name="submit" type="submit" value="post"/>

</label>

</form>

<tr>

<td>key</td>

<td>price_range</td>

<td>range_key</td>

<td>price</td>

</tr>

<?php do { ?>

<tr>

<td><?php echo $row_Recordset1['price_range']; ?></td>

<td><?php echo $row_Recordset1['range_key']; ?></td>

<td><?php echo $row_Recordset1['price']; ?></td>

</tr>

<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

</table>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

Produces this

SELECT * FROM lstng_tbl WHERE price_range = ''

market Indiana Wisconsin Illinois Michigan Ge****a Florida


key

price_range

range_key

price
  Reply With Quote
17 17th March 01:35
brads
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


I thank you kindly for your pointers.
It did really help me with getting further.
Persons like yourself are truly talented to be able and bang out the theory
like that on the fly.

Only problem is that I am using php to learn code for the first real time.
The Microsoft stuff started to throw me off.

I am going sit hear and study your example intently and hopefully it will
clue me off on my major variable error.

I am right there with it!

Brad

-----Original Message-----
From: Dan Shirah [mailto:mrsquash2@gmail.com]
Sent: Tuesday, June 12, 2007 3:05 PM
To: Jim Lucas
Cc: BSumrall; php-general@lists.php.net
Subject: Re: [php] Looking for help with forms/variables and an array!

Wouldn't a little javascript solve this problem??

Have your first dropdown menu, then when an option is selected use a
javascript Onchange function to refresh (post) the page to itself. This
would set the selected option as your "form1" value. Then just write a
simple query using that value to return the options you want for dropdown
#2.

Something like this:

<select name="states" onchange="this.submit();">
<option value="AL" > Alabama
<option value="FL" >Florida
<option value="WA" >Washington
<option value="MI" >Michigan
</select>

if (!isset($_POST['submit'])) {
$state = $_POST['states'];

Then put your result in an array and populate your second dropdown.

<td width="43" align="right">City:</td>
<td width="135" align="left" class="tblcell_sm">
<SELECT name="city">
<?php
$database = mssql_select_db("database", $connection) or die ('DB selection
failed');
// Query the table and load all of the records into an array.
$q_cities = "SELECT * FROM cities WHERE state_name = '$state'";
$r_cities = mssql_query($q_cities) or die(mssql_error());
while ($rec_cities = mssql_fetch_assoc($r_cities)) $c_city[] =
$rec_cities;

echo "<OPTION value=\"\">--SELECT--</OPTION>\n";
foreach ($c_city as $s_city)
{
if ($s_city['state_name'] == $_POST['states'])
echo "<OPTION value=\"{$s_city['city_code']}\"
SELECTED>{$s_city['city_name']}</OPTION>\n";
else
echo "<OPTION
value=\"{$s_city['city_code']}\">{$s_cc['city_name']}</OPTION>\n";
}
?>
</SELECT>
</td>

Hope that helps?? lol
  Reply With Quote
18 17th March 01:36
lists
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


Are you wanting to setup some sorta pagination, or just get the results from the DB limited by the
selected option in the form?

oh, where is your second form in this example?

In pseudo code, write out what you are attempting to do?


--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Reply With Quote
19 17th March 01:36
brads
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


I had done that before,

But here it goes again because I have learned a little bit more

-> establish db connect

-> drop down box stores result as a variable

-> first initial query performed

-> query array established

-> drop down box 2 is saved as a variable

-> variable 2 filters query 1

-> display one record at a time

Here is what I have right now. It is error free, just doest work, all I have
done change some variables and not even bothering with record set 2 yet

Anything in bold is what I have played with since it would pull every
record, just not filter and now does not work.

Brad

<?php require_once('connections/ftn.php'); ?>

<?php

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 1;

$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {

$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_ftn, $ftn);

@extract($_POST);

$query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range = '$state'";

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1,
$startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $ftn) or
die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {

$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

} else {

$all_Recordset1 = mysql_query($query_Recordset1);

$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

}

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";

if (!empty($_SERVER['QUERY_STRING'])) {

$params = explode("&", $_SERVER['QUERY_STRING']);

$newParams = array();

foreach ($params as $param) {

if (stristr($param, "pageNum_Recordset1") == false &&

stristr($param, "totalRows_Recordset1") == false) {

array_push($newParams, $param);

}

}

if (count($newParams) != 0) {

$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

}

}

$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s",
$totalRows_Recordset1, $queryString_Recordset1);

?>

<body>

<form id="form1" name="form1" method="post" action="index_dev2.php">

<label>market

<select name="states">

<OPTION value="IN">Indiana</OPTION>

<OPTION value="WI">Wisconsin</OPTION>

<OPTION value="IL">Illinois</OPTION>

<OPTION value="MI">Michigan</OPTION>

<OPTION value="GA">Ge****a</OPTION>

<OPTION value="FL">Florida</OPTION>

</select>

</label>

</form>

<?php

if ($states=="value" || !isset($states)) echo "selected";

?>

<br>

<form id="form2" name="form2" method="post" action="index_dev2.php">

<label>price_range

<select name="price">

<OPTION value="1">Over $2 million</OPTION>

<OPTION value="2">$1 million - $2 million</OPTION>

<OPTION value="3">$750,000 - $1 million</OPTION>

<OPTION value="4">under $750,000</OPTION>

</select>

<input name="submit" type="submit" value="post"/>

</label>

</form>

<?php

if ($price=="value"|| !isset($price)) echo "selected";

?>

<?php do { ?>

-----Original Message-----
From: Jim Lucas [mailto:lists@cmsws.com]
Sent: Tuesday, June 12, 2007 8:26 PM
To: BSumrall
Cc: php-general@lists.php.net
Subject: Re: [php] Looking for help with forms/variables and an array!

Are you wanting to setup some sorta pagination, or just get the results from
the DB limited by the

selected option in the form?

oh, where is your second form in this example?

In pseudo code, write out what you are attempting to do?

--

Jim Lucas

"Some men are born to greatness, some achieve greatness,

and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V

by William Shakespeare
  Reply With Quote
20 17th March 01:36
brads
External User
 
Posts: 1
Default Looking for help with forms/variables and an array!


_____

From: BSumrall [mailto:Brads@ftnco.com]
Sent: Tuesday, June 12, 2007 8:46 PM
To: 'Jim Lucas'
Cc: 'php-general@lists.php.net'
Subject: RE: [php] Looking for help with forms/variables and an array!

I had done that before,

But here it goes again because I have learned a little bit more

-> establish db connect

-> drop down box stores result as a variable

-> first initial query performed

-> query array established

-> drop down box 2 is saved as a variable

-> variable 2 filters query 1

-> display one record at a time

Here is what I have right now. It is error free, just doest work, all I have
done change some variables and not even bothering with record set 2 yet

Anything in bold is what I have played with since it would pull every
record, just not filter and now does not work.

Brad

<?php require_once('connections/ftn.php'); ?>

<?php

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 1;

$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {

$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_ftn, $ftn);

@extract($_POST);

$query_Recordset1 = "SELECT * FROM lstng_tbl WHERE price_range = '$state'";

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1,
$startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $ftn) or
die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {

$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

} else {

$all_Recordset1 = mysql_query($query_Recordset1);

$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

}

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";

if (!empty($_SERVER['QUERY_STRING'])) {

$params = explode("&", $_SERVER['QUERY_STRING']);

$newParams = array();

foreach ($params as $param) {

if (stristr($param, "pageNum_Recordset1") == false &&

stristr($param, "totalRows_Recordset1") == false) {

array_push($newParams, $param);

}

}

if (count($newParams) != 0) {

$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));

}

}

$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s",
$totalRows_Recordset1, $queryString_Recordset1);

?>

<body>

<form id="form1" name="form1" method="post" action="index_dev2.php">

<label>market

<select name="states">

<OPTION value="IN">Indiana</OPTION>

<OPTION value="WI">Wisconsin</OPTION>

<OPTION value="IL">Illinois</OPTION>

<OPTION value="MI">Michigan</OPTION>

<OPTION value="GA">Ge****a</OPTION>

<OPTION value="FL">Florida</OPTION>

</select>

</label>

</form>

<?php

if ($states=="value" || !isset($states)) echo "selected";

?>

<br>

<form id="form2" name="form2" method="post" action="index_dev2.php">

<label>price_range

<select name="price">

<OPTION value="1">Over $2 million</OPTION>

<OPTION value="2">$1 million - $2 million</OPTION>

<OPTION value="3">$750,000 - $1 million</OPTION>

<OPTION value="4">under $750,000</OPTION>

</select>

<input name="submit" type="submit" value="post"/>

</label>

</form>

<?php

if ($price=="value"|| !isset($price)) echo "selected";

?>

<?php do { ?>

-----Original Message-----
From: Jim Lucas [mailto:lists@cmsws.com]
Sent: Tuesday, June 12, 2007 8:26 PM
To: BSumrall
Cc: php-general@lists.php.net
Subject: Re: [php] Looking for help with forms/variables and an array!

Are you wanting to setup some sorta pagination, or just get the results from
the DB limited by the

selected option in the form?

oh, where is your second form in this example?

In pseudo code, write out what you are attempting to do?

--

Jim Lucas

"Some men are born to greatness, some achieve greatness,

and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V

by William Shakespeare
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666