PHP - Where Can I Learn About Using ? : In My True Or False Code
i keep seeing people use this kind of code but i cant find any document or help web pages on it. im sure there is but i done know what to call it.
i would really like to learn more about it for example Code: [Select] $lang = isset($_GET['lang']) ? (int)$_GET['lang'] : 1; or Code: [Select] return !empty($result_array) ? array_shift($result_array) : false; Similar TutorialsJust a silly question. I've been using 1 and 0 to tell if something is true or false, such as if a feature is enabled or not. I see that some use the words true and false. Is there a proper way or is either way correct? Thanks! I am trying to take all the information from $results and input it into a text file, sometimes we get duplicates in $results so I want to check the text file for the entry before writing it in so we don't get duplicates in the text file. However inarray keeps returning false, even when I echo out the two arrays and they match? Code: [Select] $myfile = "complete.txt"; foreach ($results['info'] as $data) { $output=$fields['firstname']."|".$record['lastname']."|".$record['address']."|".$record['number']."\n"; $handle = fopen($myfile, "r"); $contents = fread($handle, filesize($myfile)); fclose($handle); $list = array(); $list = explode("\n",$contents); $list = array_map("trim", $list); $current = $output; echo in_array($current,$list) ? $current.' exists' : $current.' does not exist'; if (in_array($current,$list)) { print "duplicate"; } else { if($file=fopen($myfile, "a")) { //open file for writing fwrite($file, $output); //write to file } } } Ok I guess this is more a algorithm problem than a php problem, but still I hope someone can help me. I'm trying to write some code that starting from two arrays containing observed and expected values will calculate true and false positive and negative rates of a certain event. Let's say I have 30 events and 5 of them are really red while 25 are blue. (each event is identified by an unique id i.e. number) An observer is required to evaluate the 30 events and answer if they are red or blue, their answer (only if blue if stored in the observed array - in the form of a position id) So in the end I have one array that has the observed red events i.e. 4 56 78 44 90 and the expected array with the actual red events i.e. 4 78 33 34 In this case my true positive would be 2 (4 and 78 that are both in the observed and the expected), my false positive would be 3 (observed but not expected), my false negative 2 (expected but not observed) and my true negative 23 (not expected and not observed, obtained substracting the previous three from the total number of events) How can I calculate this four values using PHP, I thought it was easier but as I started to program it I realized I didn't know where to go Thanks to all! MySQL cannot store Boolean values and thus I use 0/1. Is there much benefit to cast them as Boolean immediately after querying the database, do whatever PHP processing is required, and then convert them back to 0/1 before writing to the database? One benefit is I can type declare my arguments, but I am debating whether it is worth it. Thanks I have been trying to write code that deletes a book from a database if the user provides a BookName, and the corresponding DeletionCode. I then want to provide the user with feedback, telling the user whether they have deleted a book, that is they have provided a deletion code and a book name, or whether they have not deleted a book, because they have entered the wrong bookname or book ID. I thought this code would work, but it seems that the $result variable is always set as TRUE, no matter whether the code has deleted a row or not. What have i done wrong? $result = mysql_query("DELETE FROM books WHERE BookName = '$_POST[BookName]' && DeletionCode = '$_POST[Deletioncode]'"); if(!$result){ die('Invalid query: ' . mysql_error()); } else echo "delete book"; Hey Everyone, I want to start out by saying thanks in advance for reading this. Since I started working with the XAMPP package this community has been a great resource, though this is my first post. most of my work has been modifying existing stuff in our network, this is my first project from scratch. I am working on an access control project where I am storing site names and RFID tags in a table, and using PHP to check for existing records. Basically, I want to submit 2 credentials from a host (site and RFID), check if they exist together in the table, if so return TRUE or 1, if not return FALSE or 0. I am new to both PHP and MySQL (although I took a course years ago) so I am looking here for help. On this server I have XAMPP installed and everything I need running. I have a table and created a few records for testing. My current trouble is getting PHP to return the proper values for the SQL query. The SQL query works fine, I think - it returns the number of rows that match and that record. I'm not sure this is the result I need to be able to deal with the way I want. Using other resources my current PHP statement looks like this: Code: [Select] if(mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE 'site_name' LIKE 'berland' AND 'card_id' LIKE '290093C84E' LIMIT 0 , 30"))>0){echo '1';} else {echo '0';} So, my table has the entry as noted in this query above. Final one will be dynamic where the host will be sending those values - I will likely need help with that as well, but small steps first.;-) Anyway, I was playing around with the end statement >0{echo '1';} but wasn't able to make it do what I want. Any help is appreciated. Thank you. Aaron This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=330649.0 Should one learn object oriented programming first, before getting to learn a framework?
I have been interested in CakePHP.
hi there, is there a difference between if($var == false) and if(false == $var) thankyou! $looponce = 1; foreach ($this->info as $k => $v) { if ( (($k == 'subject') && ($v['required'])) && (!$this->settings['customSubject'])) { for ($i = 0; $i <= 0; $i++) { $output[] = $this->display_errors('error_system_subject'); } } if ( (($k == 'name') && (!$v['required'])) || ((!array_key_exists("name", $this->info)) && ($looponce == 1)) ) { $output[] = $this->display_errors('error_system_name'); $looponce++; } } That is my loop that i check things in. What i'm more interested in is the name if statement. If currently checks for a name key in an array(below) and makes sure that it is set to required. If it's not set to required, print out a system error and die()'s. I'm looking for ways to remove the need for program errors and just change them to what is needed to run. What i know how to do is, get into the inner array, what i don't know is how to edit the data and put it back exactly as it was given to me. The inner array data can be put back in any order, but the outer array must be in exact order as it was given. above code $this->info = $formdata; $formdata = array( 'name' => array('name'=>"Full Name", 'required'=>false, 'type'=>'text'), # This needs to be required=>true, but i can't trust the user, which is why i have the error. 'telephone' => array('name'=>"Telephone", 'required'=>false, 'type'=>'phone'), ); Any help is greatly appreciated, also am i doing the foreach loop in the code above in an efficient manner or is there another way? Ok figured I'd go out and try to write me something for my site that I want and can't seem to be able to find what I want...sooooooooooo
I'm trying to create an NFL score 'ticker' and so far I've gotten as far as fetching the xml.. that part works LOL
I have been sitting here for a few hours trying to figure out how to do a foreach statement that works... I've hit a brick wall because I just can't seem to figure it out...
I have even tried a few I've found in other places but no go...
Here is what I have so far:
<?php $url="http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); $xml = simplexml_load_string($data); print_r($xml); //just keeping this here so I can see it for now ?>I know that part is working as you can see I left the print_r in it temp so I can still see I"m getting what I need... Again the problem is I'm not getting a functional foreach that I can get to work.. I either get nothing back or an error of some kind and trust me I've tried as many as I could find LOL SimpleXMLElement Object ( [gms] => SimpleXMLElement Object ( [@attributes] => Array ( [w] => 18 [y] => 2014 [t] => POST [gd] => 0 [bf] => 0 [bph] => 0 ) [g] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010301 [gsis] => 56492 [d] => Sat [t] => 8:15 [q] => P [htn] => Pittsburgh Steelers [hnn] => steelers [h] => PIT [hs] => 0 [vtn] => Baltimore Ravens [vnn] => ravens [v] => BAL [vs] => 0 [n] => NBC [rz] => 0 [ga] => [o] => 1 [gt] => WC ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010400 [gsis] => 56493 [d] => Sun [t] => 1:05 [q] => P [htn] => Indianapolis Colts [hnn] => colts [h] => IND [hs] => 0 [vtn] => Cincinnati Bengals [vnn] => bengals [v] => CIN [vs] => 0 [n] => CBS [rz] => 0 [ga] => [o] => 2 [gt] => WC ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011000 [gsis] => 0 [d] => Jan 10 [t] => 4:35 [q] => P [htn] => New England Patriots [hnn] => patriots [h] => NE [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => NBC [rz] => 0 [ga] => [o] => 3 [gt] => DIV ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011101 [gsis] => 0 [d] => Jan 11 [t] => 4:40 [q] => P [htn] => Denver Broncos [hnn] => broncos [h] => DEN [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => CBS [rz] => 0 [ga] => [o] => 4 [gt] => DIV ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011801 [gsis] => 0 [d] => Jan 18 [t] => 6:40 [q] => P [hnn] => [h] => TBD [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => CBS [rz] => 0 [ga] => [o] => 5 [gt] => CON ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011800 [gsis] => 0 [d] => Jan 18 [t] => 3:05 [q] => P [hnn] => [h] => TBD [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 6 [gt] => CON ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011100 [gsis] => 0 [d] => Jan 11 [t] => 1:05 [q] => P [htn] => Green Bay Packers [hnn] => packers [h] => GB [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 7 [gt] => DIV ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011001 [gsis] => 0 [d] => Jan 10 [t] => 8:15 [q] => P [htn] => Seattle Seahawks [hnn] => seahawks [h] => SEA [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 8 [gt] => DIV ) ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010401 [gsis] => 56494 [d] => Sun [t] => 4:40 [q] => P [htn] => Dallas Cowboys [hnn] => cowboys [h] => DAL [hs] => 0 [vtn] => Detroit Lions [vnn] => lions [v] => DET [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 9 [gt] => WC ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010300 [gsis] => 56491 [d] => Sat [t] => 4:35 [q] => P [htn] => Carolina Panthers [hnn] => panthers [h] => CAR [hs] => 0 [vtn] => Arizona Cardinals [vnn] => cardinals [v] => ARI [vs] => 0 [n] => ESPN [rz] => 0 [ga] => [o] => 10 [gt] => WC ) ) [10] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015012500 [gsis] => 0 [d] => Jan 25 [t] => 8:00 [q] => P [htn] => Team Cris Carter [hnn] => team carter [h] => CRT [hs] => 0 [vtn] => Team Michael Irvin [vnn] => team irvin [v] => IRV [vs] => 0 [n] => ESPN [rz] => 0 [ga] => [o] => 11 [gt] => PRO ) ) [11] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015020100 [gsis] => 0 [d] => Feb 1 [t] => 6:30 [q] => P [hnn] => [h] => TBD [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => NBC [rz] => 0 [ga] => [o] => 12 [gt] => SB ) ) ) ) [gds] => SimpleXMLElement Object ( ) )My object is returning this and that's great... but my foreach skills need a TON of work apparently... I think I've looked at it too much and too long... some suggestions would be VERY much appreciated... Probably a bit big of a project to try on my first real attempt but I just went through the foreach in my tutorial but it's just not working.... What I'm looking to do is output the d, t, htn, vtn, hs, vs... I was trying to just get it to show just one of those but no go... Thanks everyone!!
This script with minor changes came from a tutorial. I did a var dump and get a NULL result. Can anyone tell me why? <?php /** Get web page via HTTP GET using Libcurl. */ function getPageDetails($target, $referer) { $info = curl_init(); //settings curl_setopt($info, CURLOPT_HEADER, true); curl_setopt($info, CURLOPT_COOKIEJAR, "cookie_jar.txt"); curl_setopt($info, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($info, CURLOPT_USERAGENT, "imagimediabot2"); curl_setopt($info, CURLOPT_URL, $url); curl_setopt($info, CURLOPT_REFERER, $referer); curl_setopt($info, CURLOPT_FOLLOWLOCATION, true); curl_setopt($info, CURLOPT_MAXREDIRS, 4); curl_setopt($info, CURLOPT_RETURNTRANSFER, true); //request $output = curl_exec($info); curl_close ($info); //seperate head and body $separator = "\r\n\r\n"; $header = substr( $output, 0, strpos( $output, $separator ) ); $body_start = strlen( $header ) + strlen( $separator ); $body = substr($output, $body_start, strlen($output)-$body_start); // parse headers $header_array = Array(); foreach (explode ("\r\n", $header) as $i => $line) { if($i === 0) { $header_array['http_code'] = $line; $status_info = explode( " ", $line ); $header_array['status_info'] = $status_info; } else { list ( $key, $value ) = explode ( ': ', $line ); $header_array[$key] = $value; } } $ret = Array("headers"=>$header_array,"body"=>$body); return $ret; } $page = getPageDetails("https://imagimedia.co.za", ""); $headers = $page['headers']; $http_status_code = $headers['http_code']; $body = $page['body']; var_dump($header_array) ?>
Hello everyone - I have picked dup a book on php and SQL and have been quaking through it. I have come across a problem with a foreach statement that I can not resolve. Any help and advice is greatly appreciated!
<?php try { $pdo = new PDO('mysql:host=localhost;dbname=ijdb; charset=utf8', 'ijdbuser', 'mypassword'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'SELECT `joketext` FROM `joke`'; $result = $pdo->query($sql); while ($row = $result->fetch()) { $jokes[] = $row['joketext']; } } catch (PDOException $e) { $output = 'Unable to connect to the database server: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } include __DIR__ . '/../templates/jokes.html.php'; and the other file
<!doctype html> <html> <head> <meta charset="utf-8"> <title>List of jokes</title> </head> <body> <?php if (isset($error)): ?> <p> <?php echo $error; ?> </p> <?php else: ?> <?php foreach($jokes as $joke ): ?> <blockquote> <p> <?php echo htmlspecialchars($joke, ENT_QUOTES, 'UTF-8') ?> </p> </blockquote> <?php endforeach; ?> <?php endif; ?> </body> </html>
Hello, I'm a newbie and would like to learn PHP. I have some HTML and CSS skills, but would very much like to upgrade them to PHP. How can I do that? What materials do you suggest I read?... Thanks, I am trying to find a tutorial on how to perform a depth first search. I've seen pseudocodes and sources in other languages, but I just can't implement it in PHP no matter what I try. Can anyone show me how or where I can read up on it or how to do it? Hello everyone, my name is Joe. I have no clue how to code in PHP. But have some decent knowdlege when it comes to HTML and CSS. But there are some PHP scripts i would like to build and i am very hopefull with the help of the community i will be able to learn PHP and get help with my long over due PHP projects.
Thank you for reading!
So I am fairly new to PHP. I have dabbling experience in a slew of languages, C++, Python, Java, Perl, Javascript, Haskell and I am fluent in HTML but not so great with CSS. I am currently working on developing a browser game using PHP and am going to be asking for help making it work. When I ask stupid questions, as I am sure I will, I hope people will help me learn to ask better ones.
Hi all, I am an intermediate PHP Programmer, but I'm now stuck with getting any further. I am currently developing a CMS with a few people. However, I wish to put that aside for a month or so and learn PHP a bit better. Can anyone suggest a fairly "easy" project for me to do to learn a bit more about PHP? Best Regards, DM Hello Guys... I'm new to php & mySQL... I need help... Need something to know... please help me... I'm using ubuntu 11.10, Aptana Studio 3, xampp 1.7.7. Also i'm using windows 7, notepad++ & wamp. When I visit "localhost" on my firefox. I saw a xampp or wamp welcome page. The name of the file is "index.php". 1. I need to know can I delete this file ? Bcoz i'm working on another file but it's the same file name. 2. When I upload my site on host like hostgator. How do i edit my live site? And preview it. 3. How do i store my post on database ? Like fb status update, blogger post or forum post I wanna write a site that i can post something without using html <p></p>. The main problem when i need to post something then everytime I need to edit the source code. Example:<p>some text here</p>. I don't wanna edit source everytime. Another Ques: Is Aptana Studio and notepad++ enough to write a site or I need another tool ? Any book suggestion ? please guys help me i'm new to php & mySQL.. Is there any reason why I would want to use this... Code: [Select] $_SESSION['loggedIn'] = TRUE; versus this... Code: [Select] $_SESSION['loggedIn'] = 1; (The first one is easier to read...) Debbie |