ok i am having a hard time trying to think of how to explain what i want to do lol.
here is my ultimate goal (links to pictures of what i want lol):
I am creating a kind of weight lifting blog. I am using smarty as the template engine.
1st page: Asks the users how many different exercises they did
Page 1
2nd page: Asks the names of each exercise and how many sets of each one. The number of exercies printed is dynamically based on what the user entered on page 1
.Page 2
3rd page: Prints out a table.
The names and set numbers come from the info entered on page 2
.Page 3
Then after entering everything on page 3, all the info is stored in an array, and that array is then entered into the database like this
insert into workout (workout_name, set_number, reps, weight, date) values (<some how filled in with for loops and arrays>)
ill show my code even though i know it is 110% wrong and totally incomplete :/
what little i could come up with for the processing part:
enter_workout.php
<?php
include 'db.php';
require_once("libs.inc.php");
if(isset($_SESSION['username']))
{
$_SESSION['logged_in'] = 1;
} else {
$_SESSION['logged_in'] = 0;
}
if(empty($_POST['step']))
{
$smarty->assign("step", 1);
$smarty->display("templates/enter_workout.html");
exit();
} else {
if($_POST['step'] == 2)
{
$smarty->assign("step", 2);
if(isset($_REQUSET['today']))
{
$_SESSION['date'] = date("j, n, Y");
} else {
$_SESSION['date'] = $_POST['user_date'];
}
$_SESSION['workout_night'] = $_POST['workout_night'];
$_SESSION['number_of_exercises'] = $_POST['number_of_exercises'];
$i = $_SESSION['number_of_exercises']
$exercise_names_looper = range(1, $i);
$smarty->display("templates/enter_workout.html");
exit();
}
if($_POST['step'] == 3)
{
$smarty->assign("step", 3);
$workout_names = array();
for ($i = 1; $i <= $_SESSION['number_of_exercises']; $i++)
{
$workout_names[$i][names] = $_POST['workout_names'.$i];
$workout_names[$i][number_sets_exercise] = $_POST['number_sets_exercise'.$i];
}
$_SESSION['workout_names'] = $workout_names;
$smarty->assign("workout_names", $workout_names);
and the 75% wrong smarty template
enter_workout.html:
{if $smarty.session.logged_in eq 1}
{if $step eq 1}
<form method=post action="enter_workout.php?step=2">
<table width="100%" border=1>
<tr>
<td>
<table width=100%>
<tr>
<td width=15%>Use today's Date</td>
<td width=2%><input type="radio" name=today value=today checked></td>
</tr>
<tr>
<td>Or enter the date</td>
<td><input type="radio" name=other_day value=other_Day></td><td> <input type=text name=user_date></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width=100%>
<tr>
<td width=24%>What workout night is it?</td>
<td><input type=text name=workout_night></td>
</tr>
<tr>
<td>How many different exercises?</td>
<td><input type=text name=number_of_exercises></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><input type=submit name=submit value=Next> <input type=submit name=submit value=Quit></td
</tr>
</table>
</form>
{elseif $step eq 2}
<form method=post action="enter_workout.php?step=3">
<table width=100%>
{section name=i loop=$exercise_names_looper}
<tr>
<td width=15%>Name of exercise {$i}</td>
<td><input type=text name=workout_name{$i}></td>
</tr>
<tr>
<td width=15%>Number of sets for workout {$i}</td>
<td><input type=text name=number_sets_exercise{$i}></td>
</tr>
{/section}
<tr>
<td><input type=submit name=submit value=Next> <input type=submit name=submit value=Quit></td>
</tr>
</table>
</form>
{elseif $step eq 3}
<form method=post action="enter_workout.php?step=4" >
<table width=100% border=1>
<tr bgcolor="#0099FF">
<td width=30%>Workout Name</td>
<td width=23%>Set Number</td>
<td width=23%>Reps</td>
<td width=23%>Weight</td>
</tr>
//This section is fully off i cannot figure out what do do here, and it is not really updated to match the php, cus i dont know if i can figure out how to do either
{section name=i loop=$workout_name}
{section name=j loop=$number_sets_exercise[i]}
<tr>
<td>{$workout_name[i].name}</td>
<td>Set number {j}<input type=hidden name=set_number{$j} value={j}></td>
<td><input type=text name=reps></td>
<td><input type=text name=weight></td>
</tr>
//end of messed up section
{/section}
{/section}
<tr>
<td><input type=submit name=submit value=Next> <input type=submit name=submit value=Quit></td
<td></td>
<td></td>
<td></td>
</tr>
</table>
</form>
{else}
Incorrect step choice
{/if}
{else}
Please login <br />
<a href=index.php>
{/if}
if you cannot know of a way, or know of a better way then using smarty, then that is fine too, i am just at a complete loss on how to do this. I have spent hours trying to figure this out, and nothing except a huge headache. Arrays are my weakest link when it comes to any sort of programming, i just cannot understand them for some reason, especially multi-dimensional ones.
Sorry to ask for such a large amount of help, but i know i cannot figure it out on my own, i have tried for the last few days, and NOTHING has worked :/