RE: [PHP] Query to select every other record
| From: | David Freeman | Date: | Mon, 18 Nov 2002 03:19:06 +0000 |
| Subject: | RE: [PHP] Query to select every other record | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-124860@lists.php.net to get a copy of this message | ||
> Does anybody know of a SELECT QUERY that will select every
> other record of a
> table ? I want to do this so that I can display my products
> in 2 columns (I
> will also be using arrays of course).
Don't know of a select that'll do it, but then I don't really understand
why you'd want to either.
(UNCHECKED psuedo code)
$query_result = mysql_query("whatever");
Check_that_you_got_a_result();
{
start_your_html_table_to_display_stuff();
start_first_row_of_table();
while(grab_a_row_from_query_result())
{
if (havent_started_first_column())
{
print_a_line_of_data();
close_first_column();
start_second_column();
} else {
print_a_line_of_data();
close_second_column();
close_table_row();
start_table_row();
}
}
if (still_in_first_column())
{
close_column();
}
close_table();
}
Well, something like that anyway - I haven't fully considered closing
off your rows and table properly but that's pretty much what I'd do to
make this work, and it still only needs one db query.
CYA, Dave