Jump to content

Recommended Posts

I apologize I didn't test that piece of code, I just wrote it, rather quickly at that.

 

Here is another method.

 

This is where it came from.

http://us.php.net/count

 

 

<?php
$food = array('cat' => array('orange', 'banana', 'apple'),
              'veggie' => array('carrot', 'collard', 'pea'));

// recursive count
echo count($food, COUNT_RECURSIVE); // output 8

// normal count
echo count($food); // output 2

?>

 

 

May I also see the code you used that gave you the '1' output?

<?
include("/home/content/g/e/r/gereb/html/ps3t/config22.php");       

$tro=mysql_query("SELECT userid,val FROM playertrophy WHERE userid=1");
while(list($userid,$val)=mysql_fetch_row($tro)){



echo count($val);
}

?>

 

what i got now still geting 1

<?php

include("/home/content/g/e/r/gereb/html/ps3t/config22.php");     

$query = "SELECT userid,var FROM playertrophy WHERE userid=1 ";

$result=mysql_query($query) or die("Error: ". mysql_error. " with query ". $query);

$stuff = mysql_fetch_array($result);

echo count($stuff['var']);

?>

<?php
include("/home/content/g/e/r/gereb/html/ps3t/config22.php");       
$query = "SELECT userid,var FROM playertrophy WHERE userid=1 ";
$result=mysql_query($query) or die("Error: ". mysql_error. " with query ". $query);
$stuff = mysql_fetch_array($result);
echo count($stuff['var']);
?>

 

 

still just gives me a 1

If the field contains a comma separated list, you need to use the explode() function on it to get an array and then count the elements in that array:

<?php
include("/home/content/g/e/r/gereb/html/ps3t/config22.php");       
$query = "SELECT userid,var FROM playertrophy WHERE userid=1 ";
$result=mysql_query($query) or die("Error: ". mysql_error. " with query ". $query);
$stuff = mysql_fetch_array($result);
echo count(explode(',',$stuff['var']));
?>

 

Ken

 

If the field contains a comma separated list, you need to use the explode() function on it to get an array and then count the elements in that array:

<?php
include("/home/content/g/e/r/gereb/html/ps3t/config22.php");       
$query = "SELECT userid,var FROM playertrophy WHERE userid=1 ";
$result=mysql_query($query) or die("Error: ". mysql_error. " with query ". $query);
$stuff = mysql_fetch_array($result);
echo count(explode(',',$stuff['var']));
?>

 

Ken

 

 

thank you i ben looking all day and could not find a way to get it to work but this worked thanks

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.