Jump to content

mattal999

Members
  • Posts

    692
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

mattal999's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Oh, ok. That sorts things out (pardon the pun). How about using multiple queries (or joins) instead? If I wanted to get all of the done = 0 first, then all others and have them all sorted by posted DESC, how would I do that?
  2. This problem has been nagging me for a while now. I have multiple queries that contain this at the end: ORDER BY done = 0 DESC, posted DESC Which makes the results ordered in the form 0, 1, -1 which is fine. Now, because of the = 0, MySQL has to perform a filesort. Is there any way around this? Also, is there any way to order the rows by 'done' = 0 first, but then disregard the 'done' state and just sort by posted?
  3. Indeed, and now I've just realised why it wanted to use a filesort instead. It was actually more efficient than using the index. I added another 100 rows and now it works perfectly. Thanks for your help anyway guys.
  4. Well, I need to select everything because I want the 50 most recent rows from that table. EDIT: Funny thing is: SELECT * FROM `logs` FORCE INDEX ( DATETIME ) ORDER BY `datetime` DESC LIMIT 0 , 50 Outputs: id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE logs index NULL datetime 8 NULL 11
  5. Thanks for your reply. That article is interesting, and I've tried it but it doesn't seem to work... Here's the ammended query: SELECT * FROM `logs` WHERE `datetime` > '1970-01-01 00:00:00' ORDER BY `datetime` DESC LIMIT 0, 50 And this results in: id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE logs ALL datetime NULL NULL NULL 11 Using where; Using filesort I'll give the join idea a whirl soon, but as far as I can see, that should have worked...
  6. I'm trying to optimise some queries that seem to be using temporary tables and filesorts, and stumbled across this nasty one. I have the following query: SELECT * FROM `logs` ORDER BY `datetime` DESC LIMIT 0, 50 Here's the table structure: CREATE TABLE IF NOT EXISTS `logs` ( `id` mediumint(12) unsigned NOT NULL AUTO_INCREMENT, `userid` mediumint(10) unsigned NOT NULL, `objectid` mediumint(10) unsigned NOT NULL, `datetime` datetime NOT NULL, `action` varchar(100) NOT NULL, `reason` mediumtext NOT NULL, PRIMARY KEY (`id`), KEY `datetime` (`datetime`) ) ENGINE=MyISAM ; Now, by my understanding, that query should use the datetime key. But instead, it decides to do a filesort. id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE logs ALL NULL NULL NULL NULL 11 Using filesort What am I doing wrong?
  7. Got a better solution after twiddling with one of my Twitter regular expressions. <?php $vara = <<<'END' my first name is $first_name END; $first_name = "james"; preg_match_all("/ +\\$(.*)?/i", $vara, $matches); foreach($matches[1] as $match) { $vara = str_replace("$" . $match, $$match, $vara); } echo $vara; ?> With that, you literally just define all of your variables as you do at the moment.
  8. I imagine a simple str_replace would suffice. <?php $vara = <<<'END' my first name is $first_name END; $variables['first_name'] = "james"; foreach($variables as $name => $value) { $vara = str_replace("$".$name, $value, $vara); } echo $vara; // Output: my first name is james ?> That's the best I can come up with. You may be able to use regular expressions to pick the variable names out of the nowdoc after including the defining file and then replace them with the actual variable names.
  9. As I recall you need to enclose variables in {}, like so: $var1 = <<<FIRST the first name is {$varb} FIRST; Edit: After some manual reading, you need to use a heredoc instead of a nowdoc. http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc That says that PHP doesn't parse anything inside a nowdoc, which is defined using single quotes around your name (in this case, FIRST). By removing these quotes everything works as it should.
  10. This line: header( "Content-Type: image/jpeg" ); Is setting the header to indicate a jpeg image. You have a few problems with the appended script that you showed us - firstly you're setting the same header multiple times. That's just bad. Secondly, you're setting the header of the PHP script (+ output) itself, which means that any web browser will interpret your page as an image. What you should be doing is referencing your standalone script using a basic image tag. Example: <img src="standalone.php?file=<?php echo $file[0]; ?>" /> And then in the standalone.php: <?php $file = $_GET['file']; // You'll want to sanitize this, seriously. It's a huge security hole if you don't. $im = new imagick($file); $im->setImageFormat( "jpg" ); header( "Content-Type: image/jpeg" ); $im->thumbnailImage(400, 0); echo $im; ?>
  11. Could you not just use str_ireplace? $pattern=array(".pdf","_","sop","mgmt","ste","risk","eng","dem","bus_it_requests","bus"); $replace=array(""," ","SOP","Management","Steady State -","Risk Management -","Engineering -","Demand Management -","Business/IT Requests","Business Management -"); echo "<a href=\"$file\">" . ucwords(str_ireplace($pattern,$replace,$file)) . "</a></br>"; Just a thought - it depends on how str_replace works as to whether it'll solve your issue. If you need some case sensitive, then just do the case insensitive one and then the case sensitive one on the result.
  12. My bad - replace: foreach($links as $link) { echo checkSite($_POST['www']) . "<br />"; } With: foreach($links as $link) { echo checkSite($link) . "<br />"; }
  13. <?php function checkSite($www) { $ch = curl_init('http://www.google.pl/search?hl=pl&q=site%3A'.trim($www).'&btnG=Szukaj&source=hp'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $sHtml = curl_exec($ch); preg_match('#\<div id=resultStats\>.*([0-9,]+) wynik#Ui', $sHtml, $aMatches); curl_close($ch); return (int)str_replace(',', '', $aMatches[1]); } if($_POST['www']) { $links = explode("\n", $_POST['www']); foreach($links as $link) { echo checkSite($_POST['www']) . "<br />"; } } else { print ('<form method="POST"><textarea name="www" rows="20" cols="100"></textarea><br /><br /><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></form>'); } ?>
  14. The only thing that could be not working would have to be the MySQL connection - everything else is fine. I even tested the preg_replace output on the username and password but that seems to be working alright. Try echoing $existCount to see how many rows it's matching, and also add or die(mysql_error()); on the query section.
×
×
  • 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.