Solarpitch Posted December 21, 2006 Share Posted December 21, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/31530-quick-question-counting-the-values-in-an-array/ Share on other sites More sharing options...
obsidian Posted December 21, 2006 Share Posted December 21, 2006 There's no way at all for us to know exactly what you're doing without knowing how you are setting up your session. It looks like you're retrieving the values for some reason instead. Quote Link to comment https://forums.phpfreaks.com/topic/31530-quick-question-counting-the-values-in-an-array/#findComment-146084 Share on other sites More sharing options...
Solarpitch Posted December 21, 2006 Author Share Posted December 21, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/31530-quick-question-counting-the-values-in-an-array/#findComment-146087 Share on other sites More sharing options...
HuggieBear Posted December 21, 2006 Share Posted December 21, 2006 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?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31530-quick-question-counting-the-values-in-an-array/#findComment-146132 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.