简体   繁体   中英

MySQL query result split

This is somewhat of a multipart question, but..

I am looking to query a MySQL table to get fields from a event category table.

Each category has a specific calendar assigned to it, in the "calendar" field in the category table.

I am planning to have a HTML list box for each of the different types of calendars (only 4, and they wont change).

Is there a way to query the category table once, and split the results into different arrays?

Ex.


Sports (only categories assigned to the sports calendar appear here):

(in list box):

Basketball

Baseball

Golf

etc.

then,


General:

(only categories assigned to the general calendar appear here)

etc.

etc.

etc.


I thought to do this in one query, instead of querying the whole table for each calendar type, but will there be that much difference in speed?

I am using PHP, by the way.

Thanks for the help.

You can query the table once and use mysql_data_seek to reset the rowset pointer back to the beginning after having read through it - ie iterate over the rowset for category 1, reset the pointer, iterate over for category 2, etc. You need only query once, and iterating over the results is very fast vs. querying.

Alternatively, have four strings each containing the HTML for the content of one of the listboxes, and iterate over the rowset once, appending to the relevant string based on the category of the current record.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM