PHP - Probably Easy Question About Operators
While going through an instructional book, I ran across some code that I didn't immediately understand. I've stripped it down to the relevant bits:
function example($object_a, $object_b) { $compare = $object_a->id == $object_b->id; return another_function('argument 1') && $compare || another_function('argument 2'); } My first confusion was this line: $compare = $object_a->id == $object_b->id; Does this set $compare to TRUE if the ids match and FALSE if they do not? And the second confusion: return another_function('argument 1') && $compare || another_function('argument 2'); What is returned if the ids match? What is returned if they are different? When I try testing this out on my machine, it returns both functions whether or not the ids match, but I know that's not what's supposed to happen. Can anyone break this down for me? Thanks. Similar TutorialsI need make error lower then 3 and higher then 15 how should i add higher then 15? Code: [Select] if (strlen($searchTerms) < 3) { $error[] = "Add more then 3 symbols and less then 15!"; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } I want to know can we do text formatting to a result coming from echo if so then kindly guide how? Right now I'm working on a simple register form and I have included the theme. I set up a div and positioned the div below the register form to output any error in red text. If I were to use code like this if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['Veremail'])){ $required_info = "All three fields are required to continue!"; } It will not work, because I don't have a die(); or end(); function, so it will display: " All three fields are required to continue! and You have been successfully registered! " BUT IT'S IN THE CORRECT PLACE UNDER THE FORM WHERE I PLACED THE DIV. So I made this change if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['Veremail'])){ $required_info = die("All three fields are required to continue!"); } and it worked fine, but now, the words are not positioned under the form, but at the bottom of the page, I'm wondering how I would end that script, but align the text so it displays underneath the form, and not at the bottom of the page? If you don't understand ask me please. hello. i want to know what is *$ or +$ because i see it in many contact forms. also, what is the difference between these: /^[A-Z]+[a-z]*$/ /^[A-Z]+[a-z]+$/ /^[A-Z]+[a-z]$/ /^[A-Z]+[a-z]/ also, which is the shortest and efficient method of checking somebodys name to be exactly "Name Surname" - "Green Trancer" ? in my form, i use var filter = /^[A-Z]+[a-z]*$/; var filter2 = /^[A-Z]+[a-z]+\s+[A-Z]+[a-z]+$/; and then i check the name to be like filter or filter2. how can i check that between the words to be exactly one space character ? thank you very much. So I am extending the DateTime class and would like to completely disable the modify() function that is built in so i have this: Code: [Select] <?php class NewDateTime extends DateTime { public function modify() { throw new Exception('modify() has been disabled.'); } } thats not the entire class description, just the pertinent part of course now any time I create a new object from NewDateTime I get this message at the top of the screen: Quote Strict Standards: Declaration of NewDateTime::modify() should be compatible with that of DateTime::modify() in C:\xampp\htdocs\.....my file path here.....\NewDateTime.php on line 62 what gives? how do I get rid of this and still disable modify()? I'm betting its a setting that i have wonky but I am really rusty in php so dont know where to look in php.ini Hey people! I've been setting a coding script for experience and this is my situation: To buy a virtual flower, one needs to have 50 virtual coins. So I first extract the number of coins the person has from the DB. If the user doesn't have the sufficient number of coins, the BUY button will not be available and vice versa. When the BUY button is clicked, I update the database, adding the flower to the user's inventory and subtracting 50 from the total number of coins the user has. This I do in that page itself using if(isset($_POST['submit'])) Now, I need to know how I could check whether the user has at least 50 coins even if the button is available. I hope that you could understand this. I want to do it for validation purposes. Its to prevent the user spending the coins he has in another browser window and then returning to the visible button to click it. I hope that I make sense. Thanks in advance! Regards, Thauwa I'm trying to search the 'ad' column where 'ad' = 1 or 3 I'm having problems doing this. Here is what I currently have, but it is not bringing back 'ad' where ='1' (for obvious reasons) Quote $query = "SELECT * FROM users WHERE ad='3' AND state='$state1'"; Here is what I thought would work, but it displays every listing in my database when I do it this way. Quote $query = "SELECT * FROM users WHERE ad='3' OR ad='1' AND state='$state1'"; Thank you in advance for your answers, google is not being so kind to me right now. Hello Everybody
I usually work with C#, but I'm doing a website right now and have a question:
I want a picture in my header and when I change the window size the image may not move.
My code so far:
#a1 { position: relative; top:-175px; left:0px; width:50px; height:50px; background-image:url(http://domain.png); background-repeat:no-repeat;} </style>Hope someone can answer this question easy Wow, am I glad I found this forum! I spent the past few hours trying to modify a PHP/mySQL script in order to test it. What this script does is basically look up a mySQL database (based on ip2nation) to find out what country and currency the IP address belongs to. This is the code sample: Code: [Select] $sql = 'SELECT c.country, c.curr_code FROM ip2nationcountries c, ip2nation i WHERE i.ip < INET_ATON("24.24.24.24") AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1'; $countryName = $db->get_sql_row($sql); I tested the code in PHPmyAdmin and it returns 2 rows: country ------- curr_code (row names) United States ------- USD (actual values) So basically 2 variables, United States and USD. Now comes the problem, in order to test the script for several countries, I need to be able to "override" the result in the PHP script I tried to do that by commenting out the part that returns the result from the mySQL query and modifying it with the following style, but I think I'm doing something wrong: Code: [Select] ### $countryName = $db->get_sql_row($sql); ### $countryName = "United States USD"; Is there any way that I can temporarily override the result returned by mySQL and "fake it" so to say? I understand the mySQL query returns 2 rows, so how would I go about overriding 2 rows? I hope this makes sense ...you're all my last hope. How can I use an include file that has a list of links in any directory at my website without breaking those links? You can see it in action here... The links in this directory work... https://www.billelgin.com/primary-directory/ The links in this directory (being created from the same include file) do not work... https://www.billelgin.com/primary-directory/subsection-one/ Obviously the problem is the include file is being called from different directories, so it's breaking the relative path links in the include file, but what can I do to fix it? You can download the example directory structure here... https://www.billelgin.com/EXAMPLE.zip Alright, so I just started picking up PHP again and I have a pretty simple question. I have a html form that takes a string then writes it on another page. My problem is when I use quotations I'll get slashes in them on the page it writes the string on. Is there a way to clean that stuff up? I am very new to php and am trying to create a simple application that uploads a PDF file to a database. I have one field for the Volume Number and on file field for the PDF to be uploaded. My issue is i can't get the PDF to upload or insert the name of the pdf (eg volume1.pdf) into the data base. I would also like to point out that I know i have a low post count, but i only seek help when i truly need it and have exhausted all other resources... Here is what i have, please go easy on me this is my first round at php: Code: [Select] <?php if(isset($_POST['submit'])){ $vol_num = $_POST['vol_num']; $pdf = $_FILES['pdf']['name']; $path = '../pdf/'.$_FILES['pdf']['name']; move_uploaded_file($_FILES["pdf"]["tmp_name"], $path); mysql_query("INSERT INTO volumes set vol_num='$vol_num', vol_link='$pdf'") or die (mysql_error()); echo "<script>location.href='add_volume.php'</script>"; } ?> what am i doing wrong here? Thanks in advance Hi guys! I am trying to understand why the final value of $m equals 40 in the following code Code: [Select] <?php $i = 29; $j = 11; $m = 10; $j = ($j - 4) / 2; $m += $j * 10; echo "m = ".$m."<br>"; //Equals 40 ?> Can anyone explain me please? I feel very confused right now. I came across these pieces of code and have been trying to understand this operator -> Or if it is a operator. I have searched and couldn't find explanations. In trying to learn I need to know what is is used for. Is it used only with classes? $m->myMethod(); return $this->x; I have a query that is very messy. I have tried using () to seperate everything and when I do it just all goes wrong. here is the query SELECT posts.*, users.*, countries.countryID, countries.country FROM posts INNER JOIN users ON users.userID = posts.postUserID INNER JOIN countries ON countries.countryID = users.userCountry WHERE posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'sightseeing' OR posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'Inner city sightseeing' OR posts.cityID = '".$row_rs_city['cityID']."' AND posts.type = 'Outer city sightseeing' ORDER BY posts.postID DESC Is there a way of re-writing this so that it has brackets seperating everything and it will still work. It works for the minute but re- writing posts.cityID = '".$row_rs_city['cityID']."' inbetween every OR just seems wrong. Thanks for your help guys Hi every one, I just want to know what is the use of '<<' and '>>' operators in php i'm trying to develop a deeper understanding of sessions, and I found this article on php.net regarding sessions with the following script;
<?php // Get the private context session_name('Private'); session_start(); $private_id = session_id(); $b = $_SESSION['pr_key']; session_write_close(); // Get the global context session_name('Global'); session_id('TEST'); session_start(); $a = $_SESSION['key']; session_write_close(); // Work & modify the global & private context (be ware of changing the global context!) ?> <html> <body> <h1>Test 2: Global Count is: <?=++$a?></h1> <h1>Test 2: Your Count is: <?=++$b?></h1> <h1>Private ID is <?=$private_id?></h1> <h1>Gloabl ID is <?=session_id()?></h1> <pre> <?php print_r($_SESSION); ?> </pre> </body> </html> <?php // Store it back session_name('Private'); session_id($private_id); session_start(); $_SESSION['pr_key'] = $b; session_write_close(); session_name('Global'); session_id('TEST'); session_start(); $_SESSION['key']=$a; session_write_close(); ?> [EDIT BY danbrown AT php DOT net: Contains a bugfix provided by (lveillette AT silexmultimedia DOT com) on 19-NOV-09.]I do not understand line 21 and 22. <h1>Test 2: Global Count is:<?=++$a?></h1>If I change this to; <h1>Test 2: Global Count is:<?php echo =++$a; ?></h1> or <h1>Test 2: Global Count is:<?php =++$a ?></h1>I would get a parse error, unexpected "=" in line 21. Can anyone explain why this is? * Why is it being echoed * Why can I not use echo in this case * Why does the code not start with <?php ? * What does line 21 even mean? =++$a? Thanks in advance guys! Edited by empec, 13 July 2014 - 11:30 AM. I'm trying to get an equation from a user that types it in the url, ex) 1+2+3. I can get the 1,2,3 fine, but the + operator is no longer in the string. Same with the * and / operators. Is there a way to keep them as a string using $_GET?
In php is there a way to shortcut logical operators... example: Code: [Select] if ($row['CustomerSaas'] == 'Yes' && ($row['CustomerSaasPaidStatus'] == 'Trial' || $row['CustomerSaasPaidStatus'] == 'Trial Ended')) { to Code: [Select] if ($row['CustomerSaas'] == 'Yes' && ($row['CustomerSaasPaidStatus'] == 'Trial' || 'Trial Ended')) { hi everyone
i keep seeing the following Comparison Operators:
<>i see it used in the following context: if ($connection <> 'SSL') { $connection = 'NONSSL'; }be grateful if somone would tell me what it means, i looked online but could not find the symbol thanks |