Jump to content

Quick question (counting the values in an array?)


Solarpitch

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.