Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop to generate table rows
    primarykey
    data
    text
    <p>I have a dynamic list of gym machines that are being pulled from a database. </p> <p>I want to achieve this:</p> <p><img src="https://i.stack.imgur.com/jhv4l.png" alt="enter image description here"></p> <p>Right now I have 2 different pieces of code that I want to combine. </p> <p>This pulls the machines from the database:</p> <pre><code>$sql1 = "SELECT m1.machine_id, m2.* FROM userPlanDetail AS m1 LEFT JOIN machines AS m2 ON m1.machine_id = m2.machine_id WHERE `user_id` = '$user_id1' AND `cardio` = 0"; $retval1 = mysql_query( $sql1, $conn ); $array = array(); </code></pre> <p>This code creates the pictures:</p> <pre><code>&lt;?php $machine_id = 1; $count = mysql_result(mysql_query("SELECT COUNT(*) FROM `userPlanDetail` WHERE `user_id` = '$user_id1'"), 0); $sql = "SELECT m1.machine_id, m2.* FROM userPlanDetail AS m1 LEFT JOIN machines AS m2 ON m1.machine_id = m2.machine_id WHERE `user_id` = '$user_id1'"; $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { ?&gt; $('&lt;div/&gt;', { 'id': 'div _&lt;?php echo $row["machine_id"]; ?&gt;', 'class': 'some_class_name', 'html': '&lt;img src="client workout page/round_&lt;?php echo $machine_id++ ?&gt;.jpg" style="position:absolute;top:50%;left:0;"&gt;'+ '&lt;img src="&lt;?php echo $row["picture"]; ?&gt;" style="width:200px;height:200px;display:block;margin:20px auto;"/&gt; '+ ' &lt;a class="demo" href="&lt;?php echo $row["link"]; ?&gt;" rel="group1"&gt;&lt;img src="client workout page/click to play video.jpg" style="width:186px;height: 14px;position:absolute;bottom:0;left:0;right:0;margin-left:auto;margin-right:auto;"&gt;&lt;/a&gt;'+ ' &lt;img src="" style="position:absolute;top:0;right:-15px;bottom:0;margin-top:auto;margin-bottom:auto;"&gt;' }).appendTo('.body1'); &lt;?php } ?&gt; </code></pre> <p>And this code generates the sets and reps:</p> <pre><code>$machine_atts = array( 'bicep curl' =&gt; array( 'sets' =&gt; 1, 'reps' =&gt; 50, 'weight' =&gt; 25 ), 'cable chest press' =&gt; array( 'sets' =&gt; 1, 'reps' =&gt; 100, 'weight' =&gt; 40 ), 'lat pulldown' =&gt; array( 'sets' =&gt; 2, 'reps' =&gt; 25, 'weight' =&gt; 20 ), 'tricep extension' =&gt; array( 'sets' =&gt; 3, 'reps' =&gt; 25, 'weight' =&gt; 30 ), ); $i=0; while ($row = mysql_fetch_array($retval1, MYSQL_ASSOC)) { $i++; $sets = $machine_atts[$row['machine_name']]['sets']; $reps = $machine_atts[$row['machine_name']]['reps']; $weight = $machine_atts[$row['machine_name']]['weight']; $array[] = '&lt;td&gt;'.$row['machine_name'].' &lt;span class="blue"&gt;#'.$i.'&lt;/span&gt;&lt;br&gt;sets &lt;span class="blue"&gt;'.$sets.'&lt;/span&gt; reps &lt;span class="blue"&gt;'.$reps.'&lt;/span&gt;&lt;br&gt;weight &lt;span class="blue"&gt;'.$weight.'&lt;/span&gt;&lt;/td&gt;'; } </code></pre> <p>This goes wherever I want the sets and reps to be displayed:</p> <pre><code>echo '&lt;table style="width: 100%; height:85%;table-layout:fixed;text-align:center;"&gt;'; foreach ( array_chunk( $array, 1 ) as $chunk ) echo '&lt;tr&gt;' . implode('', $chunk ) . '&lt;/tr&gt;'; echo '&lt;/table&gt;'; </code></pre> <p>I want to combine these separate pieces of code somehow to produce the output in the picture. Right now the pictures are fine but the sets and reps are being generated in a separate table.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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