Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. What exactly is contained in your set() and reset() functions? I'm not entirely sure why capturing is important here. It's always better to not embed Javascript directly in the HTML. Using addEventListener() is better than using event attributes.
  2. You probably need to have declared the variables beforehand. $item = null; $sid = null; $catid = null; $oqty = null; $unitid = null; $sprice = null $pprice = null; $description = null; $stmt->bind_result($item,$sid,$catid,$oqty,$unitid,$sprice,$pprice,$description);
  3. It's time to do some more serious debugging. Check to see how many numbers it prints before it stops. I've also reordered some of your instructions so that they make more sense. $stmt = $mysqli->prepare("SELECT item,sid,catid,oqty,unitid,sprice,pprice,description FROM stock WHERE (icode=? or bcode=?) AND cid=?"); if($stmt) { echo 1; $stmt->bind_param('ssi', $icode, $icode, $cid); echo 2; $stmt->bind_result($item,$sid,$catid,$oqty,$unitid,$sprice,$pprice,$description); echo 3; $success = $stmt->execute(); echo 4; if(!$success) { echo $stmt->error; } echo 5; $stmt->fetch(); echo 6; $stmt->free_result(); echo 7; $stmt->close(); echo 8; } else { echo 'Error: '.$mysqli->error; }
  4. It should show an error if you used a reserved word. But just to be sure, you can surround it in backticks `description`. If it's still not working after that then a reserved word is not the problem.
  5. W3Schools doesn't have a tutorial for it. You can find information about it on the Mozilla Developer Network: https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame The difference between requestAnimationFrame() and setInterval/setTimeout is that requestAnimationFrame() has a variable interval, so you need to use the timestamp provided in the function to calculate values.
  6. The forum software updated and caused everything to break in older posts.
  7. Have you checked to see what value $datas->items actually has. Find out using var_dump($datas->items). It's clearly not an array.
  8. The session has nothing to do with whatever other issues you're encountering. If you're going to delete the session data every time then you're not any better off than having no session at all.
  9. Don't call session_unset() or session_destroy() on any page or all your data will be lost. session_write_close() is only needed if you're using PHP's header() function for redirecting. If it's Javascript doing the redirect then there's no need for it.
  10. The socket timeout isn't the problem, it's PHP's execution time that's the problem. You can increase the amount of time PHP is allowed to execute using set_time_limit().
  11. A combination of background-size and background-position may allow you to clip the image using the div. You can use media queries to change the values based on screen size. Set negative background position values to offset the image to the left and up. Set the background size in absolute units, such as pixels, to have the most precise control over its size and position. For that to work it has to be a background image, though. An image element can't be altered in the same way with CSS.
  12. $sql = "SELECT id FROM users WHERE id = (SELECT MAX(id)FROM users)"; $result = $conn->query($sql); if(!$result) { // SOMETHING WENT HORRIBLY WRONG. // FIND OUT WHY echo $conn->error; exit; } else { foreach ( $result as $row ) { $id = $row['id'];
  13. This looks like an answer that will work: http://stackoverflow.com/questions/10236166/does-file-get-contents-have-a-timeout-setting But you could use PHP's cURL library instead of file_get_contents(). cURL is better suited for accessing files from remote servers.
  14. You can transfer values across pages using the session: http://www.w3schools.com/php/php_sessions.asp One thing they didn't mention in the tutorial is that you should call session_write_close() before redirecting to store the session values.
  15. Ingolme

    center navigation

    It's probably because the elements inside are floated to the left. If you remove the float rule from the menu items, set their display to inline-block and at the text-align property of the parent to "center" it probably will work.
  16. That means that the query failed. You should have $result in the foreach() loop, not $conn->query(). Because you're executing the query twice. if $result is false then check $conn->error if you're using MySQLi, use $con->errorInfo() if you're using PDO.
  17. Show us your code. Something in your code is taking far too long to run, it could be an infinite loop or a slow MySQL query.
  18. You cannot have an image as large as 3000x2000 on your page. The users would have to wait between 10 and 20 seconds for your page to load. The average amount of time a user will wait for a page to load before giving up and leaving is 7 seconds. There is no way around it, you have to make smaller versions of the image.
  19. HTML 5 introduces many semantic elements such as <main>, <section>, <aside>, <header>, <footer> and others. It adds new form inputs, such as email, date, number and range It allows embedding of audio and video natively supported by the browser as opposed to using plug-ins. The new <canvas> element gives Javascript unprecedented power, Javascript can now be used to make videogames, video players, 3D model rendering and more. Alongside HTML 5 is CSS 3 which is much more powerful for laying out and styling pages than CSS 2.1.
  20. There's a lot that needs to be improved in your code, starting with indentation and proper commenting so that your code is easy to read. I notice a large amount of your variables are not declared using var. This means they're in the global scope. It is inefficient and also leaves the risk of its value being overwritten. Your intervals are too short: interval = setInterval(updateGameArea, 5); This is expecting the browser to run the operation 200 times per second. Most mobile devices cap the browser at 60 redraws per second. The time intervals should be no less than 17 milliseconds. If you want precision timing, look into requestAnimationFrame() it's faster and more efficient than setInterval(). This is probably one of the biggest factors in your program being slow on mobile devices. You have quite a lot of messy code. Just replace this: var TargetImages = (function () { function TargetImages() { // Big block of code } // endof function TargetImages() return TargetImages; })(); // endof var TargetImages = (function () With this: function TargetImages() { // Big block of code } It's more readable and more efficient. Finally the block of code that's probably the biggest culprit in slowing your game down is this one: this.update = function() { ctx.drawImage(allImgs[allImgsCnt], this.x, this.y, this.width, this.height); this.x = this.x + (this.speedX * this.directionX); // always = +1 or -1 // idTag = this.idTag; if(this.x > canvas.width - 2) { this.directionX = -1; // change direction this.x = canvas.width - 2; this.tripsCnt++; totalTrips++; } if(this.x < -64 ) { this.directionX = 1; // change direction this.x = 0; this.tripsCnt++; totalTrips++; } if(this.tripsCnt > this.tripsMax) { // time to change sprites if(this.idTag == "tru01") { this.speedX = 0; tru01.tripsCnt = 0; this.visible=false ; lie01.speedX=1 ; lie01.visible=true ; // idTag = "lie01"; } if(this.idTag == "tru02") {this.speedX = 0; tru02.tripsCnt =0; this.visible=false ; lie02.speedX=2 ; lie02.visible=true ; // idTag = "lie02"; } if(this.idTag == "tru03") {this.speedX = 0; tru03.tripsCnt =0; this.visible=false ; lie03.speedX=1 ; lie03.visible=true ; // idTag = "lie03"; } if(this.idTag == "tru04") {this.speedX = 0; tru03.tripsCnt =0; this.visible=false ; lie04.speedX=1 ; lie04.visible=true ; // idTag = "lie03"; } if(this.idTag == "lie01") {this.speedX = 0; lie01.tripsCnt =0; this.visible=false ; tru01.speedX=1 ; tru01.visible=true ; // idTag = "tru01" ; } if(this.idTag == "lie02") {this.speedX = 0; lie02.tripsCnt =0; this.visible=false ; tru02.speedX=1 ; tru02.visible=true ; // idTag = "tru02" ; } if(this.idTag == "lie03") {this.speedX = 0; lie03.tripsCnt =0; tru03.speedX=1 ; tru03.visible=true ; // idTag = "tru03" ; } if(this.idTag == "lie04") {this.speedX = 0; lie04.tripsCnt =0; tru04.speedX=1 ; tru04.visible=true ; // idTag = "tru04" ; } } for (var i = cowpies.length - 1; i >= 0; i--) { thisPie = i; if (cowpies[thisPie].idActive) { if(self.visible) { if (cowpies[thisPie].y < this.y + this.height && cowpies[thisPie].y + cowpies[thisPie].height > this.y) { if (cowpies[thisPie].x < this.x + this.width && cowpies[thisPie].x + cowpies[thisPie].width > this.x ) { thisIdTag = this.idTag ; var findsIt = 0 ; var playsIt = 0 ; var yestru = thisIdTag.startsWith("tru"); var yeslie = thisIdTag.startsWith("lie"); if(yestru) { switch(this.idTag) { case "tru01":tru01.visible = false ; tru01.tripsCnt =0 ; tru01.x = -60; this.speedX = 0; lie01.visible=true ; lie01.tripsCnt =0 ; lie01.x = 0 ; lie01.speedX = 1; break; case "tru02": tru02.visible = false ; tru02.tripsCnt =0 ; tru02.x = -60; this.speedX = 0; lie02.visible=true ; lie02.tripsCnt =0 ; lie02.x = 0 ; lie02.speedX = 1; break; case "tru03": tru03.visible = false ; tru03.tripsCnt =0 ; tru03.x = -60; this.speedX = 0; lie03.visible=true ; lie03.tripsCnt =0 ; lie03.x = 0 ; lie03.speedX = 1; break; case "tru04": tru04.visible = false ; tru04.tripsCnt =0 ; tru04.x = -60; this.speedX = 0; lie04.visible=true ; lie04.tripsCnt =0 ; lie04.x = 0 ; lie04.speedX = 1; break; } playsIt = My_audio_Urls.indexOf("sounds/oops.mp3"); oopsScore ++; playAudio(cached_Audio_files[playsIt]); } if(yeslie){ switch(this.idTag) { case "lie01": lie01.visible=false ; lie01.tripsCnt =0 ; lie01.x = -60; this.speedX = 0; tru01.visible=true ; tru01.tripsCnt =0 ; tru01.x = 0; tru01.speedX = 1; break ; case "lie02": lie02.visible=false ; lie02.tripsCnt =0 ; lie02.x = -60; this.speedX = 0; tru02.visible=true ; tru02.tripsCnt =0 ; tru02.x = 0; tru02.speedX = 1; break ; case "lie03": lie03.visible=false ; lie03.tripsCnt =0 ; lie03.x = -60; this.speedX = 0; tru03.visible=true ; tru03.tripsCnt =0 ; tru03.x = 0; tru03.speedX = 1; break ; case "lie04": lie04.visible=false ; lie04.tripsCnt =0 ; lie04.x = -60; this.speedX = 0; tru04.visible=true ; tru04.tripsCnt =0 ; tru04.x = 0; tru04.speedX = 1; break ; } playsIt = My_audio_Urls.indexOf("sounds/CowMooSplat.mp3"); goodHits ++ ; playAudio(cached_Audio_files[playsIt]); } cowpies.splice(thisPie,1); //alert("cowpies.length= "+ cowpies.length); totalScore = ((goodHits * 4) - (oopsScore * 2)); } } } } } } I've fixed the indentation halfway just so I could understand what it was doing. There are many issues with this: 1. This assignment is completely useless: thisPie = i;, but if you changed it to thisPie = cowpies; it would improve efficiency by a lot. 2. String operations are expensive. The whole "idTag" property is unnecessary. thisIdTag = this.idTag ; // Another unnecessary assignment var findsIt = 0 ; var playsIt = 0 ; var yestru = thisIdTag.startsWith("tru"); // String operations var yeslie = thisIdTag.startsWith("lie"); // String operations if(yestru) { // Some code } if(yeslie){ // Some code } If you had given a boolean property isTrue to your TargetImages object you could use this code instead: if(this.isTrue) { // Some code } else { // Some code } 3. Your objects are aware of other objects' existence. This block of code has the object trying to identify itself among the others. Logic like this should not be inside the object's own code: if(this.idTag == "tru02") {this.speedX = 0; tru02.tripsCnt =0; this.visible=false ; lie02.speedX=2 ; lie02.visible=true ; // idTag = "lie02"; } if(this.idTag == "tru03") {this.speedX = 0; tru03.tripsCnt =0; this.visible=false ; lie03.speedX=1 ; lie03.visible=true ; // idTag = "lie03"; } if(this.idTag == "tru04") {this.speedX = 0; tru03.tripsCnt =0; this.visible=false ; lie04.speedX=1 ; lie04.visible=true ; // idTag = "lie03"; } if(this.idTag == "lie01") {this.speedX = 0; lie01.tripsCnt =0; this.visible=false ; tru01.speedX=1 ; tru01.visible=true ; // idTag = "tru01" ; } if(this.idTag == "lie02") {this.speedX = 0; lie02.tripsCnt =0; this.visible=false ; tru02.speedX=1 ; tru02.visible=true ; // idTag = "tru02" ; } if(this.idTag == "lie03") {this.speedX = 0; lie03.tripsCnt =0; tru03.speedX=1 ; tru03.visible=true ; // idTag = "tru03" ; } if(this.idTag == "lie04") {this.speedX = 0; lie04.tripsCnt =0; tru04.speedX=1 ; tru04.visible=true ; // idTag = "tru04" ; } The same thing is going on in these blocks of code: switch(this.idTag) { case "tru01":tru01.visible = false ; tru01.tripsCnt =0 ; tru01.x = -60; this.speedX = 0; lie01.visible=true ; lie01.tripsCnt =0 ; lie01.x = 0 ; lie01.speedX = 1; break; case "tru02": tru02.visible = false ; tru02.tripsCnt =0 ; tru02.x = -60; this.speedX = 0; lie02.visible=true ; lie02.tripsCnt =0 ; lie02.x = 0 ; lie02.speedX = 1; break; case "tru03": tru03.visible = false ; tru03.tripsCnt =0 ; tru03.x = -60; this.speedX = 0; lie03.visible=true ; lie03.tripsCnt =0 ; lie03.x = 0 ; lie03.speedX = 1; break; case "tru04": tru04.visible = false ; tru04.tripsCnt =0 ; tru04.x = -60; this.speedX = 0; lie04.visible=true ; lie04.tripsCnt =0 ; lie04.x = 0 ; lie04.speedX = 1; break; } switch(this.idTag) { case "lie01": lie01.visible=false ; lie01.tripsCnt =0 ; lie01.x = -60; this.speedX = 0; tru01.visible=true ; tru01.tripsCnt =0 ; tru01.x = 0; tru01.speedX = 1; break ; case "lie02": lie02.visible=false ; lie02.tripsCnt =0 ; lie02.x = -60; this.speedX = 0; tru02.visible=true ; tru02.tripsCnt =0 ; tru02.x = 0; tru02.speedX = 1; break ; case "lie03": lie03.visible=false ; lie03.tripsCnt =0 ; lie03.x = -60; this.speedX = 0; tru03.visible=true ; tru03.tripsCnt =0 ; tru03.x = 0; tru03.speedX = 1; break ; case "lie04": lie04.visible=false ; lie04.tripsCnt =0 ; lie04.x = -60; this.speedX = 0; tru04.visible=true ; tru04.tripsCnt =0 ; tru04.x = 0; tru04.speedX = 1; break ; } These are also string comparisons. Just to test each of the cases the computer is actually performing up to five operations per case, as opposed to a single operation used in boolean and integer comparisons. You should actually have an array of TargetImages() objects rather than having a variable for each one. Code like this is very repetitive and inflexible: allImgsCnt = 1; if(tru01.visible) { tru01.speedX = 1; tru01.update();} allImgsCnt = 2; if(tru02.visible) { tru02.speedX = 1; tru02.update(); } allImgsCnt = 3; if(tru03.visible) { tru03.speedX = 1; tru03.update(); } allImgsCnt = 4; if(tru04.visible) { tru04.speedX = 1; tru04.update(); } allImgsCnt = 5; if(lie01.visible) { lie01.speedX = 1; lie01.update(); } allImgsCnt = 6; if(lie02.visible) { lie02.speedX = 1; lie02.update(); } allImgsCnt = 7; if(lie03.visible) { lie03.speedX = 1; lie03.update(); } allImgsCnt = 8; if(lie04.visible) { lie04.speedX = 1; lie04.update(); } allImgsCnt = 0; if(thrower.moveMe) { thrower.update(); drawThrower(); }
  21. I can't really say much about the subject, since XML is such a vague thing. Did they provide software to generate the XML? What are the specifications of the XML they're asking for? I don't really think any publisher would expect writers to know XML. Perhaps they're asking you to save your documents in an XML-based format, which the editing program probably can do, but they would need to specify which one.
  22. You could find out by testing yourself. I don't memorize these kinds of details and I'm not ashamed for it either. Frames and framesets are outdated concepts that are no longer used on the web.
  23. That's not how HTTP works. Each request would have a different response, so it has to be handled by a new XmlHttp object. Store the data in a variable, use that same variable for multiple AJAX requests. // This is the data we're going to send var data = { name: "John", location: "Boston" } // The response handler var handler = function(response) { // DO something } // Send it to page 1 $.ajax({ method: "POST", url: "page1.php", data: data, success : handler }) // Send it to page 2 $.ajax({ method: "POST", url: "page2.php", data: data, success : handler }) // Send it to page 3 $.ajax({ method: "POST", url: "page3.php", data: data, success : handler })
  24. I don't agree with the article. There's no single function that can predict how you intend to use the information supplied by the user. If you intend to use it in your HTML: $html = htmlspecialchars($_GET['data']); If you intend to use it in SQL $query = $pdo->prepare('SELECT * FROM table WHERE id = ?'); $query->execute(array($_GET['data'])); If you intend to use it in mathematical operations: $float = (float) $_GET['data']; $int = (int) $_GET['data']; If you tried to use an escaped GET or POST value in a prepared statement you would end up with backslashes in your database table.
  25. You can send as many requests as you want. To do that in jQuery, just call $.ajax() more than once with different destination URLs.
×
×
  • Create New...