Page 1 of 1

counter / adder function

Posted: Tue Jul 29, 2008 2:10 pm
by dyluck
I need some help to build this function and then call it.
Seems easy, but for me not :-P
I have input checkboxes that contain the word "item" in the id= tag.
As the database starts to populate it's array to the table / form using a while loop,
I would like this function to count the existing "item"s and then place the number after "item" that it corrisponds to the number of "item"+1 to on the fly.
(it's for a checkbox limiter that requires sequencial numbers)

Code: Select all

function itemcount($fieldData) {
    global $itemCount;
    $itemCount++;
 
    if ($fieldData['id'] = 'item') {
        $fieldData['id'].=$itemCount;
    }
 
    //rest of script to display the field (this is where I need more help)
}
The last part is, how to i call the function?

ie. <input type="checkbox" id="item'.function(itemcount).'" name = "stream[]" onclick="setItems(this.form);">

Another option would be if someone knows how to index the number of rows pulled in a query and then echo the generated indexed row number corrisponding with the particular row being displayed in the loop.

Re: counter / adder function

Posted: Tue Jul 29, 2008 4:42 pm
by Chalks
you're going to want something like this (I think).

Code: Select all

<form>
<?php
  for($i=0; $i < $itemListArray.length; $i++)
    echo "<input type=\"checkbox\" id=\"$itemListArray[$i]($i)\" name=\"stream[]\" onclick=\"dostuff(this.form)\" />";
?>
</form>
This is very rough (and untested). It should give you the basic idea though. If you want to use a mysql query instead, do something like this:

Code: Select all

<?php
$i = 0;
  while($row = mysql_fetch_assoc($mysqlResource))
  {
    echo "row number is: $i";
    echo "data is: " . $row['item'];
    $i++;
  }
?>
Again, rough and untested. :)

Re: counter / adder function

Posted: Tue Jul 29, 2008 11:08 pm
by dyluck
Hi Chalks
I chose to use the later, so easy and it works perfectly!
Thanks for your help!

PS: I am praying for US and Canada too! (we are in the same boat)
http://www.godtube.com/view_video.php?v ... fc7b2c449f

Cheers brother!