PHP - Moved: Explain This Code...
This topic has been moved to Third Party PHP Scripts.
http://www.phpfreaks.com/forums/index.php?topic=330152.0 Similar TutorialsThis topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=331697.0 I have some code that is supposed to get data from a site and then insert the gathered data into a database. The code does start adding data to database but it isn't adding data that it is getting from site that has starting data. What I mean is this. This code gets current player scores and such from gametracker and adds that to the database. then it will get player scores from my own tracker and add new scores to the ones that weere adde3d from game tracker. We did this so that our game servers continue tracking the scores for our new server trackers and not start out at zero initially. How ever when we run the code it says data was not written to database probably because server does not exists in database when in fact it really does. SO if someone could explain the code to me as to what it is doing then maybe I can figure out why it isn't working. Code: [Select] function InitializeServer( $sid, $ip, $name, &$totalplayers ) { !mysql_query( "DROP TABLE ".SERVER_TABLE_NAME.$sid.";" ); // we don't care if this fails if table didn't exist before if( !mysql_query( "CREATE TABLE ".SERVER_TABLE_NAME.$sid." (" ." `name` varchar(32), `score` int, `goal` int default 0, `leader` int default 0, `enemy` int default 0, `kia` int default 0, `roe` int default 0," ." PRIMARY KEY(`name`) );" ) ) { die( "Error creating table: ".mysql_error() ); } $id = 1; $page = 1; $done = FALSE; while( !$done ) { $data = http_request( "www.gametracker.com", "/server_info/".$ip."/top_players/?searchipp=50&searchpge=$page" ); $pos = 0; $out = ""; while( !$done ) { $num = GetStringInMiddle( $data, $pos, '<td class="c01">', '</td>' ); if( $num == NULL && $id > 1 ) break; if( $num != $id || $num == NULL ) { $done = TRUE; break; } $name = GetStringInMiddle( $data, $pos, '/">', '</a>' ); if( $name === NULL ) break; $score = GetStringInMiddle( $data, $pos, '<td class="c04">', '</td>' ); //$timePlayed = GetStringInMiddle( $data, $pos, '<td class="c05">', '</td>' ); //$scorePerMinute = GetStringInMiddle( $data, $pos, '<td class="c06">', '</td>' ); if( $out != "" ) $out .= ",\n"; $out .= "('$name', '$score')"; $id ++; $totalplayers ++; } // Write data to database, if any if( $out != "" ) { $cmd = "INSERT INTO ".SERVER_TABLE_NAME.$sid." (`name`, `score`) VALUES ".$out.";"; if( !mysql_query( $cmd ) ) { echo "Error with insert: ".mysql_error()."\n[$cmd]"; } } echo ($id-1)." "; flush(); ob_flush(); $page++; } if( $id > 1 ) echo "\nInitalized server #$sid: ".$ip." - ".$name." - ".($id-1)." players added<br />"; else echo "\nServer #$sid: ".$ip." - ".$name." - no players added (server probably not in database)<br />"; flush(); ob_flush(); } $sid, $ip and such are defined in other files that are included in the same file as this code is included in. Hi guys, for a long time now I have been using the same block of code to include my content pages into my layout, I understand what it does as a whole, but I have never understood what the individual parts do, could someone explain the main parts please. Thanks. here's the code: Code: [Select] <?php if (isset($_GET['page'])) { if (strpos($_GET['page'], "/")) { $direc = substr(str_replace('..', '', $_GET['page']), 0, strpos($_GET['page'], "/")) . "/"; $file = substr(strrchr($_GET['page'], "/"), 1); if (file_exists($direc.$file.".php")) { require($direc.$file.".php"); } else { require("error.php"); } } else { if (file_exists(basename($_GET['page']).".php")) { require(basename($_GET['page']).".php"); } else { require("error.php"); } } } else { require("default.php"); } ?> i found some code that is helping me extract a table. Currently it works and extracts every single table row however it duplicates some of the rows. I am new to XPATH and would appreciate if someone could comment the following code so that I can alter it to meet my needs. Thanks. $newDom->appendChild($newDom->importNode($item,true)); $xpath = new DOMXPath( $newDom ); foreach ($item->attributes as $attribute) { for ($node = $item->firstChild; $node !== NULL; $node = $node->nextSibling) { if (($attribute->nodeName =='valign') && ($attribute->nodeValue=='top')) { print($node->nodeValue); } else { print("<br>".$node->nodeValue); } } print("<br>"); Hi everyone! I'm making friends with DOM+PHP+XML. I found an example in w3school tutorial but there are some things I don't understand. Code: [Select] <?php $q=$_GET["q"]; $xmlDoc = new DOMDocument(); $xmlDoc->load("cd_catalog.xml"); $x=$xmlDoc->getElementsByTagName('ARTIST'); for ($i=0; $i<=$x->length-1; $i++) { //Process only element nodes if ($x->item($i)->nodeType==1) { if ($x->item($i)->childNodes->item(0)->nodeValue == $q) { $y=($x->item($i)->parentNode); } } } $cd=($y->childNodes); for ($i=0;$i<$cd->length;$i++) { //Process only element nodes if ($cd->item($i)->nodeType==1) { echo("<b>" . $cd->item($i)->nodeName . ":</b> "); echo($cd->item($i)->childNodes->item(0)->nodeValue); echo("<br />"); } } ?> This part I understand, it's a PHP method: Code: [Select] $xmlDoc = new DOMDocument(); $xmlDoc->load("cd_catalog.xml"); $x=$xmlDoc->getElementsByTagName('ARTIST'); but I don't get the rest , and what is this Code: [Select] $x->length-1 means? What does this mean? Code: [Select] nodeType==1 what do the numbers represent? Can anyone give me the URL of a good XML PHP tutorial? Thank you I looked up 'how to get all POST variables' and I ended up putting this bit of code together. Im not experienced at all with OOP programming, but I think that when '=>' is used its to do with OOP? Anyway. I dont get this code. I understand Foreach $_POST, as $someVar, (BTW im looking for checkboxes from a form), However, If I leave out the '=> $val' I simply get a lot of 'on' values, indicating the checkboxes I checked. However, WITH the '=> $val' I end up with the checkbox name. Now i've changed the name of '$val' so i know its not a keyword. But i dont get it. Is there a way to access the value of the checkbox? Can someone explain to me whats going on here? I know that I can get the value of the checkbox by $_POST['$checkRows'] But, I have a feeling It can be done in the foreach line. foreach($_POST as $checkRows => $hip) { echo "POSTED: $checkRows<br>\n"; } Please help! Code: [Select] if ($r['parent_id'] > 0) { $this->children[ $r['parent_id'] ][$r['id']] = $r; } else { $this->forums[ $r['id'] ] = $r; } what is this code doing? i don't get it how it uses the 2 variables in the " [ " " ] " 's ? weird? $r is a simple select * from a query.. i dont get the 2 variables with [] right next to each other? in the following code I am unable to understand the purpose of @ Code: [Select] function get_categories(){ //query database for a list of categories $conn = db_connect(); $query ="select catid, catname from categories"; $result = @$conn->query($query); if (!$result){ return false; } $num_cats = @$result->num_rows; if($num_cats==0) { return false; } $result = db_result_to_array($result); return false; } function db_result_to_array($result) { $res_array = array(); for ($count=0; $row = $result->fetch_assoc(); $count++){ $res_array[$count] = $row; } return $res_array; } If a user is using internet explorer, display error "You are not using a browser that is supported. Please reload in Google Chrome or Mozilla Firefox to access content", otherwise display page. Not sure if this is possible with an if else statement, or even php for that matter. Does anyone know what I'm talking about, and if so, any suggestions? the more source code i see this in, =. , the more intrigued i am by it, i cant find tuts on it anywhere it cant be searched. please explain what it is and how to use it please. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=352862.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=351710.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=334386.0 This topic has been moved to Beta Test Your Stuff!. http://www.phpfreaks.com/forums/index.php?topic=309601.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=349890.0 Can anyone explain to me why this isn't working , and explain how i would rectify the problem, Many Thanks. Code: [Select] <? $rawr = mysql_real_escape_string($_GET['type']); "SELECT COUNT(id) FROM items Where type = $rawr" ?> function quote_smart($value, $handle) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value, $handle) . "'"; } return $value; } how this script works and this script not linked to any variable or any other place so how this scripts works without linked or connected to anywhere (sorry if this ques is dumb but i m newbie in php I am working with wordpress. I am coding some custom meta boxes following some code someone else had written. My code is working but I am not sure if I need to do it the way I am doing it. The person who wrote the code added the option like so Code: [Select] $custom = get_post_meta($post->ID); $item_link = $custom["item_link"][0]; According to the wordpress codex, get_post_meta($post->ID) Returns a multidimensional array with all custom fields of a particular post or page. so when I added a second option, I followed with this Code: [Select] $item_text = $custom["item_text"][0]; I guess my question would be..Do i need to add the index 0 to every option or should I increase it by 1 for every new option I add? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=354376.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306039.0 |