PHP - Subtract Two Arrays?
Say I already have the two example arrays below ($arrayA and $arrayB). What is the proper way to cycle through these arrays to ultimately create a single array ($arrayC) that only has the items that are in Array B but are NOT in Array A? Basically subtracting the first array from the second array...
Array A: 1-dog 2-cat 4-fish 7-monkey 9-bird Array B: 1-dog 2-cat 3-elephant 4-fish 5-whale 6-dolphin 7-monkey 8-aardvark 9-bird 10-stingray So again, I want the end result to be this array... Array C: 3-elephant 5-whale 6-dolphin 8-aardvark 10-stingray Can anyone help? Similar TutorialsOk, i have setup a page to add points to a member using 2 tables as i have said in one of my older posts, now i am wanting to subtract an entered amount of points... removepoints.php Code: [Select] <body> <form method="post" name="memberadd" action="points_remove_complete.php"> <label>Name:</label> <select name="memberid"> <?php $con = mysql_connect("localhost","slay2day_User","slay2day"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("slay2day_database",$con); $sqlquery="SELECT * FROM `members` Order By name"; $result=mysql_query($sqlquery,$con); while($row=mysql_fetch_array($result)) { echo "<option value='".$row['id']."'>".$row['name']."</option>"; } ?> </select> <br> <label>Points:</label> <input type="text" name="points" id="points" size="5"><br> <input type="submit" value="submit" /> </form> </body> points_remove_complete.php: Code: [Select] <?php $id=$_POST['memberid']; $points=$_POST['points']; $con = mysql_connect("localhost","slay2day_User","slay2day"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("slay2day_database",$con); $sql="INSERT INTO slay2day_database.`points` VALUES (NULL,'$memberid','$points')"; if(mysql_query($sql,$con)) { echo 'Points removed.<br /><a href="../index.php">Return To Points List</a><br /><a href="removepoints.php">Remove More Points!</a>'; } else { die('Could not submit: ' . mysql_error()); } mysql_close($con); ?> Hello I have 2 datetimes...both are inside a database. The datetimes are not unix time they are regular date\times. So for instance...in the database I have a field called Login_time which is 2012-01-30 02:43:13 I am taking the current time in the same format with the following code Code: [Select] $curDate = date("Y-m-d H:i:s", time()); The problem is that I can't figure out how to tell the exact minutes for the 2 date\time intervals. Code: [Select] //find out if the ip address is inside the database $doesIpExsist = mysql_query("Select * from login_information where IP_Address like '$ip'", $link); $num_rows = mysql_num_rows($doesIpExsist); echo "$num_rows Rows\n"; if ($num_rows == 0) { //create the field inside the database $ip_query = "INSERT INTO login_information (IP_address, `Login_attempts`, Login_time, Total_login_attempts) VALUES ('$ip', '1', NOW(), '1')"; $ip_result = mysql_query($ip_query, $link) or die (mysql_error()); } else //the fields alaready exsist { $curDate = date("Y-m-d H:i:s", time()); echo $curDate; include ('timefunction.php'); echo "<br>"; echo "IP ".$ip; echo "<br>"; $select_ip_id = "SELECT ID from login_information where IP_address like '127.0.0.1'"; //$select_ip_id = "SELECT ID from login_information where IP_address like '$ip'"; echo $select_ip_id; $ip_error = mysql_query($select_ip_id, $link) or die (mysql_error()); foreach ($row = mysql_fetch_array($ip_error, MYSQL_ASSOC) as $key => $value) { echo dateDiff('$curDate', '$get_ip_error') . "<br>"; echo dateDiff('$get_ip_error', '$curDate') . "<br>"; echo "HIoROW " . $value. "<br>"; } $get_ip_time = "Select Login_time from login_information where IP_address like '$ip'"; $get_ip_error = mysql_query($get_ip_time, $link) or die (mysql_error()); //echo $get_ip_error; /*while ($row = mysql_fetch_array($get_ip_error, MYSQL_ASSOC)) //while($row=mysql_fetch_array($get_ip_error)) { echo $row; } */ echo "HI"; echo $curDate; echo "<br>"; echo $get_ip_error; echo "<br>"; echo dateDiff('$curDate', '$get_ip_error') . "<br>"; echo dateDiff('$get_ip_error', '$curDate') . "<br>"; echo "<br>"; //$datetime1 = date_create($curDate); //$datetime2 = date_create($get_ip_error); //$interval = date_diff($datetime1, $datetime2); //echo $interval->format('%R%a days'); //$dt1 = new DateTime($get_ip_error); //$dt2 = new DateTime($curDate); //$dtdiff = $dt1->diff($dt2); //print $dtdiff->format('%h hours, %i minutes'); //echo "<br>"; //$timeDifference = time_diff ($get_p_error, $curDate); //echo $timeDifference; //$timeDifference = $get_ip_error - $curDate; //echo "<br>"; //echo $timeDifference; //mysql_query("UPDATE Persons SET Age = '36' WHERE FirstName = 'Peter' AND LastName = 'Griffin'"); //$ip_query = "UPDATE INTO login_information (IP_address, `Login_attempts`, Login_time, Total_login_attempts) VALUES ('$ip', '1', NOW(), '1')"; echo "So far so good"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> </body> </html> Currently it doesn't work to the minutes. Can you tell me what i am doing wrong on this issue. Gud Pm! Im trying to display a list of years (last year, current year and next year) with these simple code i made.. It displays the current and next year correctly except last year, which gives me "1970". I don't get why it gives me that since may next year works properly.. Code: [Select] $currentyear = date('Y'); $subtract_year = strtotime(date('Y', strtotime($currentyear)) . '-1 year'); $lastyear = date('Y', $subtract_year); $addyear = strtotime(date('Y', strtotime($currentyear)) . '+1 year'); $newyear = date('Y', $addyear); $year_array = array($lastyear, $currentyear, $newyear); foreach($year_array as $year) { echo "<option value='{$year}'>"; echo $year; echo "</option>"; } I'm not familiar with dates yet.. so i'm gonna read the manual while w8ting for your kind replies. I have the following code: Code: [Select] //DETERMINES ASL POLICY if ($perfRow['ASL']=='ToArrange'){ $ASLdate = $perfRow['startDateTime']; $ASLconfirm = strtotime($ASLdate-'21 days'); echo "<!--[ASL=ToARRANGE--><p>An ASL Interpreted performance of this event is offered on".date("l, F j",strtotime($perfRow['startDateTime']))." at ".date("g:i a",strtotime($perfRow['startDateTime'])).".<br />Please contact me by ".date("l, F j",strtotime($ASLconfirm))." to confirm this service.</p>"; }What I need is that if the ASL is "To be Arranged" there is a date that lists for $ASLconfirm that is three weeks prior to $ASLdate. The code above gives me the following: Quote An ASL Interpreted performance of this event is offered on Friday, September 28 at 7:30 pm. Please contact me by Wednesday, December 31 to confirm this service. As you can see from the output the December date is NOT three weeks prior to the September date. Where did I go wrong in my coding? I have a PHP script that downloads a file from a remote server but in order to download the correct file it has to subtract 1 day of the week. It used to work quite some time ago so I dont know what is going on now. The section of the script goes like this....
$days = array("sun","mon","tue","wed","thu","fri","sat"); $today = date("w"); $yesterday = $days[$today - 1];Then it joins the 3 letter version of the day of week with a file name to grab the correct file download. $yesterday is not returning the correct value instead I am getting an error... # ./update.php PHP Notice: Undefined offset: -1 in /root/fcc/work/update.php on line 6 fetching l_am_.zip ncftpget: server said: l_am_.zip: No such file or directory. PHP Warning: unlink(counts): No such file or directory in /root/fcc/work/update.php on line 23 data set empty nothing to process Sun, 01 February, 2015 6:29:06 PMSo in the above error I can see that $yesterday is "Undefined offset" and because of that the file it tries to download is incorrect, it should have tried to download l_am_sat.zip and it left out the 3 letter date code. Edited by chadrt, 01 February 2015 - 09:48 PM. Hi if i have $date = "12-08-2018" or "2018-08-12" Need to subtract a month. Could this be done for day and year even? TIA Desmond. P.S. What I want to do is clear out a database table with records over a month old so today is 27th Jan 2018. I would like to create a date “2018-12-01” I can then use this in an SQL to delete all before “2018-12-01” Edited January 27, 2019 by Paul-DHello this may sound a little confusing.
I recently made a fake website using this phpacademy tutorial I found. Anyways it has an quantity stock what I mean by this is let's I have 3 copies of a video game an a person set they quantity for 2 of the 3 copies and proceed to the checkout through paypal payment successful okay. My question is: How can I go about sending the quantity stock back to the database to subtract 2 from 3 to be left with 1 copy of the game in the quantity section after a successful purchase? Code is below in case I confused someone ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////// Maximumize / calling the quantity from Database ///////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(isset($_GET['add'])){ $quantity = mysqli_query($db_conx,'SELECT id, quantity FROM products WHERE id='.mysqli_real_escape_string($db_conx,(int)$_GET['add'])); while ($row = mysqli_fetch_assoc($quantity)){ if ($row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) { $_SESSION['cart_'.(int)$_GET['add']]+='1'; } } header('Location: '.$page); } if(isset($_GET['remove'])){ $_SESSION['cart_'.(int)$_GET['remove']]--; header('Location:' .$page); } if(isset($_GET['delete'])){ $_SESSION['cart_'.(int)$_GET['delete']]='0'; header('Location:' .$page); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////// Calling all products from Database ///////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function products($db_conx){ $get = mysqli_query($db_conx,"SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id DESC"); if (mysqli_num_rows($get) ==0){ echo "There are no products to display"; } else { while ($row = mysqli_fetch_assoc ($get)){ echo '<p>'.$row ['name']. '<br/> <br/>' .$row ['description']. '<br/> <br/>' .'$'.number_format($row['price'], 2).' <a href="cart.php?add='.$row ['id'].'">Add</a></p>'; } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////// Paypal Checkout ///////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function paypal_items($db_conx){ $num = 0; foreach($_SESSION as $name => $value){ if ($value != 0){ if(substr($name, 0, 5)=='cart_'){ $id = substr($name, 5, strlen($name) -5); $row = mysqli_query($db_conx,'SELECT id, name, price, shipping FROM products WHERE id ='.mysqli_real_escape_string($db_conx,(int)$id)); while ($query = mysqli_fetch_assoc($row)){ $num++; echo '<input type="hidden" name="item_number_'.$num.'" value="'.$id.'">'; echo '<input type="hidden" name="item_name_'.$num.'" value=" '.$query['name'].' ">'; echo '<input type="hidden" name="amount_'.$num.'" value=" '.$query['price'].' ">'; echo '<input type="hidden" name="shipping_'.$num.'" value=" '.$query['shipping'].' ">'; echo '<input type="hidden" name="quantity_'.$num.'" value=" '.$value.' ">'; } } } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////// Shopping Cart View ///////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function cart($db_conx) { foreach($_SESSION as $name => $value) { if ($value > 0) { if(substr($name,0 ,5) . 'cart_'){ $id = substr($name, 5, (strlen($name) -5)); $row = mysqli_query($db_conx,'SELECT id, name, price FROM products WHERE id=' .mysqli_real_escape_string ($db_conx,(int)$id)); while ($query = mysqli_fetch_assoc($row)){ $sub = $query['price']*$value; echo $query['name'].' x ' .$value. ' @ $' .number_format ($query['price'], 2). ' = $'.number_format($sub, 2). '<a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a> <br/> <br/> '; } } $total += $sub + $shipping; } } if ($total ==0) { echo "Your cart is empty."; } else { echo 'Total: $' .number_format($total, 2); ?> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="youremail@outlook.com"> <?php paypal_items($db_conx); ?> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="amount" value="<?php echo $total ;?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> <?php } } ?> Edited by mac_gyver, 09 September 2014 - 08:06 PM. code tags please Hey, I have a minigame on my website and when you bet 1 It says you lost and you lose your point but it doesn't remove it, Same with if you win it says you gain the point but doesn't add it.... Code: [Select] function bet ($bet){ sleep(2); $user1 = mysql_query("SELECT * FROM `users` WHERE `id`='" . $_SESSION['id'] . "'"); $user = mysql_fetch_object($user1); $chance = rand (1, 2); $bet = round ($bet); $betPretty = number_format ($bet); if ($bet == 0) { $echo = "You did not bet anything!"; $chance = 0; } if ($bet < 0) { $echo = "You cannot bet a negative number."; $chance = 0; } if ($bet > $user->minigame_points) { $echo = "This is more minigame points than you have!"; $chance = 0; } if ($user->minigame_points == 0) { $echo = "You do not have any minigame points."; $chance = 0; } if ($chance == 1) { //Win $money = $user->minigame_points+$bet; $times_bet = $user->times_bet+1; mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'"); $money = number_format($money); $echo = "You won $betPretty minigame points!<br /><b>Current Minigame Points:</b> $money"; } if ($chance == 2) { //Lose $money = $user->minigame_points-$bet; $times_bet = $user->times_bet+1; mysql_query ("UPDATE `users` SET `minigame_points`='" . $money . "', `times_bet`='" . $new_bet . "' WHERE `username`='" . $user->username . "'"); $money = number_format($money); $echo = "You lost $bet minigame points.<br /><b>Current Minigame Points:</b> $money"; } return $echo; Hello, I am learning php in a class for school and I was hoping I could get some help with some code. I am trying to make a game life counter. I just want it to have simple +1, -1 and reset buttons. I have gotten it to add and subtract the first time, but it will not continue adding/subtracting. Thank you for any help you can give. Here is the code I'm having issues with: <?php session_start(); ?> <form method="post" action =""> <input type="submit" name="name" value="Add"/> <input type="submit" name="name" value="Minus"/> <input type="submit" name="name" value="Reset"/> </form> <? lifeTotal(); function lifeTotal() { $_SESSION['total']=20; if($_POST["name"] == 'Add') { $_SESSION['total']++; echo $_SESSION['total']; } else if($_POST["name"] =='Minus') { $_SESSION['total']--; echo $_SESSION['total']; } } ?> Code: [Select] $startdt = $_POST['startdt'].":".$_POST['starttmh'].":".$_POST['starttmm'].":".$_POST['sAMPM']; // 09/08/2011:11:35:AM $enddt = $_POST['enddt'].":".$_POST['endtmh'].":".$_POST['endtmm'].":".$_POST['eAMPM']; //09/09/2011:11:35:AM From the code above I want to subtract 09/08/2011:11:35:AM from 09/09/2011:11:35:AM and get the total number of hours. A simple solution would be highly appreciated: thanks in advance: Hello, I am trying to subtract the current time from a list of times in a mysql database. The first page inserts the time into mysql.
<?php $var_Time = date("h:i:s"); $mysqli = new mysqli('localhost','root','blah','test'); if ($mysqli->connect_error) { die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); } $insert_row = $mysqli->query("REPLACE INTO test_table (id, time) Values(NULL, '$var_Time')"); if($insert_row){ while (false); }else{ die('Error : ('. $mysqli->errno .') '. $mysqli->error); } $mysqli->close(); ?>The second page is supposed to iterate through all of the times in the database and subtract the current time, but i cant figure out how to do it. <?php $mysqli = new mysqli('localhost','root','blah','test'); if ($mysqli->connect_error) { die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); } $query = "SELECT * FROM `test_table`"; $result = $mysqli->query($query) or die($mysqli->error.__LINE__); $var_set_time = stripslashes($row['time']); $var_current_time = date("h:i:s"); $diff = strtotime( $var_current_time .' UTC' ) - strtotime( $var_set_time .' UTC'); echo $diff; ?> Edited by Ch0cu3r, 09 October 2014 - 01:40 PM. Added code tags Im trying to execute an update sql query, but its not working. IDK if I got the right query tho what i want to do is, when the form is submitted, subtract 15 from the value 'creditleft'. So say the value is 20 , i want to subtract 15 and get 5. Here is the sql query im using; $query2="update userdata set creditleft = - 15 where username = '".$_SESSION['login_name']."'"; mysql_query($query2, $link); I dont get any errors, just no output I have somewhat of a dilemma. When someone clicks on a Buy Now button and subsequently follows necessary steps to complete process of purchase, when that transaction is completed, in my product table, I want to subtract 1 from whatever value is in the field. E.g. say product one is being purchased, prior to purchase in product table, there are 5 product one's in stock, when purchase is complete, subtract 1 from 5 (to get 4). Here is my code Code: [Select] <?php $title = "Like This Product, Buy It NOW!!!"; require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['prodID'])) { $query = "SELECT `prodID`, `product`, `prod_descr`, `image`, `price` FROM product WHERE `prodID`='{$_GET['prodID']}'"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['product'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<div id='item'>"; // div class 'item' echo "<div class='item_left'>"; echo "<p id='p_desc'>"; echo $row['prod_descr']; echo "</p>"; echo "<p>" . "<span>" . "£" . $row['price'] . "</span>" . "</p>"; echo "</div>"; echo "<div class='item_right'>"; echo "<img src='db/images/".$row['image']."' />"; $showHeader = false; echo "</div>"; ?> <p> <form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="7UCL9YCYYXL3J"> <input type="hidden" name="item_name" value="<?php echo $row['product']; ?>"> <input type="hidden" name="item_number" value="<?php echo $row['prodID']; ?>"> <input type="hidden" name="amount" value="<?php echo $row['price']; ?>"> <input type="hidden" name="currency_code" value="GBP"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </p> <p> <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="me@mybusiness.com"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="item_name" value="<?php echo $row['product']; ?>"> <input type="hidden" name="amount" value="<?php echo $row['price']; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> </p> <?php echo "</div>"; // End of div class 'item' $strSQL = "SELECT prodID, product, price, image FROM product ORDER BY RAND() LIMIT 1"; $objQuery = mysqli_query($dbc, $strSQL) or die ("Error Query [".$strSQL."]"); while($objResult = mysqli_fetch_array($objQuery)) { echo "<div class='love'>"; echo "<h6>Like this......you'll love this!!!</h6>"; echo "<ul>"; echo "<li>" . "<img src='db/images/" . $objResult['image'] . "' width='50' height='50' />" . "</li>"; echo "<br />"; echo "<li>" . "<a href='item.php?prodID={$objResult['prodID']}' title='{$objResult['product']}'>" . $objResult['product'] . "</a>" . " - " . "£" . $objResult['price'] . "</li>"; echo "</ul>"; echo "</div>"; } } } ?> <?php echo "</div>"; } include ('./includes/footer.html'); ?> How is this achievable please? I have setup a website that has a shopping basket and it displays the objects ordered in a table before being purchased, i have added a plus and minus button to adjust the quantity using the following code:
$add ="<form action='cart.php' method='post'><input type='hidden' name='additem' value='$id'/><input type='submit' name='itemadd' onclick='CheckQty()' value='+'/></form>"; $sub ="<form name='sub' action='cart.php' method='post'><input type='hidden' name='subitem' value='$id'/><input type='submit' name='itemsub' value='-'/></form>"; //add to quantity of item if (isset($_POST['itemadd'])){ $additem = $_POST['additem']; if ($qty < 5){ $addqty = $qty + 1; $adding = "UPDATE orders SET quantity = '$addqty' WHERE id = '$additem'"; $add_query = mysqli_query($db_conx, $adding); header('Location: http://www.quichlicious.co.uk/cart.php'); //print $additem; exit(); } else { $usemes = "You have reached maximum quantity"; } } //subtract to quantity of item if (isset($_POST['itemsub']) && ($_POST['itemsub'] !="")){ $subitem = $_POST['subitem']; if ($qty > 1){ $subqty = $qty - 1; $subing = "UPDATE orders SET quantity = '$subqty' WHERE id = '$subitem'"; $sub_query = mysqli_query($db_conx, $subing); header("location: cart.php"); exit(); } else { $usemes = "<font color='red'>Please use delete to remove item</font>"; } }The issue i have is it works great if just one item is in the basket but if i have more than 1 item in the basket i can only adjust the very last item in the baskets quantity and the others just randomly jump numbers or will not change at all? $additem gets the item ID from the table. Edited by mik_se7, 19 November 2014 - 10:14 AM. Please help me. I'm fairly new to php and have been looking for answers on Goog for about two weeks or so with not an answer. This is my first post on a forum of any type. I have a form on a php page that when submitted sends a value to a confirm php page Code: [Select] <form action='buyconfirmorder.php' method='post'> Purchase: <input type='text' name='ask_shares'><br /><br /> You Will Pay:  <input type='text' name='ask'><br /><br /> <input type='hidden' name='postcardname' value='$postcardname'> <input type='submit' name='submit' value='Order'> </form> I need to take the users input from the form and subtract each row from a mysql DB one at a time until the users input is down to a remainder and then I need the remainder (I'll be working with the remainder as well). Code: [Select] $query = mysql_query(" SELECT * FROM ask, search WHERE search.id = ask.card_search_id AND search.card_name = '$postcardname' ORDER BY ask_price ASC"); The array will be numbers only. So an example would be: User input from the form is 100.00 Code: [Select] while($rows = mysql_fetch_array($query)) { $ask_price = $rows['ask_price']; } Let's say the array is 50.50, 40.50, 35.00 I need some code to do: 100.00 - 50.50 = 49.50 49.50 - 40.50 = 9.00 9.00 - 35.00 = <0 does not do anything so remainder = 9.00 would it be something like Code: [Select] $new_ask_shares = $_POST['ask_shares']; //some sort of a loop or array or combo of both ($new_ask_shares - $ask_price); the numbers are just an example as the actual numbers will be different each time I query my DB. Thanks in advance I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } Good day I have three tables - receiving - shipping and stock movement. everyday i transfer into stock movent the sum of receining with date - havein a stock movent entry per day - I also at end of day update with shipping for that day, in stock table I calculate ne stock level. my problem is that when three days bac i stil have stock i need to start subtracting from oldest entry first till it reaches 0 the move over to second eldest? i have no idea where to start or how to achieve this |