Forum Moderators: coopster

Message Too Old, No Replies

Reading out multidimensional array values

         

redbanditos2005

2:16 pm on Jul 4, 2003 (gmt 0)

10+ Year Member



Hi there!

I have an aray like this:


$tmparr = array ( "0" => array ( "0" => 15, "1" => Hello1 ),
"1 => array ( "0" => 16, "1" => Hello2 ),
"2" => array ( "0" => 17, "1" => Hello3 ),
"3" => array ( "0" => 18, "1" => Hello4 ) ) ;

as packed result from mysql_query:


while ($db->next_record()) {
$myarr[0]=$db->f("id");
$myarr[1]=$db->f("title");
$tmparr[]=$myarr;
}

Now I want display the array values in a ordered list, like:


<ol>
<li> Key: 15, Value: Hello1</li>
<li> Key: 16, Value: Hello2</li>
<li> Key: 17, Value: Hello3</li>
<li> Key: 18, Value: Hello4</li>
</ol>

but the clue is, I want to do this with a "Next" submit button.

On page load I make the db query, then I display the first $tmparr value + the "Next" button. After submitting the next $tmparr value shall be displayed under the first value...

Do anyone has a quick solution for this?

Many greeeetz && thxss...

jatar_k

4:27 pm on Jul 4, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You only want to show one at a time?

First time there is only 1 row
click next
now there are 2 rows
click next
now there are 3 rows

is that what you are saying or are we talking page by page?

You could use a limit/range/or both in your select query and pass the values to use in the query when you click the next button.

redbanditos2005

7:59 am on Jul 7, 2003 (gmt 0)

10+ Year Member



Hi Jatar_k!

I think both possibilities could be interesting ;-).
Lets say explain me your soultions - and how limit/range works (there is not much about them in MySql Doc :-(( ).

My quick solution for now is to set a hidden field with

$countvar= (isset($nextbutton))? $countvar-1 : count($tmparr);
and passing thru to display the arrvalues page by page ($PHP_SELF)...

jatar_k

5:27 pm on Jul 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think the best bet is page by page really.

What I usually do is pass a results per page value, which could also be hard coded depending on your needs, and a start number.

The start number could be the id of the first row to display or the id of the last row displayed. I then use them in my select statement.

$show = 20; // results per page
$start = 336; // last row displayed

These values could be passed as either GET or POST. Assuming I have been showing rows in order of ascending id and the values are passed via GET I could then do something like this

$sql = "select * from table where id > " . $_GET['start'] . " limit " . $_GET['show'];

then I would need to build into my next link the proper values after diaplaying the results for this page.

$start += $show;
echo "<a href=\"searchpage.php?start=$start&show=$show\">Next</a>";