Jump to content

JamesB

Members
  • Posts

    425
  • Joined

  • Last visited

Everything posted by JamesB

  1. JamesB

    Session variables

    If you want a dynamic table name in the query: $tableName = 'mobiles';$result = mysql_query("SELECT * FROM ".$tableName); Also table names in a query are surrounded by ` instead of '.
  2. from the PHP manual:"PDO::query() returns a PDOStatement object, or FALSE on failure." http://php.net/manual/en/pdo.query.php in your first post where you've got:if($pdo->query($chkUsr) = $username){ that should be using 2 equal signs, as its a comparison not an assignment. but if you're wanting to check if a username exists, based on your existing query, you can check if the COUNT(*) gives anything but 0: $chkUsr = "SELECT COUNT(*) FROM login WHERE username='$username'";$result = $pdo->query($chkUsr); $row = $result->fetch(PDO::FETCH_NUM);if($row[0] != 0){ die('ERROR: This username is already taken!');}
  3. you've got 'values' repeated twice, also try removing the square brackets.
  4. try putting single quotes around $username in the query
  5. none, it is the same function.document is a global variable, and all global variables can be accessed through the window object.
  6. $result = mysql_query('SELECT SUM(malai) AS total FROM orders WHERE delivered = 0');$row = mysql_fetch_assoc($result);echo $row['total']; $result = mysql_query('SELECT SUM(malai) FROM orders WHERE delivered = 0');$row = mysql_fetch_row($result);echo $row[0];
  7. $row['malai'] The string given to $row should match the one used after 'AS' in the query.
  8. Also if you're looking to access the total number via a string into $row, instead of an integer into $row, you should use the 'as' keyword in the query:http://www.w3schools.com/sql/sql_alias.asp eg. SELECT SUM(malai) AS malai FROM orders WHERE delivery = 0
  9. That seems to pass valid requests to apache, and invalid requests to php.I'm after having valid requests passed to both php and apache.
  10. I'm trying to have image requests passed to php (to increment hit counts for the images) and then have apache handle the image request as normal. I'm wanting to avoid outputting the image binary data in php, to take advantage of apache's encoding/compression/caching etc.Also i'm looking to avoid external redirection with a Location header. eg.1) I visit http://127.0.0.1/image.png in the browser2) A .htaccess file catches requests with image file extensions and:2a) Gives the image filename to php2b) Outputs the image's binary data (as if there was no rewrite rule) I managed to pass image requests to php with this: RewriteEngine OnRewriteRule ^(.*\.(png|bmp|gif|jpg|jpeg))$ on_view_image.php?path=$1 But I can't seem to let apache handle the request as normal after it's been sent to php. I've tried this: (any many other ways too) RewriteEngine OnRewriteRule ^(.*\.(png|bmp|gif|jpg|jpeg))$ $1RewriteRule ^(.*\.(png|bmp|gif|jpg|jpeg))$ on_view_image.php?path=$1 But that appears to ignore the apache rule and only run the php rule.The only reason I've put the apache rule before the php rule there is because I read "Subsequent patterns are matched against the output of the last matching RewriteRule.".But ideally I'd want it to run the php rule first lol, in case the client connection is lost when downloading the image (assuming next rules only get ran when the previous one is complete, just guessing on that). Thanks,James
  11. not sure if this will fix it, but try removing the comma at the end of: classtype = '$classtype',
  12. mysql_affected_rows() should work:http://www.php.net/m...fected-rows.php
  13. I guess if player_stats was split into 2 tables, 1 for the last 24 hours, and 1 for 24+ hours, it would probably be faster for the 24 hour batch run, but i'm just guessing with that, I don't know much about database performance.
  14. I'd go with something like this: players player_id player_name player_stats player_id retrieval_time stat1 stat2 stat3 every hour: foreach player {fetch stats for player, and insert 1 row into player_stats} every 24 hours: foreach player {remove rows for player_id where retrieval_time >= (current time - 24 hours) and retrieval_time != (max(retrieval_time) for player_id)}
  15. JamesB

    outer inner loop

    should be 2 equal signs for comparison, as $r = 1 will result in true.
  16. JamesB

    How to escape &

    i'm pretty sure the & character doesn't need escaping:http://dev.mysql.com/doc/refman/5.6/en/string-literals.html try changing the commas to AND or OR.
  17. as birbal showed, without using the brackets AND will take priority over OR, due to operator precedence:http://dev.mysql.com...precedence.html without the brackets in your query, it was actually getting ran as: SELECT * FROM members WHERE nick='$username' OR (email='$username' AND password='$password') which is also a huge security issue, as any password could have been used with a valid username.
  18. According to the PHP manual, end() takes it's parameter by reference.http://php.net/manua...unction.end.php Sending an array directly to end() is not valid, as it would not be passing it by reference, eg. end(array());//orend(explode(' ', 'a b c')); But these would be valid because they are stored in a variable first: $a = array();end($a);//or$a = explode(' ', 'a b c');end($a);
  19. If you want your MakeRequest() function to return the response text from ajax, the ajax request would need to be synchronous.That is, ajax's send() method would pause javascript execution until the ajax request is completed, and then it could return the response text.But pausing javascript's execution isn't ideal, it's much better to use an asynchronous request. You're currently using an asynchronous request (3rd argument to open() is true), but the responseText property in this code will not have been set yet: return xmlHttp.responseText It's common to send a function to the function which creates the ajax request, and when the ajax request is complete it simply calls the function sent to it.eg. MakeRequest(function(xmlHttp) { alert(xmlHttp.responseText);}); and function MakeRequest(callback) {var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function(){if(xmlHttp.readyState == 4){callback(xmlHttp);}} xmlHttp.open("GET", "ajax.php", true);xmlHttp.send(null);}
  20. how about splitting the sub entries into tags within the tag, like changing: <platform>Java, .NET, Mainframe</platform> to something like: <platform> <subentry>Java</subentry> <subentry>.NET</subentry> <subentry>Mainframe</subentry></platform> and <servicegroup>System Integration (SI), Technology Consulting (TC)</servicegroup> into: <servicegroup> <subentry>System Integration (SI)</subentry> <subentry>Technology Consulting (TC)</subentry></servicegroup> and the code which searches for the text could perform this on each filter: - if there are sub entries, do a "where" on each sub entry's value- if there are no sub entries, do a "where" on the single value
  21. If your wanting JavaScript to fetch the contents of a xml or txt file which is on the server, you can use AJAX inside JavaScript. var ajax = new XMLHttpRequest; ajax.onreadystatechange = function() { if (ajax.readyState == 4) { alert(ajax.responseText); }} ajax.open('GET', 'path/to/some_file.txt', true);ajax.send(); http://www.w3schools...equest_send.asp
  22. This code: <script type="text/javascript"> $('.dropdown-toggle').dropdown(); </script> will get ran before the <body> of the document is loaded, because it's in the <head>. You can tell it to run the code when the window is loaded, by assigning a function to window.onload: <script type="text/javascript"> window.onload = function() {$('.dropdown-toggle').dropdown();} </script>
  23. I'd recommend echoing this query: (to see exactly what is getting sent to mysql_query()) $sql = mysql_query("SELECT * FROM myMembers WHERE id='$u_id' AND username='$u_name' AND email='$u_email' AND locator='$u_loca'"); Try adding the following line before it: echo "SELECT * FROM myMembers WHERE id='$u_id' AND username='$u_name' AND email='$u_email' AND locator='$u_loca'";exit;
  24. haha, fantastic! my favourite updates/fixes: Implemented the HTML5 parsing algorithmImplemented full support for ECMAScript 5.1Ctrl+T doesn't set focus in address fieldBlurry thumbnails when resizing Speed DialGmail inbox doesn't load http://www.opera.com...s/windows/1160/
  25. I made this function some time ago, I doubt it's very efficient but it should work: function getElementsByAttribute(Attribute, Value) {var Elements = []; var scanElementNodes = function(Element) {var Nodes = Element.childNodes;var i, j = Nodes.length, Node;var i2, j2, Attributes, Attribute2; for (i=0; i<j; i++) {Node = Element.childNodes[i];if (Node.nodeType == 1) { Attributes = Node.attributes;j2 = Attributes.length;for (i2=0; i2<j2; i2++) {Attribute2 = Attributes[i2];if (Attribute2.nodeName == Attribute && Attribute2.nodeValue == Value) {Elements.push(Node);break;}} scanElementNodes(Node);}}} scanElementNodes(this); return Elements;}HTMLElement.prototype.getElementsByAttribute = getElementsByAttribute;document.getElementsByAttribute = getElementsByAttribute; then you could do like: var tds = document.getElementsByAttribute('itemprop', 'productID');alert( tds[0].innerHTML );
×
×
  • Create New...