Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am trying to populate a workout from a list in a database.

For example, the Bicep Curl machine has these sets and reps:

bicep curl machine  sets 1  reps 50
bicep curl machine  sets 2  reps 25
bicep curl machine  sets 3  reps 15
bicep curl machine  sets 4  reps 10
bicep curl machine  sets 1  reps 100

I want to randomly choose one of these rows and push it to my site. Right now there is a SetsRepsWeight table containing set_id, sets, reps, and weight

Then there is a setMaster table containing machine_id and set_id, where machine_id comes from a table with all the machines available.

So if my SetsRepsWeight table looks like this:

enter image description here

setMaster contains:

enter image description here

So bicep curl can be any of the set_id's 1-5. I want to randomly pick the row and populate it into the database but i need a recommendation on setting this up. Right now the sets, reps, and weight are in an array. How can i achieve my goal?

Here is my code now:

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

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

$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[] = '<tr><td width="50"><img src="client workout page/round_'.$i.'.jpg"></td><td><img src="'.$row["picture"].'" style="width:200px;height:200px;display:block;margin:20px auto;"/></td><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></tr><tr><td></td><td><a class="demo" href="'.$row["link"].'" rel="group1"><img src="client workout page/click to play video.jpg" style="width:186px;height:14px;margin:0 auto;"></a></td></tr>';
}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.