Jump to content

deadliver

Members
  • Posts

    20
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

deadliver's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in on line 78 This is my first time using MYSQLI and i followed and example I found on procedural coding and it always returns this error. I looked on the php manual online and their examples seem to be coded like this as well. Does anyone know how I can correct this issue? I connect to the db successfully. $link = mysqli_connect(DB_HOST, DB_USER,DB_PASS,DB_NAME); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } Then I make the INSERT statement and run the query successfully $players_query = "INSERT INTO `players` (id_players,player_name,player_id,clan_id,created_at,clan_name,clan_role,clan_member_since,data_updated_at) VALUES ('','$player_name',$player_id,$clan_id,$created_at,'$clan_name','$clan_role',$clan_member_since,$updated_at) ON DUPLICATE KEY UPDATE clan_id =$clan_id ,clan_role = '$clan_role',data_updated_at =$updated_at"; $result = mysqli_query($link,$players_query); Then I verify the query ran and try to free results before the next query. if($result){ echo "Player Information Updated Successfully"; mysqli_free_result($result); }else{ printf("Errormessage: %s\n", mysqli_error($link)); die(); } Then I get this: Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in on line 78
  2. I know your frustrated by me and I am sorry. Yes, your solution works perfectly. Let me tell you what I think I know..and maybe that is better so you can see the faulty logic I am using. I understand each set of $vdata represents all the current element's information, both keys and values. so by using $results['vehicles']=>$vdata we are putting in the values for the the name,total,wins. That is how we can use $veh directly to because it is representing a value not a key. That is what I think is happening anyways as I try to grasp this. .
  3. php manual: and because of this we can use $veh to get the first element of the array each time?
  4. Thanks for the help. Can I ask for an edification. [color="#000000"]echo [/color][color="#008800"]"$veh : Wins: {$vdata['wins']} : Total : {$vdata['total']} <br>"[/color][color="#666600"];[/color] In my thoughts when you used $veh in the echo it would have had to start of with at least $vdata['vehicles'][????]
  5. $results['vehicles'][$veh]['total'] = str_replace(" ","",trim($match[1])); $results['vehicles'][$veh]['wins'] = str_replace(" ","",trim($match[2])); if my array is set up like this code..how would a foreach loop be coded to go through this data? I can do a normal foreach loop, but not one like this. I was thinking of doing it like this , but if I do I dont know how to code it correctly. foreach ($tankData as $row) { echo $row['vehicles'][<whatgoeshere>]; echo $row['vehicles'][<whatgoeshere?>]['wins'] ; echo $row['vehicles'][<whatgoeshere?>]['total']; }
  6. Just though you might like to know: Array ( [battles Participated] => 10 443 [Victories] => 5 020 (48%) [Defeats] => 5 214 (50%) [battles Survived] => 2 351 (23%) [Hit Ratio] => 61% [Destroyed] => 7 110 [Detected] => 13 091 [Damage] => 8 519 566 [Capture Points] => 13 842 [Defense Points] => 5 614 [Targets Destroyed] => 7 110 [Targets Detected] => 13 091 [vehicles] => Array ( [A-20] => Array ( [total] => 6 [wins] => 4 ) [AMX 105AM] => Array ( [total] => 18 [wins] => 9 ) [AMX 12t] => Array ( [total] => 69 [wins] => 32 ) [AMX 13 75] => Array ( [total] => 39 [wins] => 24 ) [AMX 13 90] => Array ( [total] => 83 [wins] => 53 ) [AMX 13 F3 AM] => Array ( [total] => 212 [wins] => 108 ) [AMX 38] => Array ( [total] => 15 [wins] => 7 ) [AMX 40] => Array ( [total] => 18 [wins] => 11 ) [AMX AC Mle. 1946] => Array ( [total] => 45 [wins] => 24 ) [AT-1] => Array ( [total] => 17 [wins] => 8 ) [b1] => Array ( [total] => 5 [wins] => 2 ) [bat Chatillon 25 t] => Array ( [total] => 145 [wins] => 88 ) [bDR G1B] => Array ( [total] => 5 [wins] => 4 ) [bT-2] => Array ( [total] => 74 [wins] => 31 ) [bT-7] => Array ( [total] => 12 [wins] => 5 ) [Churchill] => Array ( [total] => 5 [wins] => 1 ) [D2] => Array ( [total] => 3 [wins] => 2 ) [Hetzer] => Array ( [total] => 66 [wins] => 30 ) [Hotchkiss H35] => Array ( [total] => 11 [wins] => 2 ) [iS] => Array ( [total] => 346 [wins] => 153 ) [iS-3] => Array ( [total] => 588 [wins] => 252 ) [iS-4] => Array ( [total] => 125 [wins] => 70 ) [iS-7] => Array ( [total] => 381 [wins] => 179 ) [iS-8] => Array ( [total] => 563 [wins] => 257 ) [Jagdpanther] => Array ( [total] => 36 [wins] => 19 ) [JagdPz IV] => Array ( [total] => 50 [wins] => 26 ) [KV-1] => Array ( [total] => 289 [wins] => 130 ) [KV-1S] => Array ( [total] => 32 [wins] => 13 ) [KV-2] => Array ( [total] => 5 [wins] => 1 ) [KV-3] => Array ( [total] => 7 [wins] => 1 ) [Leichttraktor] => Array ( [total] => 10 [wins] => 6 ) [Lorraine 40 t] => Array ( [total] => 306 [wins] => 163 ) [Lorraine155 50] => Array ( [total] => 149 [wins] => 77 ) [Lorraine155 51] => Array ( [total] => 13 [wins] => 8 ) [Lorraine39 L AM] => Array ( [total] => 19 [wins] => 10 ) [M18 Hellcat] => Array ( [total] => 116 [wins] => 57 ) [M2 Light Tank] => Array ( [total] => 17 [wins] => 7 ) [M26 Pershing] => Array ( [total] => 155 [wins] => 77 ) [M3 Lee] => Array ( [total] => 11 [wins] => 7 ) [M3 Stuart] => Array ( [total] => 16 [wins] => 8 ) [M46 Patton] => Array ( [total] => 86 [wins] => 44 ) [M4A3E8 Sherman] => Array ( [total] => 126 [wins] => 61 ) [M5 Stuart] => Array ( [total] => 57 [wins] => 23 ) [M6] => Array ( [total] => 19 [wins] => 7 ) [M7] => Array ( [total] => 80 [wins] => 43 ) [M8A1] => Array ( [total] => 11 [wins] => 6 ) [Marder II] => Array ( [total] => 24 [wins] => 6 ) [MS-1] => Array ( [total] => 51 [wins] => 34 ) [Object 212] => Array ( [total] => 324 [wins] => 173 ) [Object 261] => Array ( [total] => 76 [wins] => 26 ) [Panzerjäger I] => Array ( [total] => 1 [wins] => 1 ) [PzKpfw 38 nA] => Array ( [total] => 41 [wins] => 25 ) [PzKpfw III] => Array ( [total] => 6 [wins] => 4 ) [PzKpfw IV] => Array ( [total] => 95 [wins] => 47 ) [PzKpfw VI Tiger] => Array ( [total] => 31 [wins] => 17 ) [RenaultBS] => Array ( [total] => 1 [wins] => 1 ) [RenaultFT AC] => Array ( [total] => 1 [wins] => 0 ) [RenaultFT] => Array ( [total] => 2 [wins] => 1 ) [s-35 CA] => Array ( [total] => 49 [wins] => 24 ) [stuG III] => Array ( [total] => 71 [wins] => 33 ) [sU-14] => Array ( [total] => 177 [wins] => 92 ) [sU-18] => Array ( [total] => 37 [wins] => 12 ) [sU-26] => Array ( [total] => 48 [wins] => 21 ) [sU-5] => Array ( [total] => 147 [wins] => 68 ) [sU-8] => Array ( [total] => 206 [wins] => 101 ) [sU-85] => Array ( [total] => 12 [wins] => 9 ) [sU-85B] => Array ( [total] => 5 [wins] => 4 ) [T-15] => Array ( [total] => 42 [wins] => 22 ) [T-150] => Array ( [total] => 353 [wins] => 140 ) [T-25] => Array ( [total] => 73 [wins] => 32 ) [T-26] => Array ( [total] => 15 [wins] => 10 ) [T-34] => Array ( [total] => 20 [wins] => 9 ) [T-34-85] => Array ( [total] => 11 [wins] => 4 ) [T-43] => Array ( [total] => 82 [wins] => 44 ) [T-46] => Array ( [total] => 51 [wins] => 23 ) [T-50] => Array ( [total] => 75 [wins] => 36 ) [T-50-2] => Array ( [total] => 179 [wins] => 94 ) [T1 Cunningham] => Array ( [total] => 20 [wins] => 11 ) [T1 Heavy] => Array ( [total] => 6 [wins] => 4 ) [T110E4] => Array ( [total] => 120 [wins] => 62 ) [T14] => Array ( [total] => 87 [wins] => 41 ) [T18] => Array ( [total] => 6 [wins] => 2 ) [T2 Medium Tank] => Array ( [total] => 64 [wins] => 30 ) [T20] => Array ( [total] => 113 [wins] => 46 ) [T25/2] => Array ( [total] => 187 [wins] => 91 ) [T28 Prototype] => Array ( [total] => 271 [wins] => 132 ) [T28] => Array ( [total] => 216 [wins] => 94 ) [T29] => Array ( [total] => 129 [wins] => 59 ) [T30] => Array ( [total] => 187 [wins] => 89 ) [T32] => Array ( [total] => 93 [wins] => 44 ) [T49] => Array ( [total] => 69 [wins] => 27 ) [T82] => Array ( [total] => 7 [wins] => 2 ) [T95] => Array ( [total] => 267 [wins] => 124 ) [Type 59] => Array ( [total] => 1 115 [wins] => 558 ) ) )
  7. omg. you are sickenly talented. I was just getting ready to post that I bit off more than I can chew trying to use DOM. I will try it of course I'm sure it works..when my domain gets fixed I guess my host is having DNS issues. Thanks for the help on this. I should just quit because well.look at your code and then look at my babble.
  8. This is the knowledge I am starting with as far as the patterns of the HTML code curl returns from the website. Here are the formats: <h1>usernamer</h1> If the user is in a clan it will have a link <a class="b-link-clan" href="/community/clans/1000005799-B-O-W/"> <span class="tag">[b-O-W]</span> Based on that this information I wrote one function function get_login($curlstr){ $login = get_part($curlstr,'<h1>','</h1>'); /** WAS PROFIE FOUND? **/ if ($curlstr == "" || $login == "" || $login == ' PAGE NOT FOUND ') { die("User Not Found"); } //IF USER HAS CLAN $s = '<a class="b-link-clan"'; if (strpos($curlstr,$s)!=0) { $clan = substr($curlstr,strpos($curlstr,$s)+strlen($s),300); $clan = substr($clan,strpos($clan,'[')+1,strpos($clan,']')-strpos($clan,'[')-1); $login = "[$clan] $login"; }else{ $login = $login; } return $login; } Now the values in $CategoriesMajor will follow this HTML format: <tr><td class=""> Battles Participated: </td> < td class="td-number-nowidth"> 10 338 </td> </tr> And of course I was using the infamous function you have been helping me with for this. I have another array $CategoriesMinor = array('Targets Destroyed','Targets Detected','Hit Ratio'); the HTML follows the same format as for $CategoriesMajor but doesnt have the colon at the end and has a second value to grab < td><span>Targets Destroyed</span></td> < td class="right value">7 042</td> < td class="right value">17 556</td> What you have not seen yet is a hole other format almost identical for a lot more information <td class="value"> <a class="b-gray-link" href="/encyclopedia/vehicles/china/ch01_type59/">Type 59</a> </td> <td class="right value">1 083</td> <td class="right value">539</td> the link shows a vehicle name and the following <td></td> shows total battles in that vehicle and the next set shows total wins I have simply been using substrings to gather information via this function, rather than DOM function get_part($str,$from,$to) { $value = substr($str,strpos($str,$from)+strlen($from),300); $value = substr($value,0,strpos($value,$to)); return $value; } The CURL is like this /** LOAD SETTINGS **/ $id = "1002011274"; $server = "com"; $flag = us; $languages = 1; $url="[url="http://worldoftanks.$server/community/accounts/$id/"]http://worldoftanks.$server/community/accounts/$id/[/url]"; // break; /** DOWNLOAD DATA **/ $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $string = curl_exec($ch); curl_close($ch); //dont start unless we get the webpage if(!isset($string)){ echo "no return"; } I attached the file the curl_exec returns. This is really all I have so far except scribble at the end where I am testing values I get returned etc. I think I need to step back and start over with a better plan of attack, first starting with using DOM wotsource.txt I am going to rethink , rewrite, and respond to this thread. In the mean time if you have any additional advice that will help me with my strategy to attack this..please post your thoughts. Sorry again for the misunderstanding Psycho.
  9. Psycho, my apologies if I misread your intent. What I am doing is just getting the all the data I need into arrays then I will be putting them into a database for later use. I just thought if I use an associative array ($Stats) that it would be easier when it comes time to write the code to dump the information into the db. And of course I do appreciate you finding the error as well. Oh..you are right $value is kind of the html code. Really its the text I know is inside the code of the html table, but then once I find that text I know where to get the numerical value based on positioning. When I get a chance I will switch that all to DOM. Would something like this work better? or you know put me on the path to being better. $CategoriesMajor = array( array("Battles Participated","Victories","Defeats","Battles Survived","Destroyed","Detected","Hit Ratio","Damage","Capture Points","Defense Points") array("0","0","0","0","0","0","0","0","0","0") ); function GetStats($curlstr,$array){ for ($i=0; $i < 11; $i++) { $str = '<td class=""> '.$CategoriesMajor[0][$i].': </td>'; $str = get_part($curlstr,$str,'</tr>'); $str = get_part($str,'<td class="td-number-nowidth">','</td>'); $str = str_replace(' ',' ',$str); if (strpos($str,'(')) { $str = get_part($str,'(',')'); } $CategoriesMajor[0][$i]$i] = $str; } }
  10. My apologies for being a novice, perhaps this is too advanced of a forum for me to be asking questions. Pyscho, I am not sure what you mean when you say unprocessed $value. I come here in all sincerity and respectfully sincerely looking for guidance not ridicule. If I had a clear understanding of what I was doing I would not be seeking assistance and I would also be a php guru like yourself. Barand..thank you for your information. I will try your recommendation.
  11. Christian I understand what you said about the index and it is 0, but with an associative array I do not think i understand the concept of how to put it in a different index. I assumed the way this code would work is that each time I called [color="#000000"]$Stat[/color][color="#666600"][[/color][color="#000000"]$value[/color][color="#666600"]][/color] [color="#666600"]=[/color][color="#000000"] $str[/color][color="#666600"];[/color] that the $value would become the index and the next $value in the loop would add to the array and be the next index ? If that is not the case. I am not sure how to proceed. If you could advise me on some reading etc. I have taken a look at a few reference books, but am still at a loss. Thank You.
  12. I am doing some web scraping. I start with an array: $CategoriesMajor = array("Battles Participated","Victories","Defeats","Battles Survived","Destroyed","Detected","Hit Ratio","Damage","Capture Points","Defense Points"); I am getting the html using curl. and get substrings based on my categories from my array. Up to this point its all good. My Get_Stats() is not returning anything in the array. I know the $str is getting a value as it loops. I assume I am having an issue adding it into the array properly or returning it from the function properly. //this function is fine just included in post for reference function get_part($str,$from,$to) { $value = substr($str,strpos($str,$from)+strlen($from),300); $value = substr($value,0,strpos($value,$to)); return $value; } function GetStats($curlstr,$array){ //array is $Categories Major foreach($array as $key =>$value) { $str = '<td class=""> '.$value.': </td>'; $str = get_part($curlstr,$str,'</tr>'); $str = get_part($str,'<td class="td-number-nowidth">','</td>'); //grab the part of string with the numerical value //Replace spaces $str = str_replace(' ',' ',$str); //It has %, replace the original value with % if (strpos($str,'(')) { $str = get_part($str,'(',')'); } $str = strip_tags($str); $Stat[$value] = $str; } return $Stats; } I am trying to get the information returned using this code, but nohing is loaded into the array $Stats[] = GetStats($string,$CategoriesMajor); foreach($Stats as $key=>$value){ echo $key." ".$value; }
  13. Brilliant. I feel so stupid posting but I have been staring at it for 3 days. Thanks so much for the help again.
  14. $Stats_Cats = array("Battles","Victories","Defeats"); $Stats = array(); function GetStats($curlstr){ foreach($CategoriesMajor as $key =>$value) { [s] $str = '<td class=""> '.$value.': </td>'; $str = get_part($curlstr,$str,'</tr>'); $str = get_part($str,'<td class="td-number-nowidth">','</td>'); $str = preg_replace ( "'<[^>]+>'U", "", $str); $str = strip_tags($str);[/s] //add value to the item in the array $Stats[$value]=$str; } return $Stats; } //$string is my return from a web scrape using curl library GetStats($string); When I test this foreach loop outside of this function it works fine. When I embed it into the function and call it, it does not begin the loop. I am not concerned about the code inside the foreach statement since it has yet to even try to loop.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.