Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple arrays in a while

Tags:

php

mysql

I need a help to solution that: I need to do a table with a value of 4 different my sql arrays, like:

$sql = mysql_query("select * from tbl_work where work_category = 1 
 ORDER BY note DESC");

$sql2 = mysql_query("select * from tbl_work where work_category = 2 
 ORDER BY note DESC");

$sql3 = mysql_query("select * from tbl_work where work_category = 3 
 ORDER BY note DESC");

$sql4 = mysql_query("select * from tbl_work where work_category = 4 
 ORDER BY note DESC");

And I make four arrays with each one:

$find1 = mysql_fetch_array($sql);

$find2 = mysql_fetch_array($sql2);

$find3 = mysql_fetch_array($sql3);

$find4 = mysql_fetch_array($sql4);

Now, I need to do 10 times, a table with value of all of that arrays, but need to be order, without repeat and side by side, split in category.

Like 4 columns, each have order and different value of work_category.

Thank you!

like image 979
Matheus Felipe Santana Avatar asked Feb 04 '26 05:02

Matheus Felipe Santana


1 Answers

Why not change the query to get all results at once:

SELECT * FROM tbl_work WHERE work_category IN (1,2,3,4) ORDER BY note DESC  

P.S: Use PDO, mysql_* are deprecated.

like image 153
ka_lin Avatar answered Feb 06 '26 21:02

ka_lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!