1

我有一个从数据库中提取的健身器械的动态列表。

我想实现这一点:

在此处输入图像描述

现在我有 2 段不同的代码要组合。

这会从数据库中提取机器:

$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();

此代码创建图片:

<?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))
    {
    ?>
        $('<div/>', {
                'id': 'div _<?php echo $row["machine_id"]; ?>',
                'class': 'some_class_name',
                'html': '<img src="client workout page/round_<?php echo $machine_id++ ?>.jpg" style="position:absolute;top:50%;left:0;">'+
                        '<img src="<?php echo $row["picture"]; ?>" style="width:200px;height:200px;display:block;margin:20px auto;"/> '+
                       ' <a class="demo" href="<?php echo $row["link"]; ?>" rel="group1"><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;"></a>'+
                       ' <img src="" style="position:absolute;top:0;right:-15px;bottom:0;margin-top:auto;margin-bottom:auto;">'
            }).appendTo('.body1');
<?php   }

 ?>

这段代码生成集合和代表:

$machine_atts = array(
'bicep curl' => array( 'sets' => 1, 'reps' => 50, 'weight' => 25 ),
'cable chest press' => array( 'sets' => 1, 'reps' => 100, 'weight' => 40 ),
'lat pulldown' => array( 'sets' => 2, 'reps' => 25, 'weight' => 20 ),
'tricep extension' => array( 'sets' => 3, 'reps' => 25, 'weight' => 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[] = '<td>'.$row['machine_name'].' <span class="blue">#'.$i.'</span><br>sets <span class="blue">'.$sets.'</span> reps <span class="blue">'.$reps.'</span><br>weight <span class="blue">'.$weight.'</span></td>';
}

这会出现在我希望显示组和代表的任何地方:

echo '<table style="width: 100%; height:85%;table-layout:fixed;text-align:center;">';
  foreach ( array_chunk( $array, 1 ) as $chunk )
    echo '<tr>' . implode('', $chunk ) . '</tr>';
  echo '</table>';

我想以某种方式组合这些单独的代码片段以产生图片中的输出。现在图片很好,但组和代表正在单独的表中生成。

4

1 回答 1

0

在图片代码片段中:使用您需要将机器与集合/代表匹配的任何键创建一个关联数组,并将其发送到集合/代表代码片段。在那里你可以访问图片。

于 2013-09-16T23:01:11.900 回答