Jump to content

sequalit

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Everything posted by sequalit

  1. At first I didn't think PHP could do half the stuff it can, such as write and read files and such. The more I learn about PHP the more I see its just like any other OO-Programming language out there, and can do all the same stuff, only difference is you have to run a apache server and a web browser haha
  2. Is this secure? Technically anything other than letters and numbers should throw it off right? if(!ctype_alnum($_POST['username'])){ die('hey a hacker!'); }else{ $result = mysql_query(sprintf("SELECT * FROM users WHERE username='%s'", $_POST['username']) }
  3. why do you have a while loop for the images?
  4. you can write the code to a file and then include('/path/to/filename');
  5. Think you better start working on it In my opinion, anybody would be crazy to do that for you... Whats the point in learning PHP if you're not willing to fork over the brain cells? Some hints though: the links are using AJAX
  6. Won't let me edit post for some odd reason? Anways, a couple of changes Change all instancse of $_SESSION to $GLOBALS - better place to store it. And in the echoAll() class, change this line echo $message[1]."<br>"; to this echo "Message $i: ".$message[1]."<br>";
  7. Ever look at your code and you have a million echo statements throughout your code, and some are commented out others are not, and you used these echo's to help you debug your application during development? I wrote a simple class to help with debugging! With this class you will never have to uncomment your echo statements again! Just tell the debugger class to not display those messages! Its awesome! I'm sure this could use some work to be made even cooler Please give any idea's or suggestions you have so that I can make this cooler If you add something to it, please let me know in this post, so I can merge it into the official class Where would be the best place to store this? I choose $_SESSION because thats the only place i know of to put it! Debugger Source, version 1 /** * Copyright (c) 2008 Thadeus N. Burgess (thadeus.burgess(at)gmail.com) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * define("ECHOS", true); define("ECHO_SEPERATOR", "~|~"); define("debugger", "Debugger"); /** * Class to handle echo messages used for debugging during development process */ class Debugger{ private $echos; private $echoPages; /** * Constructor. * If ECHOS true then we set up the arrays */ function Debugger(){ if(ECHOS){ //if echos is off, we do nothing, to save memory $this->echos = array(); $this->echoPages = array(); } } /** * Mark page to be echo'ed * * @param string $page Name of message to be echo'ed EX. 'index.php', 'mysql.class', 'foo.function' * * @return void */ function setDoEcho($page){ if(ECHOS) //if echos is off, we do nothing, to save memory array_push($this->echoPages, $page); } /** * Register message to be echo'ed * * @param string $page Name of message to be echo'ed EX. 'index.php', 'mysql.class', 'foo.function' * @param string $message Message that will be echo'ed * * @return void */ function registerEcho($page, $message){ if(ECHOS) //if echos is off, we do nothing, to save memory array_push($this->echos, $page.ECHO_SEPERATOR.$message); } /** * Echo all messages that have been set to echo */ function echoAll(){ if(ECHOS)//if echos is off, we do nothing, to save memory for($i=0;$i<count($this->echos);$i++){ $message = explode(ECHO_SEPERATOR, $this->echos[$i]); if(in_array($message[0], $this->echoPages))// if we have set it to be echo'ed, echo it echo $message[1]."<br>"; } echo "<br><br><br>"; } } HOW TO USE: index.php require_once('debugger.php'); $_SESSION[debugger] = new Debugger(); // we set it in session so that everything can access it if(ECHOS){ //All you have to do now is comment these out to not display //a module!!! How awesome!! //examples $_SESSION[debugger]->setDoEcho('database.php'); $_SESSION[debugger]->setDoEcho('doSomething.function'); $_SESSION[debugger]->setDoEcho('a_thing.class'); $_SESSION[debugger]->setDoEcho('mysql.class'); $_SESSION[debugger]->setDoEcho('hello.world'); $_SESSION[debugger]->echoAll();// echo all messages in order } Then anywhere you want an echo do this $message = "Hello World"; $_SESSSION[debugger]->registerEcho('hello.world', $message); Turn This function query($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; //echo "<br>QUERYING"; //echo "<br>". $this->query; $this->res = mysql_query($sql, $this->con); //echo "<br>RESULTS: ".$this->res."<br>"; //return new results($this->res); } Into This: function query($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; $this->res = mysql_query($sql, $this->con); if(!$this->res) $this->queryError(); $_SESSION[debugger]->registerEcho('mysql.class', "QUERYING: ".$this->query); $_SESSION[debugger]->registerEcho('mysql.class', "RESULTS: ".$this->res); }
  8. Thank you dbo and 448191 I ended up looking at both for examples and idea's and built my own I now have a great MVC template system that I LOVE!!!! It's so awesome, works great! I love you guys ;p
  9. Average Time of PHP Completion (100 results) :0.00052145242691 Average Time of QRY Completion (100 results) :0.000961785316467 PHP faster by :0.000333070755005 0.00061297416687 - 0.000946044921875 PHP faster by :0.000367879867554 0.000465154647827 - 0.000833034515381 PHP faster by :0.00034499168396 0.000468015670776 - 0.000813007354736 PHP faster by :0.000280857086182 0.000524997711182 - 0.000805854797363 PHP faster by :0.000319004058838 0.000500917434692 - 0.00081992149353 PHP faster by :0.000659942626953 0.00047492980957 - 0.00113487243652 QRY faster by :0.000424146652222 0.0012640953064 - 0.000839948654175 PHP faster by :0.000411987304688 0.000391960144043 - 0.00080394744873 PHP faster by :0.000409841537476 0.000393152236938 - 0.000802993774414 PHP faster by :0.00040078163147 0.000395059585571 - 0.000795841217041 PHP faster by :0.000392913818359 0.000403165817261 - 0.00079607963562 PHP faster by :0.000401020050049 0.000396013259888 - 0.000797033309937 PHP faster by :0.000380992889404 0.000416994094849 - 0.000797986984253 PHP faster by :0.000495910644531 0.000389099121094 - 0.000885009765625 PHP faster by :0.000411987304688 0.000391960144043 - 0.00080394744873 PHP faster by :0.000400066375732 0.000405073165894 - 0.000805139541626 PHP faster by :0.000410079956055 0.000391960144043 - 0.000802040100098 PHP faster by :0.000412940979004 0.000388145446777 - 0.000801086425781 PHP faster by :0.000998973846436 0.000396013259888 - 0.00139498710632 PHP faster by :0.000407934188843 0.000395059585571 - 0.000802993774414 QRY faster by :0.000292062759399 0.00124311447144 - 0.000951051712036 PHP faster by :0.000439167022705 0.000391960144043 - 0.000831127166748 PHP faster by :0.000866889953613 0.000389099121094 - 0.00125598907471 PHP faster by :0.000408887863159 0.000400066375732 - 0.000808954238892 PHP faster by :0.000417232513428 0.000392913818359 - 0.000810146331787 PHP faster by :0.000415086746216 0.000393867492676 - 0.000808954238892 PHP faster by :0.000421047210693 0.000391006469727 - 0.00081205368042 PHP faster by :0.00041389465332 0.000395059585571 - 0.000808954238892 PHP faster by :0.000414848327637 0.000389099121094 - 0.00080394744873 PHP faster by :0.000419855117798 0.000393152236938 - 0.000813007354736 PHP faster by :0.000417232513428 0.000512838363647 - 0.000930070877075 PHP faster by :0.000409126281738 0.000388860702515 - 0.000797986984253 PHP faster by :0.000411987304688 0.000388860702515 - 0.000800848007202 PHP faster by :0.00041127204895 0.00038480758667 - 0.00079607963562 PHP faster by :0.000415802001953 0.000388145446777 - 0.00080394744873 PHP faster by :0.000412940979004 0.000389099121094 - 0.000802040100098 PHP faster by :0.000412940979004 0.00039005279541 - 0.000802993774414 PHP faster by :0.000915050506592 0.000385046005249 - 0.00130009651184 PHP faster by :0.000320911407471 0.000483989715576 - 0.000804901123047 PHP faster by :0.000415086746216 0.000391006469727 - 0.000806093215942 PHP faster by :0.000419855117798 0.000396013259888 - 0.000815868377686 PHP faster by :0.000414848327637 0.000388145446777 - 0.000802993774414 PHP faster by :0.000408172607422 0.000391960144043 - 0.000800132751465 PHP faster by :0.000945091247559 0.000388860702515 - 0.00133395195007 PHP faster by :0.000409841537476 0.000394105911255 - 0.00080394744873 PHP faster by :0.000416994094849 0.000391006469727 - 0.000808000564575 PHP faster by :0.000655651092529 0.000393152236938 - 0.00104880332947 PHP faster by :0.000524044036865 0.000395059585571 - 0.000919103622437 PHP faster by :0.000411987304688 0.000385999679565 - 0.000797986984253 PHP faster by :0.000810861587524 0.000389099121094 - 0.00119996070862 PHP faster by :0.000418901443481 0.000391006469727 - 0.000809907913208 PHP faster by :0.000416994094849 0.000389099121094 - 0.000806093215942 PHP faster by :0.000427961349487 0.000399112701416 - 0.000827074050903 PHP faster by :0.000445127487183 0.000395059585571 - 0.000840187072754 PHP faster by :0.000355958938599 0.000424146652222 - 0.00078010559082 PHP faster by :0.00093412399292 0.000375986099243 - 0.00131011009216 PHP faster by :0.000789880752563 0.000403165817261 - 0.00119304656982 PHP faster by :0.000420093536377 0.000396966934204 - 0.000817060470581 PHP faster by :0.000411033630371 0.000391006469727 - 0.000802040100098 PHP faster by :0.000423908233643 0.000386953353882 - 0.000810861587524 PHP faster by :0.000442028045654 0.000391960144043 - 0.000833988189697 PHP faster by :0.00114011764526 0.000401973724365 - 0.00154209136963 PHP faster by :0.000420808792114 0.000392198562622 - 0.000813007354736 PHP faster by :0.000306129455566 0.000504970550537 - 0.000811100006104 PHP faster by :0.000336885452271 0.000473022460938 - 0.000809907913208 PHP faster by :0.000412940979004 0.0003981590271 - 0.000811100006104 PHP faster by :0.000419139862061 0.000386953353882 - 0.000806093215942 PHP faster by :0.000409126281738 0.000396013259888 - 0.000805139541626 PHP faster by :0.000429153442383 0.000391960144043 - 0.000821113586426 PHP faster by :0.00040602684021 0.000393867492676 - 0.000799894332886 PHP faster by :0.00041127204895 0.000387907028198 - 0.000799179077148 PHP faster by :0.00040602684021 0.000396013259888 - 0.000802040100098 PHP faster by :0.000472068786621 0.00048303604126 - 0.000955104827881 PHP faster by :0.000577926635742 0.000468969345093 - 0.00104689598083 PHP faster by :0.00032901763916 0.000484943389893 - 0.000813961029053 PHP faster by :0.000324726104736 0.000477075576782 - 0.000801801681519 PHP faster by :0.000331878662109 0.000469923019409 - 0.000801801681519 PHP faster by :0.000359058380127 0.000468969345093 - 0.00082802772522 PHP faster by :0.000334024429321 0.00046706199646 - 0.000801086425781 PHP faster by :0.000325202941895 0.00047492980957 - 0.000800132751465 PHP faster by :0.000371217727661 0.000470876693726 - 0.000842094421387 PHP faster by :4.29153442383E-05 0.000797033309937 - 0.000839948654175 PHP faster by :0.000309944152832 0.000498056411743 - 0.000808000564575 PHP faster by :0.000505208969116 0.000476837158203 - 0.000982046127319 PHP faster by :0.00117111206055 0.00120401382446 - 0.00237512588501 PHP faster by :0.000298976898193 0.000488996505737 - 0.000787973403931 PHP faster by :0.000324010848999 0.000458955764771 - 0.00078296661377 PHP faster by :0.000342130661011 0.000458955764771 - 0.000801086425781 PHP faster by :0.000323057174683 0.000463008880615 - 0.000786066055298 PHP faster by :0.000323057174683 0.000460863113403 - 0.000783920288086 PHP faster by :0.000317096710205 0.000464916229248 - 0.000782012939453 PHP faster by :0.000832796096802 0.00045919418335 - 0.00129199028015 QRY faster by :0.000553131103516 0.00143814086914 - 0.000885009765625 QRY faster by :5.79357147217E-05 0.00163888931274 - 0.00158095359802 PHP faster by :0.000288009643555 0.000504016876221 - 0.000792026519775 PHP faster by :0.00089168548584 0.00045919418335 - 0.00135087966919 PHP faster by :0.000316143035889 0.000465869903564 - 0.000782012939453 PHP faster by :0.000323057174683 0.000464916229248 - 0.000787973403931 PHP faster by :0.00107789039612 0.00274300575256 - 0.00382089614868 PHP faster by :0.0012469291687 0.00280690193176 - 0.00405383110046
  10. i was wondering how to document your functions like that with PHP. Thanks
  11. well i tried to do it again, but under very intense testing... looping each method 10000 times, while keeping a average time and a count on which was faster... Needless to say, I froze my VPS and it has been off-line for the past 6 hours HAHA!~ It's safe to assume then, that it is less intensive and quicker to go with one db query and split the data as needed into the arrays instead of two queries.
  12. Read this -> http://www.sitepoint.com/forums/showpost.php?p=498687&postcount=15 What do you guys think? I think he's right, a template engine just makes things go that much slower...
  13. the database returns ~1000 results each query. The connect to the database was made once, then queries ran each time, then the database was closed in the end. The objective is to get two arrays, to be passed into a template engine for display into two tables, one for each kind of data. my DB abstraction layer, so you can see it ;p, though please explain what it has to do with it? <?php class MySQL{ protected $con; protected $res; protected $query; protected $connected; protected $server; protected $user; protected $pass; protected $database; function MySQL($server, $user, $pass, $database){ $this->server = $server; $this->user = $user; $this->pass = $pass; $this->database = $database; $this->query = ""; $this->connect(); } function selectDB($db){ mysql_select_db($db, $this->con); } function connect(){ $this->con = mysql_pconnect($this->server, $this->user, $this->pass) or trigger_error(mysql_error(), E_USER_ERROR); $this->selectDB($this->database); $this->connected = true; } function query($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; $this->res = mysql_query($sql, $this->con); } function queryGetResults($sql){ if(!$this->connected) $this->connect(); $this->query = $sql; $this->res = mysql_query($sql, $this->con); return new results($this->res); } function queryError(){ echo "Unable to process query<br />"; $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $this->query; die($message); } function getResults(){ return new results($this->res); } function fetch(){ return mysql_fetch_row($this->res); } function close(){ if(!$this->connected) return; mysql_close($this->con); $this->connected = false; } } class results{ protected $data; function results($res){ $this->data = $res; } function getResults(){ return $this->data; } function free(){ mysql_free_result($this->data); } function fetch(){ return mysql_fetch_assoc($this->data); } function fetchTable(){ $table = array(); if(mysql_num_rows($this->data) == 0) return $table; mysql_data_seek($this->data, 0); while($row = mysql_fetch_array($this->data, MYSQL_BOTH)){ array_push($table, $row); } return $table; } function fetchTableAndFree(){ $table = $this->fetchTable(); $this->free(); return $table; } } ?>
  14. more results: Looking at it, it seems that running two queries generally runs around .0008 no matter what, sometimes it shot up to .0010 Parsing with PHP was sometimes twice as fast as running two queries, but in some cases ended up being very slow. All these calls were made in a for loop one right after another... Generally parsing in PHP is faster, but if you are making a bunch of database calls at the same time, two queries is more stable. Took 0.000423908233643 to run one big query and parse with PHP Took 0.00081992149353 to run two queries Took 0.00131893157959 to run one big query and parse with PHP Took 0.00081205368042 to run two queries Took 0.00046706199646 to run one big query and parse with PHP Took 0.000813961029053 to run two queries Took 0.000460863113403 to run one big query and parse with PHP Took 0.00080394744873 to run two queries Took 0.00125288963318 to run one big query and parse with PHP Took 0.000875949859619 to run two queries Took 0.000470161437988 to run one big query and parse with PHP Took 0.000808000564575 to run two queries Took 0.00047492980957 to run one big query and parse with PHP Took 0.000827074050903 to run two queries Took 0.000459909439087 to run one big query and parse with PHP Took 0.000782012939453 to run two queries Took 0.000473976135254 to run one big query and parse with PHP Took 0.00080394744873 to run two queries Took 0.00162196159363 to run one big query and parse with PHP Took 0.000848054885864 to run two queries Took 0.000874996185303 to run one big query and parse with PHP Took 0.000823020935059 to run two queries Took 0.000463008880615 to run one big query and parse with PHP Took 0.000833988189697 to run two queries Took 0.000469923019409 to run one big query and parse with PHP Took 0.000808954238892 to run two queries Took 0.000465154647827 to run one big query and parse with PHP Took 0.000816822052002 to run two queries Took 0.000470161437988 to run one big query and parse with PHP Took 0.000808954238892 to run two queries Took 0.000465154647827 to run one big query and parse with PHP Took 0.00120115280151 to run two queries Took 0.000458955764771 to run one big query and parse with PHP Took 0.000802040100098 to run two queries Took 0.000505924224854 to run one big query and parse with PHP Took 0.000778913497925 to run two queries Took 0.000575065612793 to run one big query and parse with PHP Took 0.000818014144897 to run two queries Took 0.000460863113403 to run one big query and parse with PHP Took 0.000833034515381 to run two queries Took 0.000464916229248 to run one big query and parse with PHP Took 0.000817775726318 to run two queries Took 0.000471115112305 to run one big query and parse with PHP Took 0.00116610527039 to run two queries Took 0.000472068786621 to run one big query and parse with PHP Took 0.000845193862915 to run two queries Took 0.000591039657593 to run one big query and parse with PHP Took 0.00122308731079 to run two queries Took 0.000942945480347 to run one big query and parse with PHP Took 0.000870227813721 to run two queries Took 0.000476121902466 to run one big query and parse with PHP Took 0.000828981399536 to run two queries Took 0.000488042831421 to run one big query and parse with PHP Took 0.000829935073853 to run two queries Took 0.000472784042358 to run one big query and parse with PHP Took 0.00139999389648 to run two queries Took 0.00048303604126 to run one big query and parse with PHP Took 0.000809907913208 to run two queries Took 0.000481843948364 to run one big query and parse with PHP Took 0.000984907150269 to run two queries Took 0.000528812408447 to run one big query and parse with PHP Took 0.000830888748169 to run two queries Took 0.000534057617188 to run one big query and parse with PHP Took 0.00177597999573 to run two queries Took 0.000501871109009 to run one big query and parse with PHP Took 0.00089693069458 to run two queries Took 0.000468969345093 to run one big query and parse with PHP Took 0.000833034515381 to run two queries Took 0.000463962554932 to run one big query and parse with PHP Took 0.000808000564575 to run two queries Took 0.000488996505737 to run one big query and parse with PHP Took 0.000815153121948 to run two queries Took 0.000463008880615 to run one big query and parse with PHP Took 0.000815868377686 to run two queries Took 0.000468969345093 to run one big query and parse with PHP Took 0.000823974609375 to run two queries Took 0.000459909439087 to run one big query and parse with PHP Took 0.000813961029053 to run two queries Took 0.000459909439087 to run one big query and parse with PHP Took 0.00103998184204 to run two queries Took 0.000488996505737 to run one big query and parse with PHP Took 0.000797986984253 to run two queries Took 0.000468969345093 to run one big query and parse with PHP Took 0.0010769367218 to run two queries Took 0.000463962554932 to run one big query and parse with PHP Took 0.000801086425781 to run two queries Took 0.00112199783325 to run one big query and parse with PHP Took 0.000917196273804 to run two queries Took 0.000474214553833 to run one big query and parse with PHP Took 0.00084114074707 to run two queries Took 0.00047492980957 to run one big query and parse with PHP Took 0.0014021396637 to run two queries Took 0.000473022460938 to run one big query and parse with PHP Took 0.000827074050903 to run two queries Took 0.000460147857666 to run one big query and parse with PHP Took 0.00081992149353 to run two queries Took 0.00082802772522 to run one big query and parse with PHP Took 0.000808954238892 to run two queries Took 0.000445127487183 to run one big query and parse with PHP Took 0.000785827636719 to run two queries Took 0.000448942184448 to run one big query and parse with PHP Took 0.000777959823608 to run two queries Took 0.000454902648926 to run one big query and parse with PHP Took 0.000964164733887 to run two queries Took 0.00047492980957 to run one big query and parse with PHP Took 0.000805854797363 to run two queries Took 0.000469923019409 to run one big query and parse with PHP Took 0.000805854797363 to run two queries Took 0.000472068786621 to run one big query and parse with PHP Took 0.00081205368042 to run two queries Took 0.000466108322144 to run one big query and parse with PHP Took 0.000806093215942 to run two queries Took 0.000468015670776 to run one big query and parse with PHP Took 0.00081205368042 to run two queries Took 0.000463008880615 to run one big query and parse with PHP Took 0.00081205368042 to run two queries Took 0.000465869903564 to run one big query and parse with PHP Took 0.000813961029053 to run two queries Took 0.000465154647827 to run one big query and parse with PHP Took 0.00219416618347 to run two queries Took 0.000470161437988 to run one big query and parse with PHP Took 0.000815868377686 to run two queries Took 0.000478029251099 to run one big query and parse with PHP Took 0.000789880752563 to run two queries Took 0.000449895858765 to run one big query and parse with PHP Took 0.000792980194092 to run two queries Took 0.000457048416138 to run one big query and parse with PHP Took 0.000790119171143 to run two queries Took 0.000483989715576 to run one big query and parse with PHP Took 0.00081205368042 to run two queries Took 0.000463962554932 to run one big query and parse with PHP Took 0.000805854797363 to run two queries Took 0.000761985778809 to run one big query and parse with PHP Took 0.000808954238892 to run two queries Took 0.000484943389893 to run one big query and parse with PHP Took 0.000807046890259 to run two queries Took 0.000473022460938 to run one big query and parse with PHP Took 0.000809907913208 to run two queries Took 0.000472068786621 to run one big query and parse with PHP Took 0.000814914703369 to run two queries Took 0.000465869903564 to run one big query and parse with PHP Took 0.000785112380981 to run two queries Took 0.000453948974609 to run one big query and parse with PHP Took 0.000777006149292 to run two queries Took 0.000452995300293 to run one big query and parse with PHP Took 0.000769853591919 to run two queries Took 0.000452041625977 to run one big query and parse with PHP Took 0.000771999359131 to run two queries Took 0.000447034835815 to run one big query and parse with PHP Took 0.000779867172241 to run two queries Took 0.000449895858765 to run one big query and parse with PHP Took 0.00078010559082 to run two queries Took 0.000447034835815 to run one big query and parse with PHP Took 0.000771999359131 to run two queries Took 0.00044584274292 to run one big query and parse with PHP Took 0.000773906707764 to run two queries Took 0.000443935394287 to run one big query and parse with PHP Took 0.000808000564575 to run two queries Took 0.000463962554932 to run one big query and parse with PHP Took 0.000809907913208 to run two queries Took 0.00139999389648 to run one big query and parse with PHP Took 0.000861167907715 to run two queries Took 0.000831842422485 to run one big query and parse with PHP Took 0.00134301185608 to run two queries Took 0.00045108795166 to run one big query and parse with PHP Took 0.000817060470581 to run two queries Took 0.000458955764771 to run one big query and parse with PHP Took 0.00078296661377 to run two queries Took 0.00045108795166 to run one big query and parse with PHP Took 0.00078010559082 to run two queries Took 0.000455856323242 to run one big query and parse with PHP Took 0.000787973403931 to run two queries Took 0.000458002090454 to run one big query and parse with PHP Took 0.000782012939453 to run two queries Took 0.000454902648926 to run one big query and parse with PHP Took 0.00083589553833 to run two queries Took 0.000458955764771 to run one big query and parse with PHP Took 0.000782012939453 to run two queries Took 0.000453948974609 to run one big query and parse with PHP Took 0.000787019729614 to run two queries Took 0.000457048416138 to run one big query and parse with PHP Took 0.000786066055298 to run two queries Took 0.000452041625977 to run one big query and parse with PHP Took 0.000794887542725 to run two queries Took 0.000455856323242 to run one big query and parse with PHP Took 0.000786066055298 to run two queries Took 0.000452995300293 to run one big query and parse with PHP Took 0.00078821182251 to run two queries Took 0.000463008880615 to run one big query and parse with PHP Took 0.000787019729614 to run two queries Took 0.000452041625977 to run one big query and parse with PHP Took 0.000787019729614 to run two queries Took 0.000468969345093 to run one big query and parse with PHP Took 0.00447082519531 to run two queries Took 0.00273609161377 to run one big query and parse with PHP Took 0.00416684150696 to run two queries Took 0.00421690940857 to run one big query and parse with PHP Took 0.00127410888672 to run two queries Took 0.00244998931885 to run one big query and parse with PHP Took 0.00440096855164 to run two queries
  15. Correction on the example on PHP parsing, you do not have to do the fetchTable() thing I called, which returns a two-deminsional array, you just need the mysql results output Took 0.000418901443481 to run one big query and parse with PHP Took 0.00118207931519 to run two queries Took 0.000531911849976 to run one big query and parse with PHP Took 0.000844955444336 to run two queries Took 0.000542163848877 to run one big query and parse with PHP Took 0.000877141952515 to run two queries Took 0.000545978546143 to run one big query and parse with PHP Took 0.00101900100708 to run two queries Took 0.000496864318848 to run one big query and parse with PHP Took 0.000808000564575 to run two queries function testPHPparsed(){ $time_start = microtime(true); $sql = "". "SELECT userID, date, transactions.name, amt, transactionTypes.transType, transactionCategories.transCat". " FROM transactions, transactionTypes, transactionCategories". " WHERE transactions.typeID = transactionTypes.typeID". " AND transactions.catID = transactionCategories.catID". " AND userID = 1"; $transactions = $this->mysql->queryGetResults($sql);//from my database class $transactions = $transactions->getResults();//gets the actual data returned from mysql_query $expenses = array(); $deposits = array(); while($row = mysql_fetch_array($transactions, MYSQL_BOTH)){ if($row['amt'] >= 0) array_push($deposits, $row); else array_push($expenses, $row); } mysql_free_result($transactions); $time_end = microtime(true); $time = $time_end - $time_start; echo "<br>Took $time to run one big query and parse with PHP"; } function testTwoQuery(){ $time_start = microtime(true); $depositsQry = "". "SELECT userID, date, transactions.name, amt, transactionTypes.transType, transactionCategories.transCat". " FROM transactions, transactionTypes, transactionCategories". " WHERE transactions.typeID = 1". " AND transactions.catID = transactionCategories.catID". " AND userID = 1"; $expensesQry = "". "SELECT userID, date, transactions.name, amt, transactionTypes.transType, transactionCategories.transCat". " FROM transactions, transactionTypes, transactionCategories". " WHERE transactions.typeID = 2". " AND transactions.catID = transactionCategories.catID". " AND userID = 1"; $deposits = $this->mysql->queryGetResults($depositsQry);//gets results $expenses = $this->mysql->queryGetResults($expensesQry);//gets results $deposits = $deposits->fetchTableAndFree();//turns results into a two-dimensional array to be passed to Template Engine and free's the results $expenses = $expenses->fetchTableAndFree();//turns results into two-dimensional array to be passed to Template Engine and free's the results $time_end = microtime(true); $time = $time_end - $time_start; echo "<br>Took $time to run two queries"; }
  16. this is my query as it stands $sql = "". "SELECT userID, date, transactions.name, amt, transactionTypes.transType, transactionCategories.transCat". " FROM transactions, transactionTypes, transactionCategories". " WHERE transactions.typeID = transactionTypes.typeID". " AND transactions.catID = transactionCategories.catID". " AND userID = 1". " LIMIT 0 , 900"; now i place this in a variable called $results; is there any way to run a php-based query on that variable and split it up? I suppose the only way I can think of is to run the array through a while loop and add the data to each respected array... like so: $result = mysql_fetch_table($results); $expenses = array(); $deposits = array(); while($row = mysql_fetch_array($result, MYSQL_BOTH)){ if($row['amt'] >= 0) array_push($deposits, $row); else array_push($expenses, $row); } so now its only a discussion of which is faster? two queries or the php parsing? i'll start a new topic for this one link to new topic: http://www.phpfreaks.com/forums/index.php/topic,189941.0.html
  17. Say you have a table filled with transactions, both deposits and withdrawals are located in the table You have to split the data into two arrays, one for deposits and one for withdrawals Which in your opinion uses less resources to execute, and runs more effeciantly. Why do you think that? Two MySQL Queries $deposits = mysql_query(SELECT * FROM transactions WHERE type="deposit"); $withdrawals = mysql_query(SELECT * FROM transactions WHERE type="withdrawal"); $deposits = fetchTable($deposits); $withdrawals = fetchTable($withdrawals); or PHP parsed $transactions = mysql_query(SELECT * FROM transactions); $transactions = fetchTable($transactions); $expenses = array(); $deposits = array(); while($row = mysql_fetch_array($transactions, MYSQL_BOTH)){ if($row['amt'] >= 0) array_push($deposits, $row); else array_push($expenses, $row); } function fetchTable($data){ $table = array(); if(mysql_num_rows($data) == 0) return $table; mysql_data_seek($data, 0); while($row = mysql_fetch_array($data, MYSQL_BOTH)){ array_push($table, $row); } return $table; }
  18. I was trying to keep from doing two separate queries. to save system resources (I'm running a Virtual Private Server and have limited RAM) As far as I know, MySQL queries take a lot more system resources than doing something in PHP correct me if Im wrong.
  19. I have a query that pulls a list of recent transactions. this is what gets pulled into $results from the query $results = id, date, amt, type 1 , blah, 25 , deposit 2 , blah, -10 , expense My question is, I know I can create one query to get just deposits and one query to get just expenses. After i get my results into the variable $results. how can i split that variable into two sets of results, based on deposits or expenses? This way I only have to make one query and save system resources. $results = mysql_query($query); $expenses = hrmmm? $deposits = hrmmm?
  20. AJAX has absolutely nothing to do with this topic. please explain why you say that? Got nothing better to do than sit around and point out everyone's mistakes instead of actually contributing?
  21. if you implement AJAX... or some way of doing it so that you dont have to reload the page, then that woudl work great. Im just a noobie myself so good luck on figureing that one out (ive yet to tread into javascript/ajax its scary)
  22. you are loading alot of unnecessary data whenever someone goes to the page. the only way I can see that this would benefit you, is if your page is controlled with AJAX Otherwise, I would put everything in their own modules and include them, that way you only display what you need when you need it.
×
×
  • 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.