What I've managed to do is create my own multidimensional array....with a technique slightly different than i got from help on this site.

From there, what Im looking at doing is splitting the results by 3 to show 3 entries per page. Unfortunately, I can only get the first 3 entries to display. I've used
global $array;
global $newsarray;
$array = shift_array($newsarray)....

expecting the value of the arrays to change throughout the script.

Here we go:

PHP:

<?php
include 'db.php';
function test()

{

if ($GET['numrows']) {
$numrows = $
GET['numrows'];
}//end if
$dbhost = "notshown";
$dbuser = "notshown";
$dbpass = "notshown";
$dbtable = "notshown";
$sql = "select * from earticles where bgroup='internet'";
$db1 = new DB();
$db1->connectMysqlDB($dbhost,$dbuser,$dbpass);
$db1->selectMysqlDB($dbtable);
$results = $db1->queryMysqlDB($sql);
if (! $numrows ) {
$numrows = mysql_num_rows($results);
}//end if
$numpage = ($numrows / 3);
//echo("numrows: ($numrows), numpage: ($numpage)<br>\n");
$newsarray=array();
$array1 = array();

global $array1;
global $newsarray;

while ($row = mysql_fetch_array($results, MYSQL_ASSOC))    
{   
   $id = $row['id']; 
   $author = $row['author']; 
   $preview = $row['preview']; 
   $full = $row['full']; 
   $size = $row['size']; 
   $date = $row['date']; 
   $bgroup = $row['bgroup']; 

   $newsarray[$id] = array("$id","$author","$preview","$full","$size","$date","$bgroup"); 
}//end while 
//$arraysize = count($newsarray); 
//echo("count: ($arraysize)<br>\n"); 
while ($numpage >= 0) { 
    echo("numrows: ($numrows)\tdisplay single article<br>\n"); 
    if ($numrows >= 3) { 
    for ($i=0; $i <= 2; $i++) { 
         $array1 = array_shift($newsarray); 
        $sarray1 = count($array1); 
        printArray($array1); 
    }//end for 
    $numrows = $numrows -3; 
    $numpage--; 
    echo("<strong><a href='http://www.winnipegbeach.com/elektrus/multiarray.php?numrows=$numrows'>More</a></strong><br>\n");         
    exit();         

    }//end if 

    elseif ( ($numrows > 0) && ($numrows < 3) ) { 
         for ($i=1; $i <= $numrows; $i++) { 
        $array1 = array_shift($newsarray); 
        $sarray1 = count($array1); 
            printArray($array1); 
        }//end for 

        $numrows = $numrows -3; 
        $numpage--; 
        echo("<strong><a href='http://www.winnipegbeach.com/elektrus/multiarray.php?numrows=$numrows'>More</a></strong><br>\n");         
         }//end for 
    exit(); 
    }//end elseif 
        elseif ($numrows < 0) { 
        for ($i=0; $i <= $numrows; $i++) { 
            $array1 = array_shift($newsarray); 
        $sarray1 = count($array1); 
        printArray($array1); 
            }//end for 
         $numrows = $numrows -3; 
         $numpage--; 
         echo("<strong><a href='http://www.winnipegbeach.com/elektrus/multiarray.php?numrows=$numrows'>More</a></strong><br>\n");         

    }//end elseif 
    $numrows = $numrows -3; 
    $numpage--; 
        exit(); 
}//end while 

}//end function test()

function printArray($array1) {
echo("in printarray($array)<br>\n");
foreach($array1 as $index => $value) {
echo("in printarray: ($index), ($value)<br>\n");
}//end foreach
}//end function printArray($newsarray)

RESULTS

array1: (0), (3)
array1: (1), (Chris Gauthier)
array1: (2), (Another article about NHL Hockey)
array1: (3), (This is the article about the bumbs who have not appreciable skills)
array1: (4), (2000)
array1: (5), (2005-02-15 11:12:11)
array1: (6), (internet)
size of array1: (7)
array1: (0), (6)
array1: (1), (Chris Gauthier)
array1: (2), (NHL Article)
array1: (3), (This is the nhl on strike)
array1: (4), (1500)
array1: (5), (2005-02-16 11:12:12)
array1: (6), (internet)
size of array1: (7)
array1: (0), (7)
array1: (1), (Chris Gauthier)
array1: (2), (NHL Article)
array1: (3), (This is the nhl on strike)
array1: (4), (1500)
array1: (5), (2005-02-16 11:12:12)
array1: (6), (internet)
size of array1: (7)
More[next 3, etc]


Now, these results are good...but I need the next 3 rows of the table to show on a click of the more.

Anyhelp would be lovely.

Thanks.

    So, you need to store your entire resultset (in memory, or filesystem) which might not be the best way, or you need to limit your queries to $numrows, set a marker somehow, and start from that point on the next page. You often see this done, generally by passing the "start point" via GET. But, you've got to have your db indexed in such a way as to order the results in the same way and narrow the set down.....

      Hrm...well, what Ive done to get the number of pages and rows displayed properly is this, first:

      echo("<strong><a href='http://www.winnipegbeach.com/elektrus/multiarray.php?numrows=$numrows'>More</a></strong><br>\n"); 
      }//end for 
      

      Which creates a get string that displays the numrows left. Then, i have this:

      
      if ($_GET['numrows']) {
          $numrows = $_GET['numrows'];
      }//end if
      
      
      
      if (! $numrows ) {
           $numrows = mysql_num_rows($results);
      }//end if
      

      This GET has the number of rows remaining...and then i use some logic to the pages printed into 3s. My problem is, that I can't seem to figure out how to get the $newsarray variable to get any records except the first record. My theory is that shifting the global variable array1 should remove the next array and display the newsarray array properly.

      That's this snippet:

      if ($numrows >= 3) {
          for ($i=0; $i <= 2; $i++) {
               $array1 = array_shift($newsarray);
               $sarray1 = count($array1);
               printArray($array1);
          }//end for
          $numrows = $numrows -3;
          $numpage--;
          echo("<strong> <ahref='http://www.winnipegbeach.com/elektrus/multiarray.php?numrows=$numrows'>More</a></strong><br>\n");	    exit();		
      
      }
      

      The array_shift function should (in my mind) shift off the top element in the array and print it...never to hear from it again.
      So that the next piece of logic can print the next arrays:

      I'm expecting to get $newsarray[3,4,5] to be printed

      elseif ( ($numrows > 0) && ($numrows < 3) ) { 
          for ($i=1; $i <= $numrows; $i++) { 
              $array1 = array_shift($newsarray); 
              $sarray1 = count($array1); 
              printArray($array1); 
      }//end for 
      

      The only way i can explain this behaviour is if newsarray is only in scope withing the for ( ) statments. BUT, its a global variable in the function.

      Again, help would be lovely.

      Take Care
      Ego

        Write a Reply...