PHP - Adding And Subtracting Within Pages.
Hello everyone,
I am not a php programmer, but I would like to solve a problem regarding math with PHP. I was looking around on the web on how to add (in this case digits) using PHP. I found out that adding two strings using a . I can then echo out the results; so far so good. My question however is as follow. How do I add up information from multiple pages? Let's say on one page (let's call it weekly.php) I have my weekly expenses of $300, and on the second page (let's call it monthly.php) I have my monthly expenses of $1400. I would like the result (weekly + monthly) to be displayed (echo'ed out) on the third page (let's call it totalamount.php). I don't want to take advantage of anyone's time, so I am not asking for the entire solution (code) unless you want to , but I would be just happy to be pointed in the right direction, I will do the rest on my own. Thank you very much for your time. Cheers, Luigi Similar TutorialsHi ! please help me . im having a trouble with this im actually new to php. Hello people. Thank you to everyone who has helped me in the past, this is a great forum full of very helpful members. I am trying to put a pilots logbook application together for the members at microlightforum.com and here is the form that I have put together. What I would like to know is how to code the first "Auto Insert" button so that it takes the time from the variables $takeoff_hr and $takeoff_min and $landing_hr, $landing_min I would like the time difference from taking off to landing putting in the "ws_captain_hrs" box and the "ws_captain_min" box. Therefore if someone took off at 12.30 and landed at 13.50 the "ws_captain_hrs" box should read "1" and the "ws_captain_min" box should read "20" The idea behind this is that it makes it easier for the user to only have to insert take off time and landing time, then click the appropriate button to put the data into the box. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $host = 'localhost'; $usr = "vinny"; $password = 'thepassword'; $db_name = 'logbook'; $date = $_POST['date']; $type = $_POST['type']; $reg_01 = $_POST['reg_01']; $reg_02 = $_POST['reg_02']; $captain = $_POST['captain']; $passenger = $_POST['passenger']; $where_01 = $_POST['where_01']; $where_02 = $_POST['where_02']; $takeoff_hr = $_POST['takeoff_hr']; $takeoff_min = $_POST['takeoff_min']; $landing_hr = $_POST['landing_hr']; $landing_min = $_POST['landing_min']; $ws_captain_hrs = $_POST['ws_captain_hrs']; $ws_captain_min = $_POST['ws_captain_min']; $ws_student_hrs = $_POST['ws_student_hrs']; $ws_student_min = $_POST['ws_student_min']; $three_captain_hrs = $_POST['three_captain_hrs']; $three_captain_min = $_POST['three_captain_min']; $three_student_hrs = $_POST['three_student_hrs']; $three_student_min = $_POST['three_student_min']; $passenger_hrs = $_POST['passenger_hrs']; $passenger_min = $_POST['passenger_min']; $remarks = $_POST['remarks']; $errorstring = ""; // default value of errorstring if(isset($_POST['save_flight'])) { // Validate all the code inputs that are required fields if ($date =="") $errorstring = $errorstring. "Date<br>"; if ($type =="") $errorstring = $errorstring. "Aircraft Type<br>"; if ($reg_01 =="") $errorstring = $errorstring. "Reg Prefix<br>"; if ($reg_02 =="") $errorstring = $errorstring. "Registration Mark<br>"; if ($captain =="") $errorstring = $errorstring. "Captain<br>"; if ($where_01 =="") $errorstring = $errorstring. "Flight From<br>"; if ($where_02 =="") $errorstring = $errorstring. "Flight To<br>"; if ($takeoff_hr =="") $errorstring = $errorstring. "Takeoff Hours<br>"; if ($takeoff_min =="") $errorstring = $errorstring. "Takeoff Minutes<br>"; if ($landing_hr =="") $errorstring = $errorstring. "Landing Hours<br>"; if ($landing_min =="") $errorstring = $errorstring. "Landing Minutes<br>"; // does the errorstring = "nothing"? if ($errorstring !="") echo "You have not put anything in the following fields: <br><br> $errorstring"; //echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\""; //die ("Please try again, ensuring that you fill out all the fields!"); else { //echo "Your data has been saved"; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $insert_query = "INSERT INTO pilots_logbook (date, type, reg_01, reg_02, captain, passenger, where_01, where_02, takeoff_hr, takeoff_min, landing_hr, landing_min, ws_captain_hrs, ws_captain_min, ws_student_hrs, ws_student_min, three_captain_hrs, three_captain_min, three_student_hrs, three_student_min, passenger_hrs, passenger_min, remarks) VALUES ('$date', '$type', '$reg_01', '$reg_02', '$captain', '$passenger', '$where_01', '$where_02', '$takeoff_hr', '$takeoff_min', '$landing_hr', '$landing_min', '$ws_captain_hrs', '$ws_captain_min', '$ws_student_hrs', '$ws_student_min', '$three_captain_hrs', '$three_captain_min', '$three_student_hrs', '$three_student_min','$passenger_hrs', '$passenger_min', '$remarks')"; $insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query); $id = mysql_insert_id(); echo "Thank you, Your logbook entry has been saved."; } } ?> <p>Use this form to add an entry to your logbook.</p> <form name = "form1" method ="post" action=""> <table width="650" border="1" cellspacing="0" cellpadding="5"> <tr> <td>Required *</td> <td> </td> <td>This Format Only</td> </tr> <tr> <td width="180">Date *</td> <td width="300"> <input type="text" name="date" id="date" size = "25"/> </label> <input type="submit" name="today" id="today" value="Add Today" /></td> <td width="170">YYYY-MM-DD</td> </tr> <tr> <td>Aircraft Type *</td> <td><input type="text" name="type" id="type" size = "40" /></td> <td>E.G. Quantum</td> </tr> <tr> <td>Reg Number *</td> <td><input type="text" name="reg_01" id="reg_01" size = "5" /> - <input type="text" name="reg_02" id="reg_02" size = "15"/></td> <td>G - ABCD</td> </tr> <tr> <td>Captain *</td> <td><input type="text" name="captain" id="captain" size = "40" /></td> <td>Name of Captain</td> </tr> <tr> <td>Passenger or Student</td> <td><input type="text" name="passenger" id="passenger" size = "40" /></td> <td>Were you? P or S</td> </tr> <tr> <td>Flight From *</td> <td><input type="text" name="where_01" id="where_01" size = "40" /></td> <td>Take off Airfield</td> </tr> <tr> <td>Flight To *</td> <td><input type="text" name="where_02" id="where_02" size = "40" /></td> <td>Landing Airfield</td> </tr> <tr> <td>Takeoff GMT *</td> <td><label>Hr <input type="text" name="takeoff_hr" id="takeoff_hr" size = "10" /> Min <input type="text" name="takeoff_min" id="takeoff_min" size="10"/> </label></td> <td>24 Hr Format Only</td> </tr> <tr> <td>Landing GMT *</td> <td><label>Hr <input type="text" name="landing_hr" id="landing_hr" size="10" /> Min <input type="text" name="landing_min" id="landing_min" size="10" /> </label></td> <td>24 Hr Format Only</td> </tr> <tr> <td>Captain Weighshift</td> <td><label>Hrs <input type="text" name="ws_captain_hrs" id="ws_captain_hrs" size = "10"/></label> <label>Min <input type="text" name="ws_captain_min" id="ws_captain_min" size = "10" /> <input type="submit" name="autofill_ws_captain" id="autofill_ws_captain" value="Auto Insert" /> <!--This is the button I would like to take the time from the take off and put it into the captain weightshift hrs and min boxes --> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Student Weightshift</td> <td><label>Hrs <input type="text" name="ws_student_hrs" id="ws_student_hrs" size = "10"/></label> <label>Min <input type="text" name="ws_student_min" id="ws_student_min" size="10" /> <input type="submit" name="autofill_ws_student" id="autofill_ws_student" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Captain 3 Axis</td> <td><label>Hrs <input type="text" name="three_captain_hrs" id="three_captain_hrs" size = "10"/> </label> <label>Min <input type="text" name="three_captain_min" id="three_captain_min" size = "10" /> <input type="submit" name="autofill_3_captain" id="autofill_3_captain" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Student 3 Axis</td> <td><label>Hrs <input type="text" name="three_student_hrs" id="three_student_hrs" size = "10"/> </label> <label>Min <input type="text" name="three_student_min" id="three_student_min" size = "10" /> <input type="submit" name="autofill_3_student" id="autofill_3_student" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Passenger Interest Only</td> <td>Hrs <input type="text" name="passenger_hrs" id="passenger_hrs" size="10"/> Min <input type="text" name="passenger_min" id="passenger_min" size="10"/> <input type="submit" name="passenger_button" id="passenger_button" value="Auto Insert" /></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Remarks</td> <td><textarea name="remarks" id="remarks" cols="45" rows="5"></textarea></td> <td>Went to get microlight forum cup from XYZ airfield. Maximum 500 characters</td> </tr> <tr> <td><input type="submit" name="save_flight" id="save_flight" value="Save Flight" /></td> <td><input type="submit" name="reset" id="reset" value="Reset Form" /></td> <td> </td> </tr> </table> <p> </p> <p> </p> </body> </html> Hi there, I've been trying to implement pagination to an existing script that displays products, but at present only displays next and back buttons. The number of products is now increasing and we would like to show the number of pages of results but the tutorials I've been going through seem to use a very different way of displaying the results to the script we currently have. Does anyone have any suggestions how I could add pagination to this form..... // Build Pagination $ByPage = ($prod_rows * $prod_cols); $qnav = "SELECT devbg_products.*, devbg_categories.*, devbg_subcategories.* FROM devbg_products LEFT JOIN devbg_categories ON devbg_products.ItemCategory = devbg_categories.CategoryID LEFT JOIN devbg_subcategories ON devbg_products.ItemSubcategory = devbg_subcategories.SubcategoryID WHERE devbg_products.ItemCategory = " . sql($cgid); $rnav = mysql_query($qnav) or die(mysql_error()); $rows = mysql_num_rows($rnav); if($rows > $ByPage) { $pages = ceil ($rows / $ByPage); echo "<br>\n"; echo "<table align='center'>\n"; echo "<tr>\n"; echo "<td align=center><font face=verdana size=2>"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start - $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if (($Start - $ByPage) <> -$ByPage) { echo "<input class='sub' type='submit' value='<<< Back' name='btnBack'>\n"; echo "</form>\n"; echo "</td>\n"; } echo "<td>\n"; echo "<form method='POST' action='ShowCategory.php'>\n"; echo "<input type='hidden' name='Start' value='" . ($Start + $ByPage) . "'>\n"; echo "<input type='hidden' name='CategoryID' value='" . $_REQUEST["CategoryID"] . "'>\n"; echo "<input type='hidden' name='SubcategoryID' value='" . $_REQUEST["SubcategoryID"] . "'>\n"; if ($Start + $ByPage < $pages * $ByPage) { echo "<input class='sub' type='submit' value='Next >>>' name='btnNext'>"; } echo "</form>\n"; echo "</td>\n"; echo "</tr>\n"; echo "</table><br><br>\n"; } This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=354302.0 I've echoed these things to the screen, the first two values come from strtotime and the third is math: last attempt time: 1286374178 (About 1:24 pm) now: 1286735148 (About 1:25pm) difference: 360970 What does 360970 represent? I want to know how many minutes have elapsed between the two times. Why doesn't this code work... echo '<p>time() = ' . time() . ' seconds</p>'; echo '<p>$lastActivity = ' . $lastActivity . '</p>'; echo '<p>Seconds Active: ' . time() - $lastActivity . ' seconds</p>'; ...where $lastActivity comes from my database. When I run my script I see... Quote time() = 1331187131 seconds $lastActivity = 1331186745 -1331186745 seconds The last line is dropping the label and there is now Date Math?! Debbie I accidently posted this in the PHP applications board and didn't mean to because its a blizzard here and my comp is getting slow and lagging and I thought I had clicked in the right board but I was wrong so if a mod, admin can delete that other entry I'd be thankful. I'm trying to queries together because I have this query but I want to only put in those characters that have not been taken so I have another table that lists all the characters that are used. TABLE handler_characters which has fields called id, handler_id, character_id. What I want to somehow do is have it get all the character_ids out of that table and then subtract those ids from this query so it won't list them as options. Any thoughts on how to accomplish this? <?php $query = 'SELECT id, charactername FROM characters ORDER BY `charactername`'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['charactername']."</option>\r"; } ?> Good morning. I need to subtract stock levels from oldest stock first then to the next date. It is allowed to move into negative values. example 01-10 stock in 10 stock out 5 - stock count 5 02-10 stock in 10 stock out 7 stock count ... here we need to subtract the 7 from previous days 5 til it reches 0 then stock in subtraction 01-10 stock =0 02-10 stock = 8 --- as 7 -5 gives me -2 in incoming stock is 10 leaving me with stock count of 8. 03-10 stock in 8 stock out 21 02-10 stck level must be 0 03-10 stock lever now is 8-14 = -6 and so on below is my code. $lq_in = new ListQuery('stock_audit5f5795042f369'); $lq_in->addSimpleFilter('name', '%PEPPER yellow%', 'LIKE' ); //$lq_in->addSimpleFilter('product_id', $product_id, '='); $lq_in->setOrderBy('date_entered'); $res_in = $lq_in->fetchAll(); $StockArray = []; foreach($res_in as $out_rec) { /*$upd_out = array(); $upd_out['stock_out_done'] = 0; $out_rec_u = ListQuery::quick_fetch('stock_audit5f5795042f369', $out_rec->getField('id')); $aud_upd_out = RowUpdate::for_result($out_rec_u); $aud_upd_out->set($upd_out); $aud_upd_out->save(); continue; */ $stock_out = $out_rec->getField('stock_out'); $stock_out_done = $out_rec->getField('stock_out_done'); $date_entered = $out_rec->getField('date_entered'); $product_id = $out_rec->getField('product_id'); //echo '<pre>'; // print_r($out_rec->row); $StockItems[] = $out_rec->row; //$stock_done = 0; /* foreach($res_in as $in_rec) { $upd = array(); if($stock_out_new > $in_rec->getField('stock_level')) { $upd['stock_level'] = 0; $stock_out_new = $stock_out_new-$in_rec->getField('stock_level'); $stock_done = $in_rec->getField('stock_level'); } elseif ($stock_out_new == $in_rec->getField('stock_level')) { $upd['stock_level'] = 0; $stock_out_new = 0; $stock_done = $stock_out; } elseif($stock_out_new < $in_rec->getField('stock_level')) { $upd['stock_level'] = $in_rec->getField('stock_level')-$stock_out_new; $stock_out_new = 0; $stock_done = $stock_out; } else { continue; } $in_rec_u = ListQuery::quick_fetch('stock_audit5f5795042f369', $in_rec->getField('id')); $aud_upd = RowUpdate::for_result($in_rec_u); $aud_upd->set($upd); $aud_upd->save(); if($stock_out_new == $stock_done) break; } $upd_out = array(); $upd_out['stock_out_done'] = $stock_done; $out_rec_u = ListQuery::quick_fetch('stock_audit5f5795042f369', $out_rec->getField('id')); $aud_upd_out = RowUpdate::for_result($out_rec_u); $aud_upd_out->set($upd_out); $aud_upd_out->save(); */ } function GetFirstItemWithStockKey($StockItemsarrayk = null){ if($StockItemsarrayk != null){ foreach($StockItemsarrayk as $key => $value){ if(((int) $StockItemsarrayk[$key]['stock_level']) > 0){ return $key; } } } } function SetFirstItemWithStock($StockItemsarray = null){ if($StockItemsarray != null){ foreach($StockItemsarray as $key => $value){ if(((int) $StockItemsarray[$key]['stock_level']) > 0){ return $StockItemsarray[$key]; } } } } $remainder = 0; $pkey = ""; $StockLevelKey = 0; $StockIn = []; $StockOut = []; $InStock = []; $NewStockItems = $StockItems; $ArrayKeys = []; foreach($StockItems as $key => $value){ $StockIn[$key] = (int) $StockItems[$key]['stock_in']; $StockOut[$key] = (int) $StockItems[$key]['stock_out']; $InStock[$key] = (int) $StockItems[$key]['stock_level']; $ArrayKeys[] = (int)$key; } //var_dump($InStock); foreach($NewStockItems as $key => $value){ if($key < 1){ if($StockIn[$key] > 0 && $StockOut[$key] == 0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] + $StockIn[$key]); } if($StockIn[$key] == 0 && $StockOut[$key] > 0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] - $StockOut[$key]); } if($StockIn[$key] > 0 && $StockOut[$key] > 0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] - $StockOut[$key] + $StockIn[$key]); $StockItems[$key]['stock_out'] = 0; } } if($key > 0){ $previousWithStockItem = SetFirstItemWithStock($StockItems); $previousItemWithStockKey = GetFirstItemWithStockKey($StockItems); // echo "<pre>"; // print_r($previousWithStockItem); // var_dump($StockIn[$key]); echo " --IN"; // var_dump($InStock[$key]); echo " --- current"; // var_dump($StockOut[$key]); echo " --- OUT"; while($StockOut[$key] > 0){ if($StockOut[$key] > 0 && $previousWithStockItem['stock_level'] > 0){ $Counter = 0; $maxIteration = 0; for($Counter = $previousWithStockItem['stock_level']; $Counter >= 0; $Counter--){ $StockItems[$previousItemWithStockKey]['stock_level'] = $Counter; if($Counter == 0){ $StockOut[$key] = $StockOut[$key] - $maxIteration; } $maxIteration++; } } if((((int) $StockItems[$key]['stock_level'] < 0) || ((int) $StockItems[$key]['stock_level'] === 0))&& ($StockIn[$key] > 0)){ $valueTotal = $StockItems[$key]['stock_level'] + $StockIn[$key]; $StockItems[$key]['stock_level'] = $valueTotal; } echo "<hr/>"; echo (int) $StockOut[$key]; echo "<br/>"; echo (int) $StockItems[$key]['stock_level']; echo "<br/>"; echo "<hr/>"; if(((int) $StockOut[$key] > 0) && ((int) $StockItems[$key]['stock_level'] > 0) && ((int) $StockItems[$key]['stock_level'] > $StockOut[$key])){ $newStockLevel = $StockItems[$key]['stock_level'] - $StockOut[$key]; echo $newStockLevel; $StockItems[$key]['stock_level'] = $newStockLevel; $StockItems[$key]['stock_out'] = 0; $StockOut[$key] = 0; } if((((int) $StockItems[$key]['stock_level'] < 0) || ((int) $StockItems[$key]['stock_level'] === 0))&& ($StockIn[$key] > 0)){ $valueTotal = $StockItems[$key]['stock_level'] + $StockIn[$key]; echo $valueTotal; $StockItems[$key]['stock_level'] = $valueTotal; } } } } echo "<table><tr><td><pre>"; print_r($NewStockItems); echo "</pre></td><td><pre>"; print_r($StockItems); echo "</pre></td></table>"; /* if($StockIn[$key] > 0 && $StockOut[$key] >0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] + ($StockIn[$key] + $StockOut[$key])); $StockOut[$key] = 0; $StockItems[$key]['stock_out'] = 0; } if($StockIn[$key] != 0 && $StockOut[$key] != 0 && $InStock[$key] != 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] - ($StockOut[$key] + $StockIn[$key])); $StockOut[$key] = 0; $StockItems[$key]['stock_out'] = 0; }*/ /** @Rule 1 # Stockin has value and stock_out = 0 and stock_level = 0 and stock_out_done = null, actualstock to show actual stock level; # */ /*if($StockCalculation[$Skey]['stock_out'] >= $StockItems[$key]['stock_level']){ $StockItems[$key]['stock_out'] = ($StockItems[$key] - 1); $StockItems[$key]['stock_level'] = ($StockItems[$key]['stock_level'] - 1); // If StockOut == 0 next StockOutItem if($StockCalculation[$Skey]['stock_out'] == 0){ $remainder = 0; continue; }elseif($StockItems[$key]['stock_level'] == 0){ //CurrentInStock == 0 then continue to next CurrentItem $remainder = $StockItems[$key]['stock_out']; continue(2); } } $CurrentStockIn = $StockItems[$key]['stock_in']; $CurrentStockOut = $StockItems[$key]['stock_out']; $CurrentInStock = $StockItems[$key]['stock_level']; if($key == 0){ if($CurrentStockIn > 0 && $CurrentStockOut === 0 && $CurrentInStock == 0){ $CurrentInStock = $CurrentStockIn; //Query update stock level set = stock_in //"UPDATE STOCK SET stock_level = {$CurrentStockIn} where id = {$StockItems[$key]['id']}"; $StockItems[$key]['stock_level'] = $CurrentStockIn; } if($CurrentStockIn != 0 && $CurrentStockOut != 0 && $CurrentInStock == 0){ //Query Update Stocklevel if stock_out > 0 and stock_level = 0 //"UPDATE STOCK SET stock_level = "+($CurrentStockIn - $CurrentStockOut) + "where id = {$StockItems[$key]['id']}"; if($CurrentStockIn > $CurrentStockOut && $CurrentStockOut == 0){ $StockItems[$key]['stock_out'] = 0; $StockItems[$key]['stock_level'] = $CurrentInStock = $CurrentStockIn - $CurrentStockOut; } if($CurrentStockOut > $CurrentStockIn){ $StockItems[$key]['stock_level'] = $CurrentInStock = $CurrentInStock - $CurrentStockOut; } } if($CurrentInStock != 0 && $CurrentStockOut > 0){ //If Current in stock below 0 and stock out > 0 then negative more //"UPDATE STOCK SET stock_level = "+($CurrentInStock - $CurrentStockOut) + "where id = {$StockItems[$key]['id']}"; $StockItems[$key]['stock_level'] = $CurrentInStock = ($CurrentInStock - $CurrentStockOut); $StockItems[$key]['stock_out'] = 0; } if($CurrentInStock != 0 && $CurrentStockIn > 0){ //If Current in stock below 0 and stock out > 0 then negative more //"UPDATE STOCK SET stock_level = "+($CurrentInStock - $CurrentStockOut) + "where id = {$StockItems[$key]['id']}"; $StockItems[$key]['stock_level'] = $CurrentInStock = ($CurrentInStock + $CurrentStockIn); } // Run row update for first item }else{ foreach($StockCalculation as $Skey => $Sval){ $NextStockOut = $Sval['stock_out']; $NextStockIn = $Sval['stock_in']; $NextStockLevel = $Sval['stock_level']; if($Skey > 0 && $key > 0){ // print_r($NextStockOut); for($i = $NextStockOut; $i >= -1; $i--){ if($NextStockOut > 0){ if($NextStockOut > 0){ /* if($StockItems[$StockLevelKey]['stock_level'] != 0){ $StockItems[($StockLevelKey)]['stock_level'] = ($StockItems[($StockLevelKey)]['stock_level'] - 1); //$StockItems[($Skey-1)]['stock_out'] = ($StockItems[($Skey-1)]['stock_out'] -1); } if($StockItems[($Skey-1)]['stock_level'] != 0){ $StockItems[($Skey-1)]['stock_level'] = ($StockItems[($Skey-1)]['stock_level'] - 1); } } } $NextStockOut = ($NextStockOut -1); if($NextStockOut != 0){ $StockItems[$Skey]['stock_out'] = 0; break; } } } unset($StockCalculation[$Skey]); } }/* */
Hi All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. like if I'm displaying a hundred entries , my website will be super long in length so I wanna break those hundred entries into maybe like 12 per page . Then click next page or the page number to view the next 12. Hello everyone, this is my first post. This isn't just a simple post and leave, I'm looking to expand into this community and learn as much as I can. Well on to the problem at hand! I decided to start with something simple as a login page and now want to expand it to make it fully functional. Code: (index.html) [Select] <html> <head> <title>Deadnode.com</title> <LINK href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div style=width:150px;height:80px;position:absolute;left:40%;top:35%; margin-left:-135px;margin-top:-50px;"> <div class="sidebox"> <div class="boxhead"><h2>Login Required</h2></div> <div class="boxbody"> <form method="post" action="check.php"> <center><table> <tr><td><font face="verdana,arial" size=-1>User:</td><td><input type="text" name="user"></td></tr> <tr><td><font face="verdana,arial" size=-1>Pass:</td><td><input type="text" name="pwd"></td></tr> <tr><td><font face="verdana,arial" size=-1> </td><td><font face="verdana,arial" size=-1><input type="submit" value="Login"></td></tr> </table></center> </form> </div> </div> </body> </html> Code: (function.php) [Select] <?php function check() { $admin="test"; $pass="test"; if ( $_POST["user"] == $admin & $_POST["pwd"] == $pass) { header('Location: output.php'); } else { header('Location: index.html'); } } ?> Code: (check.php) [Select] <?php require('function.php'); check(); ?> This is just the code in it originally form; completely functional. I tried to use start_session() in my check() function. I know I should be using cookies, but I haven't gotten that far yet. Is it possible to use my check function as a way to block pages? I tried inserting the same code that is in check.php onto a html page, but I've had no luck with it redirecting back to my index.html page. Hi, (Just wanna say thanks to the guy who helped me earlier as i cannot find the topic) I have a game, it has 3 frames, menu, header & the main content, it WAS fine until i deleted a 4th frame, now when i click a link from the menu, instead of showing the link in the 'Main' content area, it takes you to the actual page with no menu, header etc. Thanks in advance! I want to use my form variables in other page which is not specified in action attribute. Please help me out !!! My code is below :
<body> what I'm trying to do is to setup a page called settings.php that the admin runs to order to turn option in the web site on or off. I don't know how to do this since I never done this before. My code is below. <link href="mainframe.css" rel="stylesheet" type="text/css"> <?php require_once '../config.php'; $db = new DbConnector(); $db->DbConnector(); if(isset($_GET['submit'])) { $db->query('UPDATE '.SETTING_TABLE.' SET option='.$_POST['banner'].' WHERE setname='''); echo 'Process complete'; } $result = $db->query('SELECT * FROM '.SETTINGS_TABLE); echo '<table border="1">'; echo '<tr>'; echo '<form action="settings.php" methed="post">'; while($row = $db->fetchArray($result)) { echo '<tr>'; echo '<td>'.$row['setname'].'</td><td><select size="1" name="'.$row['setname']'">'; echo '<option value="on">on</option>'; echo '<option value="off">off</option>'; echo '</td>'; echo "</tr>"; } echo '<td><input type="submit" value="Submit" name="submit">'; echo '</td>'; echo "</tr>"; echo "</form>"; echo "</table>"; /* */ ?> <h2>Settings</h2> <a href = "admin.php">Admin Panel</a> Hi, so....i have these 2 pages, but they don't show up in browser....can't find the error so will ask your help guys index.php <?php session_start(); if(!isset($_SESSION["manager"])){ header("Location: admin_login.php"); exit(); } //Be sure to check that manager SESSION value is in database $managerID = preg_replace('#[^0-9]#i',",$_SESSION["id"]); // Filter everything but numbers and letters $manager = preg_replace('#[^A-Za-z0-9]#i',",$_SESSION["manager"]); //Filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i',",$_SESSION["password"]); //Filter everything but numbers and letters //Run MySQL query to be sure that this person is an admin and that their password session var equals the database //Connect to the MySQL Database include("../storescripts/connect_to_mysql.php"); $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID AND username='$manager' AND password='$password' LIMIT 1"); //search user $existsCount = mysql_num_rows($sql); //count the row numbers if ($existsCount == 0){ //evaluate the count header("Location: ../index.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MyOnlineStore | Admin Area</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <p><br /> <br /> </p> <p> </p> <p><br /> </p> <div id="pageContent"> <div id="admin" align="left"> <h3>Hello what you want to do?</h3> <p><a href="#">Manage Inventory</a><br /> <a href="#">Manage afggagdfag</a></p> </div> </div> <?php include_once("../template_footer.php");?> </div> <p> </p> <p> </p> <p> </p> </body> </html> admin_login.php <?php session_start(); if(!isset($_SESSION["manager"])){ header("Location: admin_login.php"); exit(); } //Be sure to check that manager SESSION value is in database $managerID = preg_replace('#[^0-9]#i',",$_SESSION["id"]); // Filter everything but numbers and letters $manager = preg_replace('#[^A-Za-z0-9]#i',",$_SESSION["manager"]); //Filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i',",$_SESSION["password"]); //Filter everything but numbers and letters //Run MySQL query to be sure that this person is an admin and that their password session var equals the database //Connect to the MySQL Database include("../storescripts/connect_to_mysql.php"); $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID AND username='$manager' AND password='$password' LIMIT 1"); //search user $existsCount = mysql_num_rows($sql); //count the row numbers if ($existsCount == 0){ //evaluate the count header("Location: ../index.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MyOnlineStore | Admin Area</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <p><br /> <br /> </p> <p> </p> <p><br /> </p> <div id="pageContent"> <div id="admin" align="left"> <h3>Hello what you want to do?</h3> <p><a href="#">Manage Inventory</a><br /> <a href="#">Manage afggagdfag</a></p> </div> </div> <?php include_once("../template_footer.php");?> </div> <p> </p> <p> </p> <p> </p> </body> </html> Hi, I am looking for reliable, effective code to cache one or two of my website webpages. I know there are packages like the pear cache lite but is far beyond my needs and complex in terms of never used pear before etc. I am looking for a good cache class perhaps or a link to a good cache script. Does anyone have any code they would like to share or know of any good cache classes etc? I want to keep it relatively simple if possible. Thanks for any suggestions, help. PHPLOVER how to convert php pages to api Hello, I was wondering if someone could help me to "get" the webaddress of a current webpage and then pull off pieces of the page. All of my pages look like: http://localhost:8888/algebra_book/Chapters/Quadratic_Functions/introductory_problem.php BUT, the stuff to the left of Quadratic Functions WILL change in the future. So all will look like: *Quadratic_Functions/introductory_problem.php Then, I'd like to pull off a $chapter variable, which in this case is Quadratic_Functions and a $page_name variable which in this case will be introductory_problem. Thanks so much. Hello everyone, I am new to this site and new to working with php. I am wondering about a code that i could use for splash pages for members to be able to use them. I have the splash pages set up already but have not been able to figure out how to code it so that all the members of the site can use them to promote the site. Any help would be great thanks. Aaron Hey all, I've a problem with including of my pages. When I do choose lotto on index.php , I do get the page and also can choose how many roster I want. But I can't see my lotto results, because it does refresh to the index.php again. How can I fix this problem ? this is the code of index.php: Code: [Select] <?php echo '<table class="achtergrond" border="1">'; echo '<tr><td colspan="3">'; /* Keuzelijst tonen */ echo '<center><form action="'.$_SERVER['php_self'].'" method="POST"><select name="test">'; echo '<option selected>Kies een formulier</option></center>'; echo '<option value="1">Lotto</option>'; echo '<option value="2">Euromillions</option>'; echo '</select>'; echo '<button type="submit" name="knop">OK</button>'; echo '</form>'; echo '</td></tr>'; /* Als er op de knop gedrukt is , voer het lottoformulier uit*/ if(isset($_POST['knop'])) { echo '<tr><td>'; echo $waarde; /* variabel $waarde een waarde insteken via keuzelijst */ switch($_POST['test']) { case 1; include('formulieren/lotto.php'); case 2; include('formulieren/euromillions.php'); } echo '</td></tr>'; echo '</table>'; } ?> and this is the code of lotto.php: Code: [Select] <?php echo '<table class="achtergrond">'; echo '<tr><td colspan="3">'; /* Keuzelijst tonen */ echo '<center><form action="'.$_SERVER['php_self'].'" method="POST"><select name="lotto">'; echo '<option selected>Kies aantal rooster</option></center>'; echo '<option value="1">2 roosters</option>'; echo '<option value="2">4 roosters</option>'; echo '<option value="3">6 roosters</option>'; echo '<option value="4">8 roosters</option>'; echo '<option value="5">10 roosters</option>'; echo '<option value="6">12 roosters</option>'; echo '</select>'; echo '<button type="submit" name="knop1">OK</button>'; echo '</form>'; echo '</td></tr>'; /* Als er op de knop gedrukt is , voer het lottoformulier uit*/ if(isset($_POST['knop1'])) { /* variabel $waarde een waarde insteken via keuzelijst */ switch($_POST['lotto']) { case 0; $waarde2 = 0; break; case 1; $waarde2 = 1; break; case 2; $waarde2 = 2; break; case 3; $waarde2 = 3; break; case 4; $waarde2 = 4; break; case 5; $waarde2 = 5; break; case 6; $waarde2 = 6; break; }... |