-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
I'm not sure what you mean by this. If you mean they should show that generic example along with the specific details on every reference page, then that's a terrible idea as that would create a bunch of unnecessary clutter. Once you know how to read a prototype, you don't need that generic reference explaining the prototype everywhere. If you don't know how the read the prototype, then you find that page of the manual which tells you and read it first. It does mean variable, essentially. It's stylized with the $ because that's how things work in PHP when you write your own functions. If you wanted to write your own in_array function for example, you'd declare it like so: function my_in_array(mixed $valueToFind, array $arrayToSearch, bool $strictSearch = false) : bool { //TODO: implement me } See how the code you'd write pretty much matches exactly the prototype in the manual? That's why the manual documents the signatures the way it does. Your suggested "improvements" are not improvements at all. Making the name upper-case doesn't improve things. Neither does adding underlines or italics. The names themselves are mostly just informational, they don't mean you have to pass a variable with that exact name. You can pass whatever variable (or constant) value you want. The names only become somewhat relevant with the introduction of Named Arguments in PHP 8.0. Most functions don't benefit from the named arguments feature, so using it is unnecessary.
-
Then perhaps you should read the manual section entitled How to read a function definition (prototype). And the section entitled Callbacks / Callables. When you're new to something, you need to spend time on reading about the fundamentals. That way when you look at the detailed references you understand them. There's a lot to the PHP manual besides the function references for you to read and learn from.
-
That seems to me like maybe a misunderstanding of what is happening. You're not outputting a group of images in each LI element that get cycled through, you're just generating 9 LI elements with one image each. The code to do that can be much simpler than what you have. Randomize your array with shuffle, then dump out the first 9 elements. <?php $clients = array_filter($clients); //Remove empty elements shuffle($clients); //Randomize the array. ?> <ul class="object image-grid gallery"> <?php foreach (array_slice($clients, 0, 9) as $c): ?> <li> <a <?= ($c->link ? 'href="'.$c->link.'"' : '' ); ?>> <img class="img-fluid" src="<?= $c->image->url; ?>" /> <img style="display:none;" class="img-fluid" src="" /> </a> </li> <?php endforeach; ?> </ul> Your code to output the JSON structure of all your clients could also be improved. You should be using json_encode rather than trying to build the json manually. This way, the json data will be properly encoded and escaped if necessary. <script id="hd_client_gallery" type="text/json"> <?php echo json_encode(array_map(function($c){ return [ 'url' => $c->image->url, 'href' => $c->link ]; }, $clients)); ?> </script> array_map takes in an array and for every element in that array calls a function. The return value of that function is then put into a new array. So the above maps whatever your client objects are into a simple array with just url and href elements. That simple array then gets transformed into json and output. From the video, it seems like your duplication problem is a result of your JavaScript code that does the fade effect. When it choose a new image to fade in, it does so without regard to which images are already displayed. If you want to fix this, you'll have to do so by fixing the JavaScript code, there's nothing to do about that from within your PHP code.
-
Why My Php Does Not Extract Link Path Extensions ?
kicken replied to TheStudent2023's topic in PHP Coding Help
If this in reference to the ChatGPT link and not wanting to use it, it's not "copycatting" to look at examples to try and understand how something works, whether that example is from someone here, code on github, generated by AI, etc. There's nothing wrong with asking it for an example of how to do something and learning from that. I would advise against just taking code from ChatGPT or other and using it directly. While the AI's are pretty good, they are not perfect and their code isn't always the best quality but it's fine for an example to study. Just that the document is something other than a site map file. There are lots of different XML documents on the web, not just site map files. You need to decide what you want to do if you find a non-site-map xml file and put that in the else branch. -
Why My Php Does Not Extract Link Path Extensions ?
kicken replied to TheStudent2023's topic in PHP Coding Help
There isn't a list of values for nodeName because the list would be infinitely long. The nodeName is the tag name in the source code. Since the code is interested in Sitemap files, and the root element of those files is either <sitemapindex> or <urlset> then you'll be looking for a nodeName of 'sitemapindex' or 'urlset'. -
Why My Php Does Not Extract Link Path Extensions ?
kicken replied to TheStudent2023's topic in PHP Coding Help
Something like this: $xml = file_get_contents($sitemapUrl); $dom = new DOMDocument(); $dom->loadXML($xml); if ($dom->nodeName === 'sitemapindex'){ //parse the index } else if ($dom->nodeName === 'urlset'){ //parse url set } else { //some other xml file } But ChatGPT is, apparently. -
Why My Php Does Not Extract Link Path Extensions ?
kicken replied to TheStudent2023's topic in PHP Coding Help
Checking the extension is pointless. Extensions don't necessarily mean anything, and many URLs these days do not even have extensions to check. Trying to check the extension of a URL to determine if it's an XML file and then treat it as a site map is the entirely wrong approach here. Just because a URL ends in .xml doesn't make it a sitemap file, it could be any sort of XML file. What determines if something is a sitemap file is that the URL is part of a <sitemap> element, so that's what you need to check. If you look at the protocol page, you'll see there are essentially two types of sitemap files. A urlset listing all the URLs of the site, or a sitemapindex listing other site maps. So when you download an XML file, you should be checking whether the file is one of those two types and parse them accordingly. I'm not familiar enough with simplexml to know the code for that, but with DOMDocument you'd load the XML then check the nodeName to determine if it's a urlset or a sitemapindex. -
Suggest Me Top Artificial Intelligents Like ChatGpt
kicken replied to TheStudent2023's topic in Miscellaneous
Because it's not really necessary. The small code snippet it provided is enough to show the mistake and the solution. You can certainly ask it to re-write the code with the fix applied and it will. It will explain the fix in text, but I don't think it can highlight things other than just by using code blocks. You can get it to improve the code in other ways as well if you ask. -
Suggest Me Top Artificial Intelligents Like ChatGpt
kicken replied to TheStudent2023's topic in Miscellaneous
None. I played around with ChatGPT a bit when it first came out, to see what it was capable of and just have some fun. I was impressed by it's ability to understand things. I fed it a few functions I've written and asked it to explain what the functions did and write sample code using the functions and it was surprisingly accurate. I don't really see much use for it day-to-day though, so I haven't really used it in quite a while. It does get a lot closer to the "Ask a question, get an answer" goal of search engines, which is why I immediately knew people would be working on that and am not at all surprised to see it happening. Eventually as the models get better and more integrated into search, you'll be able to just type a plain-English (or whatever language) question into google and get an actually answer back instead of having to wade through a list of result pages. From the code side of things, the AI is good enough right now to answer simple syntax / logic errors. Take one of the questions posted here as an example. I told ChatGPT what the error was, what the code was, and to tell me why. It responded: I imagine eventually such a tool will be used to help teach new programmers by either providing better error detection in IDE's or having an virtual mentor they can ask questions and get immediate answers rather than having to either search the web or post on a forum and wait for a response. There are already AI coding assistants that might fulfill this task, I haven't tried any of them personally to know how useful they are. -
Notice: Only variables should be passed by reference
kicken replied to XCalibre3's topic in PHP Coding Help
INSERT queries do not have a result set. As such, mysqli_stmt_get_result returns false, as documented. To check if a row was inserted, use mysqli_stmt_affected_rows. -
Notice: Only variables should be passed by reference
kicken replied to XCalibre3's topic in PHP Coding Help
MD5 is not proper password hashing. PHP has a function for hashing passwords, as demonstrated in the linked stack overflow answer. Use it. Like in your original post, you're passing a value that is not a variable. In the original post it was a string constant. Now it's the result of a function call. You need to pass variables to bind_param, not constants or expressions. So hash your password before the call the bind_param and save the hashed password back into the variable (or a new variable). $password = password_hash($password, PASSWORD_DEFAULT); -
You need to use the same type of trick as with the questions. Note the CSS for those: .question { display: none; text-align: center; } .question.active { display: block; } Elements with .question are hidden by default (display: none) then shown when given the active class (.question.active selector). So you create your finished screen and make it hidden by default, then add CSS that will show it when you've added the finished class to your quiz element (.quiz.finished). It'd probably be best to not use the same class name for both your finish screen and your finished marker on the quiz, which is what you are doing currently.
-
If you're getting duplicates with that code, it sounds to me like your $client_images array simply contains duplicates, not that you're selecting the same image twice somehow. If that's the case, filter out those duplicates before you take your random selection. Your code is a little overly complicated for the task. Your original code had the components of a right solution, just too much extra junk along with it. To get X unique random elements from an array (assuming the array itself is unique) then all you need to do is shuffle the array to randomize the order slice off the first X elements. Side question, why do you have two images takes, with one of them being display none and without a src?
-
Please do not post screen shots of your code. Copy and paste the relevant parts of your code into your post using a code block (the <> button). That picture is barely readable. As for your issue, you are missing the semi-colon on the line above.
-
Other than the score update being delayed, it seems to work just fine. The update delay is because you're doing the display update before you update the totals.
-
Yes. Both. Essentially you want your click handler to do nothing if the question is already answered. That's what that if condition does, makes the function return (stop) if you click a non-li element or the quiz is answered.
-
This condition already exists in the code. Notice that once you have selected an answer, you cannot change it. All you need to do is re-arrange your code so that you increment your totals after this condition has been checked.
-
You have not defined $id anywhere, so your query will be WHERE id=NULL which is always false thus you get no results.
-
This is setting your list variable to whatever the first <li> element is in the document. That would be the first choice of the first question, which you happen to have marked as correct. There's no need for this variable, so remove it. What you need to be doing instead is check if the element that was clicked has the data-correct attribute. You already have code that applies the "selected" class to the element that was clicked so expand on that.
-
Possible To Auto Generate Prepared Statements ?
kicken replied to TheStudent2023's topic in PHP Coding Help
Because you didn't specify a column to order by. The syntax is ORDER BY someColumnName DESC -
What Would You Like To See In Tomorrow's 2023 SearchEngine ?
kicken replied to TheStudent2023's topic in Miscellaneous
Search engines have changed a lot since 1998. They are about the change a lot again thanks to things like ChatGPT I suspect. -
*-of-type only consider the tag name as the type, not any classes or id's applied to an element. The selector would be more accurately read as *:first-of-type.update_card {}. So, using that you could have other elements in your container, so long as they used different tag names. It's easier to just have a dedicated element and use :first-child / :last-child imo though. You'll have to determine the source of them. Browser's developer tools should help with that. My guess would be some sort of margin. Such gaps don't appear when using the example code from above. If you can't find the issue, you'll need to provide updated HTML and CSS code, or a fiddle link, that re-creates the issue.
-
The container needs to contain only your .update_card elements, and those elements must be direct children of the container. Your original HTML doesn't meet those requirements. The .blw element also contains your .update_grade element (which is the :first-child). Your screenshot suggests every .update-card is wrapped in some other parent element (hence, they all are :last-child of that container).
-
If you wrap all your update card elements in a container, and have them all be siblings, then you can get the effect you want using :first-child and :last-child <div class="blw"> <div class="update_grade">Class of 2023</div> <div class="update-list"> <div class="update_card"> ... Jalen Hooks ... </div> <div class="update_card"> ... Logan Imes ... </div> <div class="update_card"> ... Spencer White ... </div> </div> </div> .update_card:first-child { border-radius: 10px 10px 0px 0px; } .update_card:last-child { border-radius: 0px 0px 10px 10px; }