Jump to content

Zubaz

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Zubaz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It depends on your where clause. I can gaurantee you my method is fast. If you're lucky enough to be using an index, great - if not...
  2. can you post your code, or the relevant part of it?
  3. The easiest way to do an albums/pictures structure is by having two tables, and then if you want comments, one more. ALBUMS ---------- + id + name + description + whatever PHOTOS --------- + id + album_id (corresponds to the id column in ALBUMS) + caption + filename + whatever COMMENTS ------------ + id + photo_id (corresponds to id column in PHOTOS) + user + text + whatever else
  4. [!--quoteo(post=373332:date=May 12 2006, 02:53 PM:name=jbreits)--][div class=\'quotetop\']QUOTE(jbreits @ May 12 2006, 02:53 PM) [snapback]373332[/snapback][/div][div class=\'quotemain\'][!--quotec--] Would it be faster to run the complete query once, and cache the results to a file of some sort? Then when loading the next page, the results are read from the file? Perhaps, you could even cache 1 file per page so no-in file processing has to be done. Does this sound like a more efficient method?[/quote] YES. This is easily the most efficient way to do this if you expect high traffic or the count(*) is on a table with a lot of rows. Counts are pretty slow as sql queries go, so if you put the count(*) into a cron (you can decide how often, depending on how often the number actually changes and how it would effect your page count) OR you can have the count update when a new item is added - assuming that happens less than it's looked at. I cache stuff like that into a small MyISAM table in MySQL, and on larger (>1000) row tables, you'll see an improvement immediately. You can certainly cache to a file if you wish, but there's no need to. You know that pagecount table will only get selects except for say once an hour on cron - so you dont' have to worry about locks or anything.
  5. You need to output your date string in a manner that will sort numerically. 06042006 for June 4th 2006 won't sort like you want it to. 20060604 will sort correctly, because the heirarchy is in the same direction. 06042006 > 03042008 (wrong) 20060604 < 20080304 (right!) After that just do something like assign to an array with the date as the key and then do a ksort. [code] (inside your while loop) $filesArray[$date] = $filename; (end while loop) ksort($filesArray); echo '<pre>'; print_r($filesArray); echo '</pre> [/code] [a href=\"http://www.php.net/ksort\" target=\"_blank\"]ksort() on php.net[/a]
  6. You missunderstand. I know how to do the code with readfile - I'm looking for a way to make the connection between media server and client directly, without piping it through php. MEDIA SERVER --> readfile() --> user -bad for high traffic - effectively doubles your bandwith usage MEDIA SERVER --> user -happiness!
  7. So to stop third-party traffic on certain media files my site does, I did a download.php type script that just took in the media id, and found the filename and did a readfile on it for the user. The problem is that when you start doing massive amounts of traffic with it, I think the readfile stream is taking up a lot of cpu. Is there any alternative to readfile that creates a direct link between the user and the file, instead of it having to go through the php? I'm afraid that this is something I need to do on the server end, and not in PHP, but I figured I'd ask.
  8. okay then: [code] <?=array_search($i['country'], $wcr);?> [/code]
  9. I think you would enjoy [a href=\"http://www.phpfreaks.com/phpmanual/page/function.preg-match.html\" target=\"_blank\"]preg_match[/a] and preg_match_all
  10. looks like your connection script ain't right.
  11. I'm not totally sure I get what you're asking, but... [code] <? echo array_search($i['country'], $wcr); ?> [/code]
  12. This might be a little more than you wanted, but this is my favorite related Javascript function and should teach you a little bit about what you're trying to do if you try it out: [code] <div id="testDiv">I'm learning about innerHTML!</div> <script language="Javascript"> function $() {     var elements = new Array();     for (var i = 0; i < arguments.length; i++) {         var element = arguments[i];         if (typeof element == 'string')             element = document.getElementById(element);         if (arguments.length == 1)             return element;         elements.push(element);     }     return elements; } $('testDiv').innerHTML = 'I <i>learned</i> about innerHTML. Sucka.'; </script> [/code] You don't need to use the $() function there, but it makes things a lot easier. Typing getElementById gets real old. What these guys are talking about with ajax is a little more complicated, but by doing an example script like below, you can learn stuff: [code] <script language="Javascript"> function ajaxGetCallback(url, post) {    var XMLHttpRequestObject = false;      if (window.XMLHttpRequest) {          XMLHttpRequestObject = new XMLHttpRequest();      } else if (window.ActiveXObject) {          XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");      }           if(XMLHttpRequestObject) {          XMLHttpRequestObject.open("POST", url, true);          XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');          XMLHttpRequestObject.onreadystatechange = function ()          {              if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {                  var response = XMLHttpRequestObject.responseText;                  $('testDiv').innerHTML = response;                  delete XMLHttpRequestObject;                  XMLHttpRequestObject = null;              }          }                   XMLHttpRequestObject.send(post);      } else {          alert('no request made');      } } ajaxGetCallback('path.to.my/phpfile.php', 'vars=iwant&tosend=toit') </script> [/code] Notice that the post vars are just like you'd append to a url after a ? if your postvars variable is an empty string, that'll work too. Using that in conjunction with PHP doing MySQL queries means you can do pretty much whatever you want without changing the page. Sorry if that was way more than you wanted - or wrong :)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.