• Web Development Questions That Don't Need Their Own Thread v2
    3,079 replies, posted
[QUOTE=Jelly;33991623]Don't do this. Instead [url=http://php.net/manual/en/function.file-get-contents.php]file_get_contents()[/url] and [url=http://php.net/manual/en/function.file-put-contents.php]file_put_contents()[/url]. [b]I hate it when people give complex ways to do easy shit to beginners.[/b][/QUOTE] How is that even complex? Of course the functions you suggested are easier, but I still wouldn't call kragmars' way complex, even for beginners.
[QUOTE=Skorpy;33993505]How is that even complex? Of course the functions you suggested are easier, but I still wouldn't call kragmars' way complex, even for beginners.[/QUOTE] Because it's unnecessary when you have easier and shorter methods. It's just like how people use [url=http://php.net/manual/en/function.opendir.php]opendir()[/url] and [url=http://php.net/manual/en/function.readdir.php]readdir()[/url] when you can just use [url=http://php.net/manual/en/function.scandir.php]scandir()[/url]. It's partially what gives PHP such a bad rep.
here, I know I probably screwed up something but this error is starting to really get annoying. Notice: Undefined index: gendera in /home/chattywaffle.com/scripts/registracija.php on line 25 Notice: Undefined index: capcho in /home/chattywaffle.com/scripts/capcher.php on line 18 Here is top of my index page: [code]<?php if(isset($_POST['loginButton'])){ include("scripts/loging.php"); } ?> <?php if(!(isset($_POST['registor']))){ include("scripts/capcher.php"); } ?> <?php if(isset($_POST['registor'])) { include("scripts/registracija.php"); } ?> [/code] And here are the error lines: $gender = $_POST['gendera']; and $capchoF = $_POST['capcho']; They are in 2 different files, I used include. I even tried setting if(!(isset($_POST['registor']))) { $day = 0; $month = 0; $year = 0; $gender = 0; $country = 0; $password = 0; $password2 = 0; } in top of file, that didn't work. Getting this problem second day already.
I have an annoying problem with jQuery and JSON here, can any one point out the error? I'm working on a small API for the game osu!, to retrieve user statistics. [B]index.html[/B] [HTML]<!DOCTYPE html> <html> <head> <style>img{ height: 100px; float: left; }</style> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <div id="content"> </div> <script> $(document).ready(function(){ var url="json.php"; $.getJSON("json.php", function(json) { alert("JSON Data: " + json.rows[1].name); }); }); </script> </body> </html>[/HTML] This index.html obtains the JSON feed and should alert the value "Hit Accuracy". [B]json.php (generator)[/B] [PHP]<?php error_reporting(0); if(isset($_GET['u'])) { $u = $_GET['u']; } else { $u = 701518; } include "simple_html_dom.php"; $html = file_get_html('http://osu.ppy.sh/pages/include/profile-general.php?u='. $u .'&m=0'); $result = $html->find('.profileStatLine'); echo '{ "rows":['. "\n"; $count = 1; foreach ($result as $result) { $res = preg_replace("/Ranks/", "", strip_tags($result->innertext)); list($nome, $ress) = preg_split("/([:]+)/", $res); $name = $nome //. ":" ; $coun = $count++; if ( $coun <= 7 ) { $couns = $coun . " wanted"; //echo $lol = "<span class=\"row". $couns ."\">$name</span>\n\t<span>$ress</span><br />\n"; echo $lol = "\t". '{ "name" : "'. $name .'", "stat" : "'. $ress .'"}, ' . "\n"; } } echo "]}"; ?>[/PHP] This makes the JSON feed. [B]json.php (result)[/B] [CODE]{ "rows":[ { "name" : "Ranked Score", "stat" : " 26,603,493 (#140409)"}, { "name" : "Hit Accuracy", "stat" : " 89.73%"}, { "name" : "Play Count", "stat" : " 612"}, { "name" : "Total Score", "stat" : " 134,593,542"}, { "name" : "Current Level", "stat" : " 27"}, { "name" : "Total Hits", "stat" : " 47,396"}, { "name" : "Maximum Combo", "stat" : " 582"}, ]}[/CODE] So why isn't this doing the alert?
[QUOTE=arleitiss;33994879]here, I know I probably screwed up something but this error is starting to really get annoying. Notice: Undefined index: gendera in /home/chattywaffle.com/scripts/registracija.php on line 25 Notice: Undefined index: capcho in /home/chattywaffle.com/scripts/capcher.php on line 18 Getting this problem second day already.[/QUOTE] If no POST data with the index "gendera" is sent, the index is undefined and results in an error. Are you still using $_POST['gendera'] even if $_POST['registor'] is not set (yes, you area putting e.g. $gender to 0, but are you still trying to get the value from $_POST['gendera'] later on?)? Try something like this: [php]$gender = (isset($_POST['gendera']) ? $_POST['gendera'] : 0);[/php] [editline]1st January 2012[/editline] [QUOTE=RusselG;33994927]I have an annoying problem with jQuery and JSON here, can any one point out the error? I'm working on a small API for the game osu!, to retrieve user statistics. So why isn't this doing the alert?[/QUOTE] You have an additional comma after the last array under "rows" (which JS interprets as a syntax error).
[QUOTE=Dragory;33994947]If no POST data with the index "gendera" is sent, the index is undefined and results in an error. Are you still using $_POST['gendera'] even if $_POST['registor'] is not set (yes, you area putting e.g. $gender to 0, but are you still trying to get the value from $_POST['gendera'] later on?)? Try something like this: [php]$gender = (isset($_POST['gendera']) ? $_POST['gendera'] : 0);[/php] [editline]1st January 2012[/editline] You have an additional comma after the last array under "rows" (which JS interprets as a syntax error).[/QUOTE] Yes indeed, I am trying to get values later on. by the way if that changes anything: it's 2 radio boxes, female and male choice, both named gendera.
[QUOTE=RusselG;33994927]I have an annoying problem with jQuery and JSON here, can any one point out the error? I'm working on a small API for the game osu!, to retrieve user statistics. [B]index.html[/B] [HTML]-snip-[/HTML] This index.html obtains the JSON feed and should alert the value "Hit Accuracy". [B]json.php (generator)[/B] [PHP]-snip-[/PHP] This makes the JSON feed. [B]json.php (result)[/B] [CODE]{ "rows":[ { "name" : "Ranked Score", "stat" : " 26,603,493 (#140409)"}, { "name" : "Hit Accuracy", "stat" : " 89.73%"}, { "name" : "Play Count", "stat" : " 612"}, { "name" : "Total Score", "stat" : " 134,593,542"}, { "name" : "Current Level", "stat" : " 27"}, { "name" : "Total Hits", "stat" : " 47,396"}, { "name" : "Maximum Combo", "stat" : " 582"}, ]}[/CODE] So why isn't this doing the alert?[/QUOTE] [url]http://jsonlint.com[/url] - JSON is a strict data format and jQuery will disregard any JSON that is not formatted correctly.
[QUOTE=jaybuz;33995479][url]http://jsonlint.com[/url] - JSON is a strict data format and jQuery will disregard any JSON that is not formatted correctly.[/QUOTE] So in this case it's the last comma in [I]rows[/I] [code] { "name" : "Maximum Combo", "stat" : " 582"}, [/code] Saying this just in case if the jsonlint's result is not clear enough. I've ran in this same problem in IE too. Just a normal JS array and if there's a comma after the last element, it just throws an error.
[QUOTE=arleitiss;33995062]Yes indeed, I am trying to get values later on. by the way if that changes anything: it's 2 radio boxes, female and male choice, both named gendera.[/QUOTE] Then don't try to get the values later on if there is no data to get it from. If you try to get data from $_POST['gendera'] and no POST data like that is sent, PHP will output an error. That's why you should check if the data is there (isset) and then only get it if it really is there.
[QUOTE=jaybuz;33995479][url]http://jsonlint.com[/url] - JSON is a strict data format and jQuery will disregard any JSON that is not formatted correctly.[/QUOTE] Thanks, nice tool. Can anyone tell me how to exclude the comma in the results if it is the last line (in the php generator)?
[QUOTE=RusselG;34004813]Thanks, nice tool. Can anyone tell me how to exclude the comma in the results if it is the last line (in the php generator)?[/QUOTE] [php] echo $lol = "\t". '{ "name" : "'. $name .'", "stat" : "'. $ress .'"}' . ($coun !== 7) ? ",\n" : '';[/php] That took me hours! [editline]2nd January 2012[/editline] You know instead of using echo, you could actually break out of php to make it more readable.
Instead of using echo, you could just use the proper JSON creation functions PHP provides. [url]http://php.net/manual/en/book.json.php[/url]
[QUOTE=TheDecryptor;34006697]Instead of using echo, you could just use the proper JSON creation functions PHP provides. [url]http://php.net/manual/en/book.json.php[/url][/QUOTE] Yeah, I knew about those functions, incorporating them now.
Does anyone have any suggestions for a free javascript static slideshow? I searched on the net but found nothing that would fit what I need. It would have it's own page and needs thumbnails.
End of December Thread (make a January thread)
Sorry, you need to Log In to post a reply to this thread.