Announcement

Collapse
No announcement yet.

for loop on a record set

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • for loop on a record set

    sc_lookup(rs, $check_sql);

    if (!empty({rs}))
    {
    $datasetCount = count({rs}); // returns count of array items of any array
    echo "<h1>There are $datasetCount Rows</h1>";
    $i = 0;

    // trying to loop throught the multidementional array

    for($i=0; i < $datasetCount; i++)
    {
    for($j=0; j < $datasetCount[i]; j++)
    {

    echo {rs}[i][j];

    }
    }

    }
    i want to be able to access the two values in each array.
    instead am getting input boxes to enter values for i & j.
    the values are to be manipulated.
    the structure of the array is like this:
    [2,4]
    [5,6]

    i need to put 2 & 4 into separate variables

  • #2
    PHP Code:
    echo {rs}[i][j]; 
    Try
    echo {rs}[$i][$j];
    /Giuseppe

    Professional Scriptcase Services
    Some Customers opinions

    Comment


    • #3
      Because you have forgotten to add the $ and now I and j are considered to be global variables.

      for($i=0; i < $datasetCount; i++)
      {
      for($j=0; j < $datasetCount[i]; j++)
      {

      echo {rs}[i][j];

      should be

      for($i=0; i < $datasetCount; $i++)
      {
      for($j=0; j < $datasetCount[i]; $j++)
      {

      echo {rs}[$i][$j];
      Albert Drent
      aducom software netherlands
      scriptcase partner, reseller, support and (turn-key) development
      www.scriptcase.eu / www.scriptcase.nl

      Comment


      • #4
        Originally posted by aducom View Post
        Because you have forgotten to add the $ and now I and j are considered to be global variables.
        should be

        for($i=0; i < $datasetCount; $i++)
        {
        for($j=0; j < $datasetCount[i]; $j++)
        {

        echo {rs}[$i][$j];
        and for($j=0; j < $datasetCount[i]; $j++) should be for($j=0; j < $datasetCount[$i]; $j++) too
        /Giuseppe

        Professional Scriptcase Services
        Some Customers opinions

        Comment

        Working...
        X