Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplay partial results from a mysql query
    text
    copied!<p>I have a sql query that pulls all types of data from 3 different tables that I now want to display in an array. I can get it to output all the data from the sql query, but I only want to display part of the array at a time based on if the value of the column in table is the same. Will try to demonstrate below.</p> <p>My sql result looks like this:</p> <pre><code>Client | Order | Exc1 | Exc2 | Rest | Reps | ------------------------------------------------------- Steve | 1A | this | That | This | that | ------------------------------------------------------- Mike | 1A | this | That | This | that | ------------------------------------------------------- Jax | 1A | this | That | This | that | ------------------------------------------------------- Steve | 1B | this | That | This | that | ------------------------------------------------------- Mike | 1B | this | That | This | that | ------------------------------------------------------- Jax | 1B | this | That | This | that | </code></pre> <p>I want my array to output this on a page1</p> <pre><code>Steve | 1A | this | That | This | that | ------------------------------------------------------- Mike | 1A | this | That | This | that | ------------------------------------------------------- Jax | 1A | this | That | This | that | </code></pre> <p>And this on page 2 and so on. Each page will contain a list of all clients and only one order value per page. The order column value will vary for each user as they will be able to input there own text for the order field. Is this possible and if so how is the best way possible?</p> <p>@Gordon Linoff here is my current query. I dont really understand what you wrote or more of how it would relate to my query. below id my current query. I did not finish outputting into array. I just have this as I was testing until I got the results I wanted.</p> <pre><code>function get_workout_class(){ $workout_class = array(); $workout_query = mysql_query(" SELECT * FROM `movements` LEFT JOIN `classes` ON `movements`.`class_id` = `classes`.`class_id` LEFT JOIN `clients` ON `movements`.`class_id` = `clients`.`class_id` WHERE `classes`.`class_id` = '$class_id' AND `user_id` = ".$_session['user_id']." ORDER BY `movements`.`order`, `clients`.`first_name` "); </code></pre> <p>}</p> <p>Here is a screen shot of my query result so you can see how I want them grouped. Pages to be split by different "order" values. The number of clients will vary from class to class.</p> <p><a href="http://custommovement.com/help/query.png" rel="nofollow">http://custommovement.com/help/query.png</a></p> <p>Here is my new query. The first part works just fine but the subquery is giving my problems. Its not pulling any results. @GordonLinoff</p> <pre><code>function get_workout_class($class_id){ $class_id = (int)$class_id; $workout_class = array(); $workout_query = mysql_query(" WITH `workouts` as ( SELECT `movements`.`movement_id`, `movements`.`order`, `movements`.`mv_00`, `movements`.`mv_01`, `movements`.`mv_02`, `movements`.`mv_03`, `movements`.`mv_04`, `movements`.`rep_set_sec`, `movements`.`rest`, `classes`.`class_name`, `clients`.`client_id`, `clients`.`first_name`, `clients`.`last_name`, `clients`.`nickname` FROM `movements` LEFT JOIN `classes` ON `movements`.`class_id` = `classes`.`class_id` LEFT JOIN `clients` ON `movements`.`class_id` = `clients`.`class_id` WHERE `classes`.`class_id` = '$class_id' ) SELECT `wo`.* (SELECT COUNT(DISTINCT `order`) FROM `workouts` `wo2` WHERE `wo2`.`order` &lt;= `wo`.`order`) as `pagenum` FROM `workouts` `wo` ORDER BY `pagenum` "); echo mysql_num_rows($workout_query); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload