php-general Digest 9 Aug 2011 12:30:55 -0000 Issue 7436
Topics (messages 314431 through 314441):
Re: A php bug or?..
314431 by: Simon J Welsh
314432 by: Daniel P. Brown
314433 by: Andre Polykanine
314434 by: Stuart Dallas
314435 by: Daniel P. Brown
form hidden value
314436 by: Chris Stinemetz
314437 by: Daniel P. Brown
314438 by: Dajka Tamas
pass text variables to next page
314439 by: Chris Stinemetz
314440 by: Tamara Temple
314441 by: Chris Stinemetz
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On 9/08/2011, at 8:20 AM, Andre Polykanine wrote:
> Hi everyone,
>
> As we all know, count() returns 1 if the variable
> is not an array.
> Question is: why in the world does it this? If a variable is *notA* an array,
> it contains *zero* array elements.
> You can answer: "but no, man, you can say
> $x="world";
> $y=$x{3}; // $y="l"
>
> so the variable is treated or can be treated as an array".
> Well. If strings are treated like arrays, why count($x) doesn't return 5
> instead of 1?
> Just asking.
>
> --
> With best regards from Ukraine,
> Andre
I'm assuming it has to do with the value, if not an array or object, being cast
as an array. Thus, non-false equivalent values get cast into an array of size 1:
<?php
var_dump((array)1);
var_dump((array)null);
// Output
array(1) {
[0]=>
int(1)
}
array(0) {
}
---
Simon Welsh
Admin of http://simon.geek.nz/
--- End Message ---
--- Begin Message ---
On Mon, Aug 8, 2011 at 16:20, Andre Polykanine <an...@oire.org> wrote:
> Hi everyone,
>
> As we all know, count() returns 1 if the variable
> is not an array.
> Question is: why in the world does it this? If a variable is *notA* an array,
> it contains *zero* array elements.
> You can answer: "but no, man, you can say
> $x="world";
> $y=$x{3}; // $y="l"
>
> so the variable is treated or can be treated as an array".
> Well. If strings are treated like arrays, why count($x) doesn't return 5
> instead of 1?
> Just asking.
Using count() will return the number of items passed in the first
parameter. If it's an array, each element is an item. If it's a
string, the string is an item. If it's an object, logically, the
items depend on what is contained in the object. However, at no time
does it return the number of characters within a string --- instead,
as you likely know, you'd use strlen().
--
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/
--- End Message ---
--- Begin Message ---
Hello Daniel,
DPB> does it return the number of characters within a string --- instead,
DPB> as you likely know, you'd use strlen().
For sure. But I'm asking: why it doesn't return 0 if it is not an array?
Logically: no array - no items!
--
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion
--- End Message ---
--- Begin Message ---
On 8 Aug 2011, at 21:41, Andre Polykanine wrote:
> DPB> does it return the number of characters within a string --- instead,
> DPB> as you likely know, you'd use strlen().
>
> For sure. But I'm asking: why it doesn't return 0 if it is not an array?
> Logically: no array - no items!
The manual explains what the function does - you may want to check it out cos
it does the same for all the other functions too.
"Returns the number of elements in var. If var is not an array or an object
with implemented Countable interface, 1 will be returned. There is one
exception, if var is NULL, 0 will be returned."
IOW, if you pass it a variable, that has one element, so it returns 1. An array
may have 0 to many elements, and null, logically, has none. Rocket science this
ain't!
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--- End Message ---
--- Begin Message ---
On Mon, Aug 8, 2011 at 16:41, Andre Polykanine <an...@oire.org> wrote:
>
> For sure. But I'm asking: why it doesn't return 0 if it is not an array?
> Logically: no array - no items!
No, actually, if it's a string, it's a single item --- thus, 1.
The documentation should probably reflect that as well. It wasn't
always this way before, though --- in older version of PHP5 it
returned 0, and in all versions of PHP4 it did as well.
Also, keep in mind that a blank string still constitutes a string
and will return 1, but null or nonexistent variables will still return
0.
--
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/
--- End Message ---
--- Begin Message ---
I'm trying to pass a hidden value with my form submission. Not sure what I
am doing woring, but the value is not being passed.
Query is___
$query = "SELECT id, store_name FROM store_list WHERE store_type =
'$type' AND id_market = '$market' " ;
$result = mysql_query($query) or die(report($query,__LINE__ ,__FILE__));
while($row = mysql_fetch_array($result))
{
$store_name[] = $row['store_name'];
$id[] = $row['id'];
}
sort($store_name);
}
Form portion is____
<input type="hidden" name="id" value="<?php echo '$id[]';?>">
Any help is greatly appreciated. Thank you.
--- End Message ---
--- Begin Message ---
On Mon, Aug 8, 2011 at 17:23, Chris Stinemetz <chrisstinem...@gmail.com> wrote:
>
> <input type="hidden" name="id" value="<?php echo '$id[]';?>">
You should drop the quotes around the $id[] array, and also figure
out how you want to extract the element from the array. For example:
<?php echo $id[0]; ?>
--
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/
--- End Message ---
--- Begin Message ---
First: use firebug, or something like that, and check what's get "written"
in the page's source!
Second: dump $_POST/$_GET, and check, whether "id" is set at all
Is your input field between the <form> and </form> tags?
Cheers,
Tamas
-----Original Message-----
From: Chris Stinemetz [mailto:chrisstinem...@gmail.com]
Sent: Monday, August 08, 2011 11:23 PM
To: PHP General
Subject: [PHP] form hidden value
I'm trying to pass a hidden value with my form submission. Not sure what I
am doing woring, but the value is not being passed.
Query is___
$query = "SELECT id, store_name FROM store_list WHERE store_type =
'$type' AND id_market = '$market' " ;
$result = mysql_query($query) or die(report($query,__LINE__ ,__FILE__));
while($row = mysql_fetch_array($result))
{
$store_name[] = $row['store_name'];
$id[] = $row['id'];
}
sort($store_name);
}
Form portion is____
<input type="hidden" name="id" value="<?php echo '$id[]';?>">
Any help is greatly appreciated. Thank you.
--- End Message ---
--- Begin Message ---
I am trying to pass text strings from on page to a next to populate
the queries on the passed to page.
The only way I can get the query to work is if I am able to put single
ticks around the string to make it literal, but I can't seem to figure
out how to do it for the following line of code.
echo '<h3><a href="store.php?id=' . $row['store_name'] . '">' .
$row['store_name'] . '</a><br /><h3>' . $row['store_type'];
When i do a dump the query and
print("<pre>".print_r($_GET,true)."</pre>");
I get the following respectively:
SELECT store_id, store_subject FROM stores WHERE store_subject = Loma
Vista 8712 Blue Ridge BlvdThe topic could not be displayed, please try
again later.You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'Vista 8712 Blue Ridge Blvd' at line 3
The PHP code for the query is:
Array
(
[id] => Loma Vista 8712 Blue Ridge Blvd
)
$sql = "SELECT store_id, store_subject
FROM stores
WHERE store_subject = " . mysql_real_escape_string($_GET['id']);
The query works fine When I run the command in console and place ''
around Loma Vista 8712 Blue Ridge Blvd
Thank you,
Chris
--- End Message ---
--- Begin Message ---
On Aug 8, 2011, at 11:58 PM, Chris Stinemetz wrote:
I am trying to pass text strings from on page to a next to populate
the queries on the passed to page.
The only way I can get the query to work is if I am able to put single
ticks around the string to make it literal, but I can't seem to figure
out how to do it for the following line of code.
echo '<h3><a href="store.php?id=' . $row['store_name'] . '">' .
$row['store_name'] . '</a><br /><h3>' . $row['store_type'];
When i do a dump the query and
print("<pre>".print_r($_GET,true)."</pre>");
I get the following respectively:
SELECT store_id, store_subject FROM stores WHERE store_subject = Loma
Vista 8712 Blue Ridge BlvdThe topic could not be displayed, please try
again later.You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'Vista 8712 Blue Ridge Blvd' at line 3
The PHP code for the query is:
Array
(
[id] => Loma Vista 8712 Blue Ridge Blvd
)
$sql = "SELECT store_id, store_subject
FROM stores
WHERE store_subject = " . mysql_real_escape_string($_GET['id']);
Here, you need to insert single quotes around the search value in the
WHERE cause:
WHERE store_subject = '".mysql_real_escape_string($_GET['id']."'");
If that's hard to read like it is on my mailer, it's:
<
SINGLEQUOTE
>
<
DOUBLEQUOTE
>
<
PERIOD
>
mysql_escape_string
($_GET['id']]<PERIOD><DOUBLEQUOTE><SINGLEQUOTE><DOUBLEQUOTE>
This then surrounds the data in the search string with single quotes
for the SQL query.
The query works fine When I run the command in console and place ''
around Loma Vista 8712 Blue Ridge Blvd
Thank you,
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Thank you Tamara.
Not sure if I am doing it right. It looks like the last single quote
is being escaped.
When I dump the query I get:
SELECT store_id, store_subject FROM stores WHERE store_subject =
'Bella Roe 4980 Roe Blvd\'
I am thinking maybe I have too many single quotes some where, but I
can't find it.
echo '<h4><a href="store.php?id=' . $storerow['store_subject'] . '">'
. $storerow['store_subject'] . '</a></h4> at ' . date('m-d-Y',
strtotime($storerow['store_date']));
The query:
$sql = "SELECT store_id, store_subject
FROM stores
WHERE store_subject = '" . mysql_real_escape_string($_GET['id']."'");
Thank you,
Chris
--- End Message ---