Jump to content

tricky variable program


a2bardeals

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?
Link to comment
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]
Link to comment
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....
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.