PHP - Greater Than And Less Than Problems Php
Hi im pritty new to PHP used to using ASP but found PHP to be more resourcful!
Anyway, Im trying to work out how to get my script to define if a prduct fee is higher than an available account balance, but hitting brick walls! CODE BELOW: $Credits = 10; $Fee = 5; if ($Fee > $Credits){ //NEED MORE CREDITS }else{ //YOU CAN PURCHASE THIS ITEM } But returns that 10 is not greater than 5, i guess this is because it is only taking the first digit into consideration, even if it is 12 or 15 is still says its not higher than 5 ??? Ive been at it for hours searched google and come up with nothing... please help I may be acting thick and it may be really simple but im lost! Thanks in advance! Similar Tutorialshello, how would i write if $dollars is greater than 5 or less than -5? thanks! how do I write a statement using a greater than and less than Code: [Select] if($soandso >=4 && <=6) {}how would I do something like this? Hi, My example: $setting = 4 //can challenge if opponent has 4 points lesser than you $team1 = 13; //challenger points $team2 = 7; //points In my above case, it should return false because 13-7 = 6, $team2 has 6 points lesser than team 1. If team2 had 4 points or lesser, it should return true. Can someone write the if() statement for me please? Appreciate that alot. Thanks $file = 'includes/views.txt'; $f = fopen($file, 'w+'); $views = fread($f, filesize($file)); fwrite($f, $views+1); fclose($f); The contents of views.txt is: Code: [Select] 1 Why is it returning it needs to be greater than 0?...The file isn't empty. Hi, i am trying to write a part of script for google shopping export, and all i want is that in this line, everything that is 0 or smaller, the line "pre-order" krijgt and everything that is 1 or greater the line "in stock" This is what i've got now, but it doesn't work I removed the rest of the long code. Code: [Select] $patterns = array(); $patterns[0] = '=<0'; $patterns[1] = '=>1'; $replacements = array(); $replacements[0] = 'vooraf bestellen'; $replacements[1] = 'op voorraad'; if(OPTIONS_TONEN_FEED_AVAILABILITY == 1) $output .= "~" . preg_replace($patterns, $replacements, $row->quantity); I wrote a code to echo "limit reached" if A is greater than B. But if A is 400030 and B is 400000 it shows no output. If A is further greater than that, let say 400060 or any number higher than that, it shows the output.. Please how do I explain that? The code snippet to demonstrate what I mean is....
<?php include_once('db.php'); error_reporting(E_ALL | E_WARNING | E_NOTICE); ini_set('display_errors', TRUE); if (session_status() == PHP_SESSION_NONE) { session_start(); } if(!isset($_SESSION['login'])) { echo ("<script>location.href='../clogin/'</script>"); die(); } if(isset($_POST['transfer'])) { $username = $_SESSION['login']; $transAmount = $_POST['transAmount']; $totalTrans = $transAmount + 30; $sql = "SELECT * FROM customer WHERE username = ?"; $stmt = $connection->prepare($sql); $stmt->bind_param('s', $username); $stmt->execute(); $result = $stmt->get_result(); if(!$result) { die('ERROR:' . mysqli_error($connection)); } $count = $result->num_rows; if($count == 1) { while ($row = $result->fetch_assoc()) { $accTrans = $totalTrans + $row['dailyTrans']; $sql2 = "UPDATE customer set dailyTrans=? WHERE username=?"; $stmt = $connection->prepare($sql2); $stmt->bind_param('is', $accTrans,$username); $stmt->execute(); if(!$stmt) { die('network problem'); } if($row['dailyTrans'] >= $row['dailyLimit']) { echo '<script>swal.fire("FAILED!!", "<strong>You have reached the total amount you can send per day.</strong><hr><br/><i>Visit your bank to increase transfer limit.</i>", "error"); window.setTimeout(function(){ window.location.href = "transfer1.php";} , 1700); </script>'; //exit(); } else { echo""; } }//while loop }//count }//submit ?>
My question Summary Again The value for $row['dailyTrans'] is 400030 and the value of $row['dailyLimit'] is 400000 This is suppose to echo out the error but fails... if $row['dailyTrans'] is greater than 400030, it echoes out. What is the logic behind that?. Please be nice with your comments as usual. Thanks . Both Value are integers!! . The code works well just that at 400030 it doesn't output that its greater than 400000
i tried > and < but would work very well.. Code: [Select] include("connect.php"); $getbookings = mysql_query("SELECT * FROM phpbb_posts WHERE forum_id='17' ORDER BY post_subject ASC AND post_subject > $date"); just so you know.. that post subjects are dates formatted YYYY/MM/DD.. so they can be sorted. and i would like this code to select a the ones that are greater than or less than todays date.. can someone help me please? thanks I would like to send an email when % is >than 50%, if so get fields from Txt fiel and fields from DB and send an email to the address in the txt file.
<html> <head><title>Email Alert</title></head> <body> <?php require 'PHPMailerAutoload.php'; $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output mysql_connect("ip","user","pass") or die(mysql_error()); //mysql_select_db("DB") or die(mysql_error()); //$sql = "SELECT * from pool"; $sql = mysql_db_query ("demo", "select * from pool "); while ($row = mysql_fetch_assoc($sql)) { $sql = "SELECT '%' FROM pool Where >= 50 "; { //echo $row->number; $percent = $row['%'] ; $pool2 = $row['pool']; $balance = $row['balance']; /////////////////////////// //data from file ////////// ////////////////////////// $file = fopen('EmailAndPool2.csv', 'r'); $fields = array(); if ($file) { while (($data = fgetcsv($file)) !== false) { if(empty($fields)) { $fields = $data; continue; } $row = array_combine($fields, $data); // Format output conveniently with sprintf $output = sprintf("%s Pool %s email.\n", $row['pool'], $row['email']); echo $output; } fclose($file); $pool1 = $row['pool']; //while ($pool2 == $pool1 and $percent > "50") $pool2 =$row['pool2']; $mail = new PHPMailer; $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'xxxxxxxxx; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'xxxxxxxxxxxxxxxxx'; // SMTP username $mail->Password = 'xxxxxxxxxxxxxxxx; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to $mail->FromName = 'Support'; $mail->addAddress ($row['email']); //$mail->addAddress = $members; //$mail->addCC('xxxxxxxxxxx'); //$mail->addCC('xxxxxxxxxxxxxxxx'); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); $mail->Subject = 'test'; $mail->Body = 'test '; $email_from = 'xxxxxxxxxxxx'; } if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } } ?> </body> </html>Thank you Hi guys, Probably going to be a very basic question but i'm lost, i'm trying to figure out how to display an image if the value returned is equal to or greater than a certain number, more of a hypothetical question at the moment, Thanks in advance still shows all records in the database... any idea how i go about this? Code: [Select] $date= date('y-m-d'); $query=mysql_query("SELECT * FROM listing WHERE date >= $date") or die (mysql_error()); class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); It display a blank page like attachment result1.jpg, but if I move the $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); from function debug() and join it with function execute() like this: public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } it return me Linuxformat content ( expected result ) like result2.jpg below is the working code : class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); Why I couldn't split "CURLOPT_STDERR, CURLOPT_RETURNTRANSFER" with "curl_exec" the image in my comments box wont show up it gives me an error Code: [Select] Notice: Undefined index: avatar in /home/ecabrera/public_html/profile.php on line 277 and i dont whats wrong with it Code: [Select] // display comments $perpage = 10; $start=0; if(@$_GET['s']) $start = $_GET['s']; $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' ORDER BY id DESC LIMIT $start, $perpage"); $numrows = mysql_num_rows($query); if ($numrows > 0){ $next = $start + $perpage; $prev = $start - $perpage; while($row = mysql_fetch_assoc($query)){ $user_id = $row['user_id']; $user_name = $row['user_name']; $comment = nl2br($row['comment']); $date = $row['date']; $avatar = $row['avatar']; echo "<img src='avatars/$avatar'></img><a href='$site/profile?id=$getid'></a> <b> on $date</b><br />"; echo "<div style='margin-left: 10px;'>$comment</div><hr>"; } } else echo "This user has no profile comments.<br />"; // end diplay comment area Hi I have plans in developing a connect function for remote login to my web side. I can't find any useful on Google. Some idees on how to code a API connect button? Something similiar to Facebook connect, Twitter connect etc. BUT this should not rely on facebook api. I'm going to make my own stand alone api. I know I need to use REST in backend, but I'm missing the knowledge to know how to send / recive the login data, and how to know when a user are online or not. I'm greatfull for any help. Also links. And also tips on how to make a developer plattform for apps, much like the way Facebook have it. Hello, Alright I am having a few issues here. Let me explain what I am doing...this is a script that allows a customer to split an order..he can split certain items out of one order and it will create another order with the items he split added to this order, and then subtracting the items from the old order. The products are stored in one field called products, they are stored in a delimited list like this qty, product name, price each, product id | qty, product name, price each, product id |etc. Now, before you say why are you storing your products like that?? The reason I have to store my products like so is because the customer does not want the products stored in the order table to be dependent off the products table like they were before. In that case if he modified a product it would modify all of the orders with that product stored in them. Make sense? I am aware a delimited list probably wasn't the best way to do this but it was the best way I could think of. Ok here is my list of issues. 1) Everytime you split an order, it is not creating a new order to store the items that were split into. It created an order the first time I did it, and now all it does is it keeps updating the products field in that order, rather than creating a new order. 2) Next I do not know how I can update the old products (stored in the $prod array). It needs to update the products qtys after the order was split, and then if all of the qty for that product were moved to the new order it just needs to remove that product from the $prod array rather than updating the quantity. The code is below. Please let me know if I can provide any more information to help! Thanks everyone! // Get Old Order $get_order = @mysql_query("SELECT * FROM orders WHERE order_id = {$_POST['order_id']}"); $order = @mysql_fetch_assoc($get_order); // Get Old Order Items $products = $order['products']; //breaking products text down for display $prod = array(); $_products = explode('|', $products); foreach ($_products AS $p) $prod[] = explode(',', $p); /* $get_items = @mysql_query("SELECT product_id, qty FROM order_items WHERE order_id = {$order['order_id']}"); $items = array(); while(($row = @mysql_fetch_assoc($get_items)) !== false) { $items[] = $row; } */ if(empty($prod)) { header("Location: tracking.php"); die(); } // Create New Order mysql_query("INSERT INTO orders SET customer_id = {$order['customer_id']}, order_status = {$order['order_status']}, order_date = '{$order['order_date']}', order_date_paid = '{$order['order_date_paid']}', order_shipping = '{$order['order_shipping']}', order_shipping_fee = '{$order['order_shipping_fee']}', order_insurance = '{$order['order_insurance']}', order_insurance_fee = '{$order['order_insurance_fee']}', order_insurance_total = '{$order['order_insurance_total']}', order_grand_total = '{$order['order_grand_total']}', order_date = '{$order['order_date']}', order_filled = '{$order['order_filled']}', order_ship_date = '{$order['ship_date']}'"); $get_new_order = @mysql_query("SELECT MAX(order_id) AS order_id FROM orders") or die(mysql_error()); $new_order_id = @mysql_result($get_new_order, 'order_id', 0); // Add Items to New Order & Remove Items from Old Order $new_items = array(); $_new_items = ''; foreach($prod as $p2) { for($i = 0; $i < $p2[0]; $i++) { if(!empty($_POST[trim($p2[3]).'_'.$i])) { $new_items[trim($p2[3])]++; } } } //construct new static products list foreach($new_items as $id=>$qty) { $get_product = mysql_query("SELECT name, price FROM products WHERE product_id = '{$id}'"); $got_product = mysql_fetch_assoc($get_product); $_new_items .= $qty.','.$got_product['name'].','.$got_product['price'].','.$id.'|'; //echo $id.' - '.$qty.'<br>'; } //remove last character in products text before going into DB $_new_items = substr_replace($_new_items ,"",-1); //update products field in new order mysql_query("UPDATE orders SET products = '{$_new_items}' WHERE order_id = '{$new_order_id}'"); Hi, I hope someone can help me. I am trying to generate a script for our Intranet that tells me which birthdays = today. My field in my table = d/m/y, eg 09/05/2011 (9 May 2011). How do I get the script to just look at the day & month, not the year? My script looks like this: Code: [Select] <?php echo date("d/m/Y") . "<br />"; $myDate = date('d/m/Y'); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); $sql = "SELECT * FROM detail WHERE dob='$mydate'"; $result=mysql_query($sql); echo mysql_num_rows($result); ?> First Since I first started learning PHP, I've been writing code for forms like this: $name = $_POST["name"]; if ($name == "") { echo "You didn't type anything"; } I've written scripts like this and tested them on a GOdaddy server, and they always worked fine. Now, after testing scripts like that on my own server (WAMP2 [PHP5, Mysql, Apache]), I get an error saying "Unidentified index: name", and so I have to nest that if statement AS WELL AS the variable assignment inside another if statement like this: if (isset ($_POST["name"])) { $name = $_POST["name"]; if ($name == "") { echo "you didn't type anything. } } The error doesn't actually stop the script from running, but a medium sized box appears in the browser with the error message contained that's after the element in the document of which is getting an invalid error. Which way is truly the correct way? Because now that I have to use the second way in order for my scripts to run correctly on my own server, I have to write more code and it all gets disorganized and more complicated to read. So...is this a configuration thing that I can tweak in WAMP2 to stop messages like that from popping up? Or is the second way the way you're supposed to do it? Also, I was wondering why ereg got deprecated and what the replacement of it is in PHP5? I've asked before and even googled it but I simply get taken to a "Pearl" function on PHP.net. I'm not sure what it is, or how to use it, and haven't got any hints from either PHP.net or anywhere else. Any suggestions? I'm trying to either update my database if some data matches the if statement, or insert the data in a new row if it doesn't match (if possible). The code will update the database just fine if the data matches, but if not, it won't insert the new data. (When I leave off the if statement it will insert just fine). I fear I'm not using the if...else correctly. Thanks for any help. <?php header("Location: admin_schedule.php"); include("opendatabase.php"); $date=("$_POST[gamedate]"); $week=("$_POST[Week]"); $game=("$_POST[Game]"); $hometeam=("$_POST[team_name_1]"); $awayteam=("$_POST[team_name_2]"); $check = mysql_query("SELECT week_id,game_id FROM schedule"); $row[] = mysql_fetch_array($check); if ($row[week_id]='$week' && $row[game_id]='$game') { mysql_query("UPDATE schedule SET week_id = '$week', game_id = '$game', date = '$date', H_team = '$hometeam', A_team = '$awayteam' WHERE week_id = '$week' AND game_id = '$game'"); } else { mysql_query("INSERT INTO schedule (week_id,game_id,date,H_team,A_team) VALUES('$week','$game','$date','$hometeam','$awayteam')"); } mysql_close($con); I want to gettwitter feeds, this gives me a xml http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3 based on this: http://www.w3schools.com/PHP/php_xml_simplexml.asp i try to get the xml with: <?php$xml = simplexml_load_file("http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3");?>() i get this error: Quote Warning: simplexml_load_file(http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/vhosting/x/vhost0033377/domains/doekewartena.nl/htdocs/www/temp/twitter03.php on line 2 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3" in /home/vhosting/x/vhost0033377/domains/doekewartena.nl/htdocs/www/temp/twitter03.php on line 2 i have no clue, i'm very new to php can i even use simplexml_load_file cause it has no .xml file type extention. Hello all. I'm pretty new to this, but I'm trying to build a script that will write random questions for a quiz app that I'm working on. The data is contained in two different tables. I'm trying to randomize the question order that is spit out, as well as randomize the answer order that is displayed. The output has to be in the specific JSON string that is denoted in the code. There are no errors when I go the url that I load the script, however, the string is not populated with any of the data from my tables (it is just an empty set of strings in the JSON format that the program requires. Could someone please take a look at this and tell me where I'm going wrong. I've checked that the query is pulling from the correct databases so I know that's not the problem. Thank you in advance. Code: [Select] <?php //Connect To Database $hostname=""; $username=""; $password=""; $dbname=""; $question_table="wp_mtouchquiz_question"; $answer_table="wp_mtouchquiz_answer"; $yourfield = "question"; $question = "question"; $answer = "answer"; $connection = mysql_connect($hostname, $username, $password); $lastQuestionID = -1; $str = ""; mysql_select_db($dbname, $connection); # Check If Record Exists $query = "SELECT * FROM $question_table q, $answer_table a WHERE q.ID = a.QUESTION_ID AND q.quiz_id = 1 ORDER BY question_id ASC, correct DESC"; $result = mysql_query($query); $questions = array(); $fields = array(); if($result) { while($row = mysql_fetch_array($result)) { if($lastQuestionID != $row["question_id"]) { $fields = array(); if($lastQuestionID != -1) { array_push($questions, $fields); } $fields = array(); $lastQuestionID = $row["question_id"]; $fields["question_id"] = $row["question_id"]; $fields["question"] = $row["question"]; } // correct if($row["correct"] == 1) { $fields["correct"] = $row["answer"]; } // incorrect if ($row["sort_order"] ==2) { $fields["incorrect0"] = $row["answer"]; } // incorrect if ($row["sort_order"] ==3) { $fields["incorrect1"] = $row["answer"]; } // incorrect if ($row["sort_order"] ==4) { $fields["incorrect2"] = $row["answer"]; } if ($row["sort_order"] ==5) { $fields["incorrect3"] = $row["answer"]; } } $str .= "{\"childItems\":["; $numQuestionsToUse = 172; //Set this larger than returned questions or less than row limit / 5 $randomQuestionKeys = array_rand($questions, $numQuestionsToUse); $numQuestions = count($randomQuestionKeys); for($i = 0; $i < $numQuestions ; $i++){ $pickedField = $questions[$randomQuestionKeys[$i]]; $str .= "{\"itemId\":\"question" . $pickedField["question_id"] . "\","; $str .= "\"itemType\":\"BT_questionItem\","; $str .= "\"questionText\":\"" . $pickedField["question"] . "\","; $str .= "\"correctAnswerText\":\"" . $pickedField["answer"] . "\","; $incorrectAnswers = array(); array_push($incorrectAnswers, $pickedField["incorrect0"]); array_push($incorrectAnswers, $pickedField["incorrect1"]); array_push($incorrectAnswers, $pickedField["incorrect2"]); array_push($incorrectAnswers, $pickedField["incorrect3"]); $incorrectAnsKey = array_rand($incorrectAnswers, 3); $str .= "\"incorrectText1\":\"" . $incorrectAnswers[$incorrectAnsKey[0]] . "\","; $str .= "\"incorrectText2\":\"" . $incorrectAnswers[$incorrectAnsKey[0]] . "\","; $str .= "\"incorrectText3\":\"" . $incorrectAnswers[$incorrectAnsKey[0]] . "\","; $str .= "\"imageURLSmallDevice\":\"http://www.myquizcoach.com/extras/images/clear_header.png\","; $str .= "\"imageURLLargeDevice\":\"http://www.myquizcoach.com/extras/images/clear_header.png\"},"; } // remove last comma $str = substr($str,'',-1); $str .= "] }"; echo $str; } ?> |