Jump to content

My franken script project!


xtian

Recommended Posts

My little project is to display one MYSQL query accross 4 columns (A,B,C,D). Each column is a separate div. Each div will contain a new separate table.

 

Here is my strategy to divide one MYSQL query into four separate arrays (1-4)

1) start with MYSQL query and single $dbq_record_set (ex. 100 total records);

 

2) Divide: (total number of records) 100/4 (number of columns) equals (default number of records per column) 25;

 

3) Create four variables for each column using #2 base value. (EG. $col_A_records, $col_B_records, $col_C_records, $col_D_records);

 

4) Divide $dbq_record_set (100) into four arrays using column variables $col_A-D_records. (EG. $n_array_1[records 1-25], $n_array_2[records 26-50], $n_array_3[records 51-75], $n_array_4[records 76-100]);

 

5) Start a table;

6) Loop--Assign one record at a time to ASSOC arry with mysql_fetch_array($n_array_1) = $a_array_1;

6.1) Print each record's contents in a table using $a_array_1["col_name"] for how many bits of data in each record;

 

7) Use 'some kind of conditional statement' to adjust number of records assigned to each column with variable #3 at location #4;

 

Questions? I got the idea. It would be helpful if anyone recognizes this and can suggest changes before I procede to code.

 

xtian

Link to comment
Share on other sites

If you want those 4 columns to dynamically expand use something like:

 

SELECT field, field, count(*) AS total_rows FROM table LIMIT floor(total_rows / 4) * 4

 

(not sure you can use functions in the LIMIT-clause, the Math may be improved to)

 

Or if each column has a pre-defined number of items (assume 10 for each column), use:

 

SELECT field, field FROM table LIMIT 40

Link to comment
Share on other sites

Hmmm. I hadn't thought about separating the data in the request.

 

1) Not sure if you can use math functions in MYSQL request? Then what gave you the idea? I don't understand.

 

2) My idea was to take the request and parse the result into chunks from an array based on a PHP script. I imagined this would allow me to adjust each chunk if one of them is grossly too large to make the page look balanced and "pretty". What would be the benefit of doing this procedure in the initial request from the SQL db? What logic would make it, as you say, "dynamically expand"?

 

This is exactly what I wanted to hear from the community. An alternative way to approach the problem. I'm just not seeing the benefits yet.

 

3) I'm not sure I completely understand the logic in code snip #2. You write LIMIT 40, and above suggest 10 items for each column. With my example using 100 total records I do not understand either of these numbers.

 

C

Link to comment
Share on other sites

2) My idea was to take the request and parse the result into chunks from an array based on a PHP script. I imagined this would allow me to adjust each chunk if one of them is grossly too large to make the page look balanced and "pretty". What would be the benefit of doing this procedure in the initial request from the SQL db? What logic would make it, as you say, "dynamically expand"?

 

By dynamically expand I mean to balance all columns, each column will contain the same number of items as the other columns. No column has a limit, so each column may contain up to 25 and more items. It has also a disadvantage to hide data when the number of items in the database is not a product of 4. For example when the database contains 7 items only the first 4 are shown, as it would otherwise unbalance the columns.

 

If you however only want to show 10 items in each column at any given time then you could use

 

LIMIT 40

Link to comment
Share on other sites

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.