php-general Digest 24 Feb 2011 17:20:51 -0000 Issue 7198
Topics (messages 311552 through 311566):
Re: Manipulating variables
311552 by: Joshua Kehn
311553 by: Robert Cummings
311554 by: Jim Lucas
Re: mysql_num_rows()
311555 by: Pete Ford
311564 by: Gary
Dotnet Remoting
311556 by: Gary
311560 by: Bastien
Why is this array_walk_recursive action not working?
311557 by: Dave M G
311558 by: FeIn
311561 by: Dave M G
311562 by: FeIn
311563 by: Richard Quadling
Simplest way of enforcing an array of instances of a specific class but
treating the whole thing as an array.
311559 by: Richard Quadling
311566 by: Richard Quadling
Re: Dynamically Created Checkboxes
311565 by: Gary
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
I must be missing something, why do you need to use variable variables when
checking user answers?
The logic should be something like:
$answer_key = array('question1' => 'answer', 'question2' => 'answer', ....);
foreach($answer_key as $q => $a)
{
check_answer($_POST[$q], $a);
}
Regards,
-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com
On Feb 23, 2011, at 11:48 PM, Ron Piggott wrote:
>
> Is there a way to make this syntax:
>
> $checking_answer = $answer_reference_2;
>
> Equal to:
>
> $checking_answer = $answer_reference_ . ($i + 1);
>
> (where $i = 1)
>
> making $checking_answer take on the value of $answer_reference_2 ?
>
> I am trying to develop a web app quiz and I need to test the users answers.
>
> Ron
>
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
--- End Message ---
--- Begin Message ---
On 11-02-23 11:48 PM, Ron Piggott wrote:
Is there a way to make this syntax:
$checking_answer = $answer_reference_2;
Equal to:
$checking_answer = $answer_reference_ . ($i + 1);
(where $i = 1)
making $checking_answer take on the value of $answer_reference_2 ?
I am trying to develop a web app quiz and I need to test the users answers.
<?php
$checking_answer = ${'answer_reference_'.($i + 1)};
?>
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
On 2/23/2011 8:48 PM, Ron Piggott wrote:
Is there a way to make this syntax:
$checking_answer = $answer_reference_2;
Equal to:
$checking_answer = $answer_reference_ . ($i + 1);
(where $i = 1)
making $checking_answer take on the value of $answer_reference_2 ?
I am trying to develop a web app quiz and I need to test the users answers.
Ron
The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info
Give this a try
<?php
# Variable Variables Test
$id_0 = 'zero';
$id_1 = 'one';
$id_2 = 'two';
$id_3 = 'three';
for ( $i=0; $i<4; $i++ ) {
echo ${'id_'.$i};
}
?>
--
Jim Lucas
http://www.cmsws.com
--- End Message ---
--- Begin Message ---
On 22/02/11 14:40, Gary wrote:
"Pete Ford"<[email protected]> wrote in message
news:[email protected]...
On 22/02/11 13:59, Gary wrote:
"Pete Ford"<[email protected]> wrote in message
news:[email protected]...
On 22/02/11 05:40, Gary wrote:
Can someone tell me why this is not working? I do not get an error
message,
the results are called and echo'd to screen, the count does not work, I
get
a 0 for a result...
$result = mysql_query("SELECT * FROM `counties` WHERE name =
'checked'")
or
die(mysql_error());
if ( isset($_POST['submit']) ) {
for($i=1; $i<=$_POST['counties']; $i++) {
if ( isset($_POST["county$i"] ) ) {
echo "You have chosen ". $_POST["county$i"]."<br/>";
}
}
}
$county_total=mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{$i++;
echo $row['name'];
}
$county_total=mysql_num_rows($result);
echo "$county_total";
echo 'You Have ' . "$county_total" . ' Counties ';
?>
The first thing I see is that you do
$county_total=mysql_num_rows($result)
twice. Now I'm not to sure, but it is possible that looping over
mysql_fetch_array($result) moves an array pointer so the count is not
valid after the operation... that's a long shot.
But since you are looping over the database records anyway, why not just
count them as you go? Isn't $i the number of counties after all the
looping?
--
Peter Ford, Developer phone: 01580 893333 fax: 01580
893399
Justcroft International Ltd.
www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent TN12 0AH United
Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17
1XS
Peter
Thank you for your reply.
I did notice that I had the $county_total=mysql_num_rows($result) twice.
I
had moved and removed it, always getting either a 0 or 1 result.
I put up another test page with
$result = mysql_query("SELECT * FROM `counties` ") or die(mysql_error());
$tot=mysql_num_rows($result);
echo "$tot";
?>
And it worked fine.
I have tried count() as well as mysql_num_rows() but am getting the same
result.
Could you explain what you mean by count them as I go?
Again, Thank you for your reply.
Gary
__________ Information from ESET Smart Security, version of virus
signature database 5895 (20110222) __________
The message was checked by ESET Smart Security.
http://www.eset.com
Well,
Lets go back to your original code and cut out the decoration:
$result = mysql_query("SELECT * FROM `counties` WHERE name = 'checked'")
$county_total=mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
echo $row['name'];
}
echo "$county_total";
That code should do pretty much what you want...
But, because you only show the number of records AFTER the loop, you could
do:
$result = mysql_query("SELECT * FROM `counties` WHERE name = 'checked'")
$county_total = 0;
while($row = mysql_fetch_array($result))
{
echo $row['name'];
$county_total++;
}
echo "$county_total";
Peter
Thank you for your suggestion...btw "cut out the decoration" LOL
I'm sorry to report it did not work. I tried various configurations of it
but to no avail.
Any other suggestions?
Again, thank you for your help.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5895 (20110222) __________
The message was checked by ESET Smart Security.
http://www.eset.com
Gary,
I'd probably need a bit more detail on the "it did not work" to go much further!
Actually, it looks like I missed a semicolon on the "mysql_query" line in *both*
versions - maybe that was the problem...
Do you have access to your server logs, to see if any errors are reported when
you run this?
Cheers
Peter
--
Peter Ford, Developer phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd. www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS
--- End Message ---
--- Begin Message ---
"Pete Ford" <[email protected]> wrote in message
news:[email protected]...
> On 22/02/11 14:40, Gary wrote:
>> "Pete Ford"<[email protected]> wrote in message
>> news:[email protected]...
>>> On 22/02/11 13:59, Gary wrote:
>>>> "Pete Ford"<[email protected]> wrote in message
>>>> news:[email protected]...
>>>>> On 22/02/11 05:40, Gary wrote:
>>>>>> Can someone tell me why this is not working? I do not get an error
>>>>>> message,
>>>>>> the results are called and echo'd to screen, the count does not work,
>>>>>> I
>>>>>> get
>>>>>> a 0 for a result...
>>>>>>
>>>>>>
>>>>>>
>>>>>> $result = mysql_query("SELECT * FROM `counties` WHERE name =
>>>>>> 'checked'")
>>>>>> or
>>>>>> die(mysql_error());
>>>>>>
>>>>>> if ( isset($_POST['submit']) ) {
>>>>>> for($i=1; $i<=$_POST['counties']; $i++) {
>>>>>> if ( isset($_POST["county$i"] ) ) {
>>>>>> echo "You have chosen ". $_POST["county$i"]."<br/>";
>>>>>> }
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> $county_total=mysql_num_rows($result);
>>>>>>
>>>>>> while($row = mysql_fetch_array($result))
>>>>>> {$i++;
>>>>>> echo $row['name'];
>>>>>> }
>>>>>> $county_total=mysql_num_rows($result);
>>>>>> echo "$county_total";
>>>>>>
>>>>>> echo 'You Have ' . "$county_total" . ' Counties ';
>>>>>>
>>>>>> ?>
>>>>>
>>>>> The first thing I see is that you do
>>>>> $county_total=mysql_num_rows($result)
>>>>> twice. Now I'm not to sure, but it is possible that looping over
>>>>> mysql_fetch_array($result) moves an array pointer so the count is not
>>>>> valid after the operation... that's a long shot.
>>>>>
>>>>> But since you are looping over the database records anyway, why not
>>>>> just
>>>>> count them as you go? Isn't $i the number of counties after all the
>>>>> looping?
>>>>>
>>>>>
>>>>> --
>>>>> Peter Ford, Developer phone: 01580 893333 fax: 01580
>>>>> 893399
>>>>> Justcroft International Ltd.
>>>>> www.justcroft.com
>>>>> Justcroft House, High Street, Staplehurst, Kent TN12 0AH United
>>>>> Kingdom
>>>>> Registered in England and Wales: 2297906
>>>>> Registered office: Stag Gates House, 63/64 The Avenue, Southampton
>>>>> SO17
>>>>> 1XS
>>>>
>>>>
>>>> Peter
>>>>
>>>> Thank you for your reply.
>>>>
>>>> I did notice that I had the $county_total=mysql_num_rows($result)
>>>> twice.
>>>> I
>>>> had moved and removed it, always getting either a 0 or 1 result.
>>>>
>>>> I put up another test page with
>>>>
>>>> $result = mysql_query("SELECT * FROM `counties` ") or
>>>> die(mysql_error());
>>>>
>>>> $tot=mysql_num_rows($result);
>>>> echo "$tot";
>>>>
>>>> ?>
>>>>
>>>> And it worked fine.
>>>>
>>>> I have tried count() as well as mysql_num_rows() but am getting the
>>>> same
>>>> result.
>>>>
>>>> Could you explain what you mean by count them as I go?
>>>>
>>>> Again, Thank you for your reply.
>>>>
>>>> Gary
>>>>
>>>>
>>>>
>>>> __________ Information from ESET Smart Security, version of virus
>>>> signature database 5895 (20110222) __________
>>>>
>>>> The message was checked by ESET Smart Security.
>>>>
>>>> http://www.eset.com
>>>>
>>>>
>>>>
>>>>
>>>
>>> Well,
>>>
>>> Lets go back to your original code and cut out the decoration:
>>>
>>> $result = mysql_query("SELECT * FROM `counties` WHERE name = 'checked'")
>>> $county_total=mysql_num_rows($result);
>>> while($row = mysql_fetch_array($result))
>>> {
>>> echo $row['name'];
>>> }
>>> echo "$county_total";
>>>
>>> That code should do pretty much what you want...
>>>
>>> But, because you only show the number of records AFTER the loop, you
>>> could
>>> do:
>>>
>>> $result = mysql_query("SELECT * FROM `counties` WHERE name = 'checked'")
>>> $county_total = 0;
>>> while($row = mysql_fetch_array($result))
>>> {
>>> echo $row['name'];
>>> $county_total++;
>>> }
>>> echo "$county_total";
>>>
>>
>> Peter
>>
>> Thank you for your suggestion...btw "cut out the decoration" LOL
>>
>> I'm sorry to report it did not work. I tried various configurations of it
>> but to no avail.
>>
>> Any other suggestions?
>>
>> Again, thank you for your help.
>>
>> Gary
>>
>>
>>
>> __________ Information from ESET Smart Security, version of virus
>> signature database 5895 (20110222) __________
>>
>> The message was checked by ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>
> Gary,
>
> I'd probably need a bit more detail on the "it did not work" to go much
> further!
> Actually, it looks like I missed a semicolon on the "mysql_query" line in
> *both* versions - maybe that was the problem...
> Do you have access to your server logs, to see if any errors are reported
> when you run this?
>
> Cheers
> Peter
>
> --
> Peter Ford, Developer phone: 01580 893333 fax: 01580
> 893399
> Justcroft International Ltd.
> www.justcroft.com
> Justcroft House, High Street, Staplehurst, Kent TN12 0AH United
> Kingdom
> Registered in England and Wales: 2297906
> Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17
> 1XS
Peter
I'm sorry, I sort of abandoned this post since I found I had other problems
with the scripts and posted another question above. I have at this point the
checkboxes appearing, the mysql_num_row is not working yet, but that can got
kicked down the road a bit.
Thank you for all your help, I'm trying to formulate me next question for
the aforementioned 2nd post.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5904 (20110224) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
This is purely of academic interest to me, nothing urgent.
I'm just wondering if it's possible to do remoting with PHP's DOTNET
class (http://php.net/manual/en/class.dotnet.php) which I didn't even
know existed until yesterday. If it is, is there any reason that DOTNET
is a Windows only extension?
Like I say, it's just something I'm curious about.
--
Gary Please do NOT send me 'courtesy' replies off-list.
--- End Message ---
--- Begin Message ---
On 2011-02-24, at 5:17 AM, Gary <[email protected]> wrote:
> This is purely of academic interest to me, nothing urgent.
>
> I'm just wondering if it's possible to do remoting with PHP's DOTNET
> class (http://php.net/manual/en/class.dotnet.php) which I didn't even
> know existed until yesterday. If it is, is there any reason that DOTNET
> is a Windows only extension?
>
> Like I say, it's just something I'm curious about.
>
> --
> Gary Please do NOT send me 'courtesy' replies off-list.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
How about because dotnet and the dotnet framework is a windows product?
Bastien Koert
905-904-0334
Sent from my iPhone
--- End Message ---
--- Begin Message ---
PHP users,
I obviously don't understand what array_walk_recursive does.
Can someone break down in simple terms why the following doesn't work?
- - -
$karamohOutput['test'] = "";
function test_print($item, $key)
{
return "$key holds $item\n";
}
$karamohOutput['test'] .= array_walk_recursive($karamohArray, 'test_print');
- - -
Any advice would be much appreciated.
--
Dave M G
--- End Message ---
--- Begin Message ---
Hi,
How does the input array look like (the contents of the $karamohArray
variable) ? Is your script generating any errors? What do you expect to
happen when you call array_walk_recursive?
On Thu, Feb 24, 2011 at 1:01 PM, Dave M G <[email protected]> wrote:
> PHP users,
>
> I obviously don't understand what array_walk_recursive does.
>
> Can someone break down in simple terms why the following doesn't work?
>
> - - -
>
> $karamohOutput['test'] = "";
>
> function test_print($item, $key)
> {
> return "$key holds $item\n";
> }
> $karamohOutput['test'] .= array_walk_recursive($karamohArray,
> 'test_print');
>
> - - -
>
> Any advice would be much appreciated.
>
> --
> Dave M G
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
FeIn,
Thank you for responding.
> what did you expect to happen when you call array_walk_recursive?
What I don't understand is why it did not append to the string as it
walked through each key/value pair.
It seems like even though the variable inside the function called by
array_walk_recursive has the same name as a global variable, it gets
treated as if it only has local scope and nothing done to it applies to
the global variable.
--
Dave M G
--- End Message ---
--- Begin Message ---
Hi,
Well, first array_walk_recursive returns a boolean so what you are doing in
you script is append a boolean (true or false) that will be converted to
string. So if array_walk_recursive will return true you will have the string
"1" in $karamohOutput['test'], and if array_walk_recursive will return false
you will have the empty string "" in $karamohOutput['test'].
I think what you're after is this:
$karamohOutput['test'] = "";
foreach ( new RecursiveIteratorIterator( new RecursiveArrayIterator(
$karamohArray ) ) as $key => $item ) {
$karamohOutput['test'] .= "$key holds $item\n";
}
On Thu, Feb 24, 2011 at 5:15 PM, Dave M G <[email protected]> wrote:
> FeIn,
>
> Thank you for responding.
>
>
> > what did you expect to happen when you call array_walk_recursive?
>
>
> What I don't understand is why it did not append to the string as it
> walked through each key/value pair.
>
> It seems like even though the variable inside the function called by
> array_walk_recursive has the same name as a global variable, it gets
> treated as if it only has local scope and nothing done to it applies to
> the global variable.
>
> --
> Dave M G
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On 24 February 2011 15:15, Dave M G <[email protected]> wrote:
> FeIn,
>
> Thank you for responding.
>
>
>> what did you expect to happen when you call array_walk_recursive?
>
>
> What I don't understand is why it did not append to the string as it
> walked through each key/value pair.
>
> It seems like even though the variable inside the function called by
> array_walk_recursive has the same name as a global variable, it gets
> treated as if it only has local scope and nothing done to it applies to
> the global variable.
>
> --
> Dave M G
<?php
function changeName($name) {
echo "My name is $name.\n";
$name = 'Simon';
echo "My name is $name.\n";
}
$name = 'Richard';
echo "My name is $name.\n";
changeName($name);
$name = 'Richard';
echo "My name is $name.\n";
?>
Read about variable scope at [1].
Richard.
[1] http://docs.php.net/manual/en/language.variables.scope.php
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
Hi.
Brain being a little slow today.
My objective is to enforce a parameter to a method to be an array of a
specific class (or null).
The specific class is LatLng.
I want to be able to pass an array of LatLngs to a method.
I know I can hint this as ...
function(array $LatLngs) {...}
and then in the array processing loop, use ...
if ($element instanceof LatLng) {...}
But I have a LOT of different types that can exist in arrays and I
want to enforce the commonality of the type.
I think I need a class of LatLngs and this has to implement an
Traversable and ArrayAccess interfaces.
But I'm not sure.
Anyone got any clues / reading?
Thanks.
Richard.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
On 24 February 2011 12:43, Richard Quadling <[email protected]> wrote:
> Hi.
>
> Brain being a little slow today.
>
> My objective is to enforce a parameter to a method to be an array of a
> specific class (or null).
>
> The specific class is LatLng.
>
> I want to be able to pass an array of LatLngs to a method.
>
> I know I can hint this as ...
>
> function(array $LatLngs) {...}
>
> and then in the array processing loop, use ...
>
> if ($element instanceof LatLng) {...}
>
> But I have a LOT of different types that can exist in arrays and I
> want to enforce the commonality of the type.
>
>
> I think I need a class of LatLngs and this has to implement an
> Traversable and ArrayAccess interfaces.
>
> But I'm not sure.
>
> Anyone got any clues / reading?
>
> Thanks.
>
> Richard.
>
> --
> Richard Quadling
> Twitter : EE : Zend
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
>
And it seems that ArrayObject is my start point.
Richard.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
"Steve Staples" <[email protected]> wrote in message
news:1298492194.14826.2425.camel@webdev01...
> On Wed, 2011-02-23 at 14:56 -0500, Gary wrote:
>> "Steve Staples" <[email protected]> wrote in message
>> news:1298490417.14826.2418.camel@webdev01...
>> > On Wed, 2011-02-23 at 14:17 -0500, Gary wrote:
>> >> "Jim Lucas" <[email protected]> wrote in message
>> >> news:[email protected]...
>> >> > On 2/23/2011 4:35 AM, Gary wrote:
>> >> >> "Pete Ford" <[email protected]> wrote in message
>> >> >> news:[email protected]...
>> >> >>> This bit?
>> >> >>>
>> >> >>> On 22/02/11 22:06, Gary wrote:
>> >> >>>> for($i=1; $i<=$_POST['counties']; $i++) {
>> >> >>>> if ( isset($_POST["county{$i}"] ) ) {
>> >> >>>
>> >> >>> You loop over $_POST['counties'] and look for $_POST["county$i"]
>> >> >>>
>> >> >>> I suspect that there is no field 'counties' in your form, so the
>> >> >>> server
>> >> >>> is
>> >> >>> complaining about the missing index - seems likely that the
>> >> >>> production
>> >> >>> server
>> >> >>> is not showing the error, but instead just giving up on the page.
>> >> >>>
>> >> >>> I think the IE7/Firefox browser difference is a red herring: it
>> >> >>> wasn't
>> >> >>> actually working in any browser, or the code changed between
>> >> >>> tests.
>> >> >>> Remember, PHP is server side and generates HTML (or whatever).
>> >> >>> Unless
>> >> >>> you
>> >> >>> tell the PHP what browser you are using and write PHP code to take
>> >> >>> account
>> >> >>> of that (not generally recommended) then the server output is the
>> >> >>> same
>> >> >>> regardless of browser.
>> >> >>>
>> >> >>> --
>> >> >>> Peter Ford, Developer phone: 01580 893333 fax:
>> >> >>> 01580
>> >> >>> 893399
>> >> >>> Justcroft International Ltd.
>> >> >>> www.justcroft.com
>> >> >>> Justcroft House, High Street, Staplehurst, Kent TN12 0AH
>> >> >>> United
>> >> >>> Kingdom
>> >> >>> Registered in England and Wales: 2297906
>> >> >>> Registered office: Stag Gates House, 63/64 The Avenue, Southampton
>> >> >>> SO17
>> >> >>> 1XS
>> >> >>
>> >> >>
>> >> >> Pete
>> >> >>
>> >> >> Once again, thank you for your help.
>> >> >>
>> >> >> I was able to get it to work, I did not understand the browser
>> >> >> differences
>> >> >> either, but on my testing server on IE, it worked as I wanted but
>> >> >> not
>> >> >> on
>> >> >> anything else. I chopped out most of the code and ended up with
>> >> >> this:
>> >> >>
>> >> >> if ( isset($_POST['submit']) ) {} else {
>> >> >> print "<form action=\"phpForm3.php\" method=\"POST\">\n";
>> >> >> if ($Recordset1) {
>> >> >> print "<table width=200 border=1>\n";
>> >> >> print "<th> </th>\n";
>> >> >> print "<th> State </th>\n"; //2 fields in Counties table, State and
>> >> >> County
>> >> >> print "<th> County </th>\n";
>> >> >> print "</tr>\n";
>> >> >> //create table
>> >> >> $i = 0;
>> >> >> while ( $row = mysql_fetch_array($Recordset1) ) {
>> >> >> $i++;
>> >> >> print "<tr>\n";
>> >> >> print "<td><input type=\"checkbox\" name=\"county$i\"
>> >> >> value=\"$row[name]\"></td>\n";
>> >> >> echo "<td>{$row['state_id']}</td>\n";
>> >> >> echo "<td>{$row['name']}</td>\n";
>> >> >> echo "</tr>\n";
>> >> >> }//end while
>> >> >> print "</table>\n";
>> >> >> } else {
>> >> >> echo("<P>Error performing query: " .
>> >> >> mysql_error() . "</P>");
>> >> >> }
>> >> >> print "<input type=\"hidden\" name=\"counties\" value=\"$i\"/>\n";
>> >> >> print "<input type=\"submit\" name=\"submit\" value=\"Go\"/>\n";
>> >> >> }
>> >> >> ?>
>> >> >>
>> >> >> Again, thank you.
>> >> >>
>> >> >> Gary
>> >> >>
>> >> >> __________ Information from ESET Smart Security, version of virus
>> >> >> signature database 5899 (20110223) __________
>> >> >>
>> >> >> The message was checked by ESET Smart Security.
>> >> >>
>> >> >> http://www.eset.com
>> >> >>
>> >> >
>> >> > If you would allow me to show you a little easier way of doing this.
>> >> >
>> >> > if ( !isset($_POST['submit']) ) {
>> >> > echo '<form action="phpForm3.php" method="POST">';
>> >> > if ($Recordset1) {
>> >> > echo <<<HEADER
>> >> > <table width=200 border=1>
>> >> > <tr><th> </th><th> State </th><th> County </th></tr>
>> >> > HEADER;
>> >> > while ( $row = mysql_fetch_array($Recordset1) ) {
>> >> > echo <<<ROW
>> >> > <tr>
>> >> > <td><input type="checkbox" name="county[]"
>> >> > value="{$row['name']}"></td>
>> >> > <td>{$row['state_id']}</td>
>> >> > <td>{$row['name']}</td>
>> >> > </tr>
>> >> > ROW;
>> >> > }//end while
>> >> > echo '</table>';
>> >> > } else {
>> >> > echo '<p>Error performing query: '.mysql_error().'</p>';
>> >> > }
>> >> > echo '<input type="submit" name="submit" value="Go" />';
>> >> > }
>> >> >
>> >> > Now, the main thing I want you to see is the line for the country
>> >> > checkbox'es
>> >> >
>> >> > The county[] turns the submitted values into an array. So, in the
>> >> > processing
>> >> > script, you would do this.
>> >> >
>> >> > <?php
>> >> >
>> >> > ...
>> >> >
>> >> > if ( !empty($_POST['county'])
>> >> > foreach ( $_POST['county'] AS $id => $name )
>> >> > echo "{$id} {$name}\n";
>> >> >
>> >> > ...
>> >> > ?>
>> >> >
>> >> > Hope this clears things up for you a little.
>> >> >
>> >> > Enjoy.
>> >> >
>> >> > Jim
>> >>
>> >> In a weird twist, I have/had the script working, but again it is not
>> >> working in FF or Chrome. This is a link to the first page which runs
>> >> you
>> >> through the pages.
>> >>
>> >> I have the submit to trigger upon change so there is no submit button.
>> >> This
>> >> works in IE7. If I add a submit button, it does not work in any of
>> >> them.
>> >>
>> >> I am wondering if this is more a problem with the html.
>> >>
>> >>
>> >> http://www.assessmentappeallawyer.com/forum_state.php
>> >>
>> >> This is the code for the first processing page
>> >>
>> >> if ( !isset($_POST['submit']) ) {
>> >> echo '<form action="forum_delete.php" method="POST">';
>> >> if ($Recordset1) {
>> >> echo <<<HEADER
>> >> <table width=200 border=0>
>> >> <tr><th> </th><th> State </th><th> County </th></tr>
>> >> HEADER;
>> >> while ( $row = mysql_fetch_array($Recordset1) ) {
>> >> echo <<<ROW
>> >> <tr>
>> >> <td><input type="checkbox" name="county[]"
>> >> value="{$row['name']}"></td>
>> >> <td>{$row['state_id']}</td>
>> >> <td>{$row['name']}</td>
>> >> </tr>
>> >> ROW;
>> >> }//end while
>> >> echo '</table>';
>> >> } else {
>> >> echo '<p>Error performing query: '.mysql_error().'</p>';
>> >> }
>> >> echo '<input type="submit" name="submit" value="Select" />';
>> >> }
>> >>
>> >> ?>
>> >>
>> >> ****This is the code for the second processing page.
>> >>
>> >>
>> >> <?php
>> >>
>> >>
>> >> if ( !empty($_POST['county']))
>> >> foreach ( $_POST['county'] AS $id => $name )
>> >> echo 'You have selected '. " {$name}".'<br />';
>> >>
>> >>
>> >>
>> >> $totalRows_county_result_net= "($totalRows_county_result) + (1)";
>> >> echo "[$totalRows_county_result_net]";
>> >> echo "$totalRows_county_result";
>> >> ?>
>> >> </div>
>> >> <!--eo center-->
>> >>
>> >>
>> >> <?php
>> >> $name=$_POST['name'];
>> >> echo 'You have selected'."$name";
>> >>
>> >> ?>
>> >> <?php
>> >> mysql_free_result($county_result);
>> >> ?>
>> >>
>> >> Again, thank you for any input.
>> >>
>> >> Gary
>> >
>> > I think it may have to do with HTML, or the fact that IE is "helping"
>> > you with your coding... where FF and Chrome are usually more
>> > "literal" (yet better IMO). Also, the fact that "submit" has not been
>> > defined.
>> >
>> > try adding:
>> > <input type="submit" name="submit" value="submit" style="display:
>> > none;" />
>> >
>> > This *SHOULD* give you the submit button, but the style is "hidden"
>> > now,
>> > so it shouldn't show, but it will fire off the "submit" action... make
>> > sure it is in between the <form></form> tags though.
>> >
>> > Steve
>> >
>> Steve
>>
>> Thank you for your reply, I had inserted a submit button prior, but it
>> did
>> not work. I tried your suggestions and got the same result. I am not
>> seeing anything in the html that should be causing the hick-up, but given
>> the php is run on the server as Peter pointed out, browser issues with
>> php I
>> have not really encountered before.
>>
>> I can live with a submit button, but living with one that does not
>> work...
>>
>> Thank you for your input, if you see anything else that seems amiss,
>> please
>> let me know.
>>
>> Gary
>>
>
> the <form onchange="submit"> as far as I know, isn't a standard/valid
> html attribute... so I would remove it altogether.
> http://www.w3schools.com/tags/tag_form.asp
>
>
> and try on the <select ... onchange=""> to be
> <select .... onchange="document.forms["Form1"].submit();">
> where Form1 is the id of the form (so add that to the <form...>
> <form id="Form1" ... >
>
> try that... (i haven't been testing... my fault... but I am in the midst
> of work right now to really test it out)
>
> good luck!
>
> Steve
Thank you to everybody that has helped. As it is now, I have the checkboxes
appearing in all browers, but I am unable to pass the "checked" values to
the next page which echo's the choices.
The page that produces the checkboxes is here: (and this works fine)
if ( isset($_POST['submit']) ) { // if form is submitted, process it
print "<form action=\"phpForm3.php\" method=\"POST\">\n";
if ($Recordset1) {
print "<table width=200 border=0>\n";
print "<th> </th>\n";
print "</tr>\n";
//create table
$i = 0;
while ( $row = mysql_fetch_array($Recordset1) ) {
$i++;
print "<tr>\n";
print "<td><input type=\"checkbox\" name=\"county$i\"
value=\"$row[name]\"></td>\n";
/*echo "<td>{$row['state_id']}</td>\n";*/
echo "<td>{$row['name']}</td>\n";
echo "</tr>\n";
}//end while
print "</table>\n";
} else {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
}
print "<input type=\"hidden\" name=\"counties\" value=\"$i\"/>\n";
print "<input type=\"submit\" name=\"submit\" value=\"Go\"/>\n";
}?>
***************
My query on phpForm3.php is
$query_county_result = "SELECT * FROM counties WHERE name = 'checked' ";
Which is to be displayed by
if ( !empty($_POST['county']))
foreach ( $_POST['county'] AS $id => $name )
echo 'You have selected '. " {$name}".'<br />';
I get a blank page and mysql_num_row returns 0
Again, sorry I am not getting this and thank you for all your help.
Gary
__________ Information from ESET Smart Security, version of virus signature
database 5904 (20110224) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---