Jump to content

Archived

This topic is now archived and is closed to further replies.

a2bardeals

tricky variable program

Recommended Posts

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=45

Here'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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
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]

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.