Jump to content

JamesB

Members
  • Posts

    425
  • Joined

  • Last visited

Posts posted by JamesB

  1. 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. I thought that
    $chkUsr = "SELECT COUNT(*) FROM login WHERE username='$username'";$result = $pdo->query($chkUsr);

    I thought that $result should now contain the result of "$pdo->query($chkUsr)" ?

    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. $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];

    • Like 1
  4. 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

    • Like 1
  5. 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

  6. 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.

    • Like 1
  7. 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)}

    • Like 1
  8. 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);}

    • Like 1
  9. 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

  10. 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>

  11. 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;

  12. 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...