Jump to content

Recommended Posts

If you're just trying to get two columns of 10 results each, have a look at this post, otherwise if you're wanting to echo 10 results, echo other data, then echo 10 more results, you can either use an array, or two queries with the appropriate LIMIT clauses.

If you're just trying to get two columns of 10 results each, have a look at this post, otherwise if you're wanting to echo 10 results, echo other data, then echo 10 more results, you can either use an array, or two queries with the appropriate LIMIT clauses.

So, if I want to echo 10 results, then go to the next column and echo 10 more I'd use that thread you linked to?

Well, I guess it really depends. If it absolutely has to be like this, then no, the link isn't what you need.

111

212

313

414

515

616

717

818

919

1020

 

If this will work, then you can do this with the info in that link.

12

34

56

78

910

1112

1314

1516

1718

1920

I have no idea what the accordions are. Are they javascript/JQuery/whatever?

 

Anyhow, the get the information from the database, you'd build the query string as normal, and store the results in arrays. For simplicity, I'll assume there will be one field, 'name', returned from each record. This is how I'd do it, but this may give you an idea for another way to do it yourself. Once the values are in arrays, you can manipulate them however you need to. Note that I didn't take into account any error handling, or what to do if there are less than 20 results returned.

 

$query = 'SELECT `name` FROM `table` LIMIT 20';
$result = mysql_query( $query );
$i = 1;  // initialize a counter and two empty arrays.
$right_array = array();
$left_array = array();
while( $row = mysql_fetch_assoc($result) ) {
    if( $i < 11 ) { // if $i one of the first ten results, it belongs in left column
        $left_array[] = $row['name'];
    } else {  // if it ain't in the first ten results, it goes in the right column . . .
        $right_array[] = $row['name'];
    }
    $i++;
}

$query = 'SELECT `name` FROM `table` LIMIT 20';
$result = mysql_query( $query );
list($left_array, $right_array) = array_chunk(array_map('mysql_fetch_assoc', array_fill(0, mysql_num_rows($result), $result)), 10);

 

:D

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.