a2bardeals Posted October 24, 2006 Share Posted October 24, 2006 i have page1 that asks how many tapes you have, which is sent as a variable to page2 as $tapes which is used in a foreach statement creating the correct number of input fields to ask the length of tape1, tape2, ect....On the third page i carry over those thengths via the GET method aka tape1=20 tape2=45Here's where it gets tricky...I would like to create a variable that represents a 60 or 120 min DVD and create a fuction to add the tapes to the dvd and subtract the $tape value from the $dvd value. I also need to not allow that function to be performed if there is not enough space left on the dvd. and a function to create a new 1 or 2 hour dvd. Then calculate how many tapes are on each dvd and how many dvds there are. Is this possisble or only a dream in a young programmers head? Quote Link to comment https://forums.phpfreaks.com/topic/24972-tricky-variable-program/ Share on other sites More sharing options...
Psycho Posted October 24, 2006 Share Posted October 24, 2006 Ok, instead of passing multiple values in the variables tape1, tape2, etc. It would be easier to accomplish this by just passing a single variable with the times of all the tapes comma separated.Then use the explode command to create an array. You could then accomplish what you want by doing something like this:[code]<?php$tapes = explode(",", $_GET['tapes']);$dvdlength = 120;$currentDVD = 0;$dvdIdx = 0;$i = 0;foreach ($tapes as $tape) { //See if the tape will fit on the current DVD, //If not, change to the next DVD if (($tape+$dvd[$i][length])>$dvdlength) { $dvdIdx++; } //Add the tape length & name to the current DVD $dvd[$dvdIdx][length] += $tape; if ($dvd[$dvdIdx][cont]) { $dvd[$dvdIdx][cont] .= ", "; } $dvd[$dvdIdx][cont] .= "Tape-" . $i;}?>[/code]that is very simplistic and has no error handling (such as if a tape is too big to fit an a single DVD), but it should be able to get you started.[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24972-tricky-variable-program/#findComment-113865 Share on other sites More sharing options...
a2bardeals Posted October 25, 2006 Author Share Posted October 25, 2006 that makes sense however to gather the tape lengths i am using something like:[code]foreach(range(1, $no_of_tapes) as $no){echo "<select name=tape'.$no.'>";echo "<option value=30>30 min</option>";echo "<option value=60>60 min</option>";echo "<option value=90>90 min</option>";echo "</select>";}[/code]which will always seem to pass mutiple variables even if i make the select name the same for all.... Quote Link to comment https://forums.phpfreaks.com/topic/24972-tricky-variable-program/#findComment-114298 Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 ok, change it to...[code]foreach (range(1, $no_of_tapes) as $no){ echo "<select name=tape[]>"; echo "<option value=30>30 min</option>"; echo "<option value=60>60 min</option>"; echo "<option value=90>90 min</option>"; echo "</select>";}[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24972-tricky-variable-program/#findComment-114329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.