Upon applying this code: $lines = explode("\n", $val); where $val = $_POST['result']; and $_POST['result']; is from a textarea where these strings are being exploded:
A – B -> 1:00
B – A -> 1:30
So $lines[0] = "A - B -> 1:00" and $lines[1] = "B - A -> 1:30" respectively.
In foreach ($lines as $line) , I’ll explode it again for every -> meet. Like this:
$fields = explode('->', $line);
$loc = trim($fields[0]);
$bltime = trim($fields[1]);
So $loc= “A – B” and $bltime = “1:00”. Then I’ll save these values in a table along with a value I stored in a session namely $_SESSION[rno] which is a primary key from another table and fetch another value from the same table.
$e=mysql_query("select etd from reservation
where reservno = '$_SESSION[rno]'") or die(mysql_error());
$f=mysql_fetch_array($e);
$g=$f['etd'];
mysql_query("insert into pdf(reservno, block, location, etd)
values ('$_SESSION[rno]', '".mysql_escape_string($bltime)."','".
mysql_escape_string($loc)."', '$g')") or die(mysql_error());
Then I need to add the values of etd and block for the value of eta then just update the table having the maximum pdf_id which is the primary key of pdf table after.
$a=mysql_query("select pdf_id as 'maxpdf' from pdf where pdf_id in
(select max(pdf_id) from pdf where reservno = '$_SESSION[rno]')")
or die(mysql_error());
$b=mysql_fetch_array($a);
$c=$b['maxpdf'];
$h=mysql_query("select addtime(etd, block) as 'eta' from pdf
where pdf_id = '$c'") or die(mysql_error());
$j=mysql_fetch_array($h);
$k=$j['eta'];
mysql_query("update pdf set eta = '$k' where pdf_id = '$c'")
or die(mysql_error());
So I’ll have the following values in the pdf table upon running the whole codes I posted above still based on the above value of $_POST['result'];:

What I want to do is to make this possible: have the first computed eta the value of the next etd then compute for it’s eta (etd + block). And then the waiting column should have the value of first eta minus the next etd. Something like this:

What is crucial and important here is the passing of the first eta to the next etd and the computation. How can I get it done when I’m required to loop through the exploded values? Please help me. I’m sorry for the long explanation but I want all of you to understand what I am trying to achieve. Thanks!
I’ve figured out how to pass the 1st
etavalue to the 2ndetdand so on. Here’s the whole looping statement I used..The
if(empty($g))statement checks if the queryselect eta as 'etd' from pdf where pdf_id in (select max(pdf_id) from pdf where reservno = '$_SESSION[rno]')results an empty set or not. If the query results empty, then it is the first data to be inserted, therefore,$tempwill hold the value of the resulted queryselect etd from reservation where reservno = '$_SESSION[rno]'. If otherwise, it means that there’s already data that was inputted beforehand so the$tempvariable will hold the resulted query which is held by$g, so simply,$temp = $g.