Jump to content

Recommended Posts

Hey,

Yeah, I was just wondering how you count the values in an array.

if I use
[code]
count($_SESSION['quickpick']);

//this gives me "0123456789101112" instead of just "12"
[/code]

Any reason for this or is that just the way its done?
Here's a quick idea of the structure of the session if it helps.

[code]
$_SESSION['quickpick'][] = $_GET['ID'];


http://www.myurl.com/save_quickpick.php?ID=53 <- button

<a href="http://www.myurl.com/save_quickpick.php?ID=53"><img src="..." border=0></a>




for ($i = 0; $i < count($_SESSION['quickpick']); $i++) {

$sql = "SELECT ID FROM database WHERE ID='" . $_SESSION['quickpick'][$i] . "'";
$result = $db->query($sql);
if ($row = $db->fetchrow($reslult)) {
// found ID
} else {
// id not found
}
}
[/code]
The code you've got is correct, to count the number of elements in an array then just use count().

[code=php:0]$total = count($_SESSION['quickpick']);[/code]

Or did you mean you want the total of all the elements in an array added together?

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.