Jump to content

awpti

Members
  • Posts

    459
  • Joined

  • Last visited

    Never

Everything posted by awpti

  1. This is where you're going to have to buckle down and read the PHP Manual. www.php.net/mysql That should cover most of your needs, including how to get information out of a DB.
  2. Yeah, most are setup to only listen on the local loopback device. I could give you my DB user and pass.. you'll never touch it no matter how hard you try - just because it only listens on 127.0.0.1
  3. <?php $hostname="xxxxx"; $mysql_login="xxxx"; $mysql_password="xxxx"; $database="xxxx"; $db = mysql_connect($hostname, $mysql_login , $mysql_password) or die(mysql_error()); //mysql_pconnect is BAD. if (!$db) { //Oh noes! It be brokeded! } else { echo 'connected'; // select a database mysql_select_db($db) or die(mysql_error()); } ?>
  4. What game is this for? I may already have something built /nearly complete that I could swing your way. It's ugly as sin, though.
  5. Is if (mysql_num_rows($result) == 1) { actually evaluating as expected?
  6. Important info we need to know; What OS? Are you using one of the the many AMP's out there? (XAMPP, WAMP, etc) Are you using IIS w/ PHP? This will help in diagnosing what the problem is/getting to the bottom of it.
  7. Since the timelimit for edits expired while i was editing.. You weren't pulling rows from the DB, which is where the mysql_fetch_assoc comes in. another note; Store the userlevel in the session and just check against that instead of assigning TRUE to different SESSION vars. The more levels of access you have, the messier that conditional is going to get. if($_SESSION['user_level'] === 4) // User is siteadmin { //...display the page } else { //... kick 'em out. }
  8. $sql = "SELECT user_id, user_level FROM users WHERE user_id = '$userId' AND user_password = PASSWORD('$password')"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); $row = mysql_fetch_assoc($result); if (mysql_num_rows($result) == 1) { $user_level = $row['user_level']; //.........rest of script
  9. Using functions in a for() loop is a very very very very common mistake. I'm still guilty of doing it sometimes, just because it's an old habit that I'm trying to break. And definately, give good code examples. My code examples isn't tested, but i'm reasonably sure it'll work (the concept is correct, the execution may not be completely - YMMV!)
  10. <a href="<?php echo $ps->organize_url(); ?>" target="_bank">Link</a> That's it.
  11. Hey, dude. Here's what you can do to fake having a domain (for your own testing): In Windows: Start->Run In the dialog, just paste this: notepad c:\windows\system32\drivers\etc\hosts The file should look similar to.. # Copyright (c) 1993-1999 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host 127.0.0.1 localhost Modify the line thusly; 127.0.0.1 localhost www.domain.com domain.com ex: 127.0.0.1 localhost www.awpti.org awpti.org
  12. If a result is empty, echo out You'll have to do some conditionals
  13. Slight performance improvement: for($x = 0, $array_a_count = count($array_a); $x < $array_a_count; ++$x){ for($y = 0, $array_b_count = count($array_b); $y < $array_b_count < $y; ++$y)){ // compare if($array_a[$x][$y] === $array_b[$x][$y]) { //do something } } } This will stop it from running count() on each loop. You could also just do this: $array_a_count = count($array_a); $array_b_count = count($array_b); for($x = 0; $x < $array_a_count; ++$x){ for($y = 0; $y < $array_b_count < $y; ++$y)){ // compare if($array_a[$x][$y] === $array_b[$x][$y]) { //do something } } }
  14. There can be no field named * nor is there an _POST var called *. Methinks an SQL refresher is due $query= "select * from dealerlocater where * '" . $_POST['*'] . "'"; // Should be.. $state = mysql_real_escape_string($_POST['state']); $query= "select * from dealerlocater where my_field_name = '{$state}'";
  15. Except he's looking for how to create a logging system, not a login system. Really, it's not terribly difficult. You can either fire stuff out to a flat text file or store it in a DB. Figure out what information you need to store and create a function: _system_logger('alert_level', 'action_taken', 'by_user'); ex; function _system_logger($level = 'NOTICE', $action, $user) { $action_insert = array('level' => $level, 'action' => $action, 'user' => $user); $this->db->insert('system_logger', $action_insert); } Private function, only you will ever call it.. My above example relies on the ActiveRecord library included with CodeIgniter, but it gives you the idea of how it works. Just make a function that either does a fwrite() or mysql_query('insert into...');
  16. Notice the forum: PHP Freaks Forums > PHP and MySQL > PHP Help > See that MySQL part? In any case.. Read the mySQL documentation. Look up tutorials on MySQL Performance tuning.
  17. Actual cron would be: */10 * * * * /my/command 10 * * * * just runs it on the 10th minute of every hour. 1:10.. 2:10 3:10 4:10
  18. Please be very careful using the script thorpe suggested. This opens you to file-inclusion attacks. Here's how I handled the same thing before moving to a template system: <?php $allowed_pages = array('page1', 'page2', 'page3', 'page4'); //you'll have to add to this for every new page $page = $_REQUEST['page']; if(in_array($page, $allowed_pages)) { include($page'.page'); } else { include('page1.php'); //or some error page. whatever. } ?>
  19. Bit of a hack using SQL.. SELECT ..... WHERE image_id >= $current_image_id LIMIT 2 ORDER BY image_id ASC That'll get the current ID + next one. No the prettiest way to do it. Easiest though.
  20. awpti

    "<<<" in php

    Seems like everyone is getting different results. At the console (php test.php) HEREDOC: Total: 0.28366875648499 Average: 2.8366875648499E-5 echo: Total: 0.22118401527405 Average: 2.2118401527405E-5 Via apache (2.2.6 w/ php 5.2.5): HEREDOC: Total: 0.28366875648499 Average: 2.8366875648499E-5 echo: Total: 0.22118401527405 Average: 2.2118401527405E-5 ???
  21. awpti

    "<<<" in php

    I shrunk the string, now they're both about the same. I didn't think about it earlier, but these results may be poisoned by the fact my hosting server is a Virtual instance among a few others. They both swing pretty big in the results - ranging from 0.3x to 0.9x+ I'll actually be shifting off to a dedicated server soon - be able to do a more reliable test then. As far as the difference being minor? Any savings is a saving. I'll also assume you ment 4 hundredths and not 4 tenths. 4 tenths would be a significant savings (and an odd result ). It may be a -slight- exaggeration to say 'very' on short HEREDOC's.. start pumping out serious content w/ variables using HEREDOC and you'll feel the hurt when the site gets active. I had to deal with a site that did such a thing and it was AWFUL. The performance was horrible and the memory usage difference was visible (still insignificant compared to the processing time). Every page was, pretty much, a HEREDOC with about 30-40 variables being dumped to it, with breaks out of the HEREDOC to take care of 'for' loops. Start running load tests. You'll see load times/processing times increase exponentially. Every little tweak matters when your site is live and high-traffic. That .04 can be the difference between crushing your server's CPU or not during a spike.
  22. awpti

    "<<<" in php

    They are more intensive for PHP to parse than single or double-quoted strings, resulting in slower code execution and increased memory usage (memory usage part isn't always noticable). http://www.awpti.org/test_heredoc/ - >Result: ~0.178 -> 0.233 http://www.awpti.org/test_heredoc/double_quote/ - >Result: ~ 0.133 -> 0.145 Take into consideration that this test was built using the CodeIgniter Benchmark class/Framework. The actual times on this will be lower, but double_quote is still faster. Load the page and scroll to the bottom. And the code.. <?php class Test_heredoc extends Controller { function Test_heredoc() { parent::Controller(); } function index() { $this->benchmark->mark('code_start'); $tests = 10000; for($i=0;$i<$tests;++$i) { $string = 'blah-'.$i; echo <<<EOF This is a test $string. This should run 10000 times.<br /> EOF; } $this->benchmark->mark('code_end'); echo 'Time taken: '.$this->benchmark->elapsed_time('code_start', 'code_end').'<br />'; $this->view->load('test/mem'); } function double_quote() { $this->benchmark->mark('code_start'); $tests = 10000; for($i=0;$i<$tests;++$i) { $string = 'blah-'.$i; echo "This is a string with $string in it.<br />"; } $this->benchmark->mark('code_end'); echo 'Time taken: '.$this->benchmark->elapsed_time('code_start', 'code_end').'<br />'; $this->view->load('test/mem'); } } ?> In retrospect, I should have named this test_perf
  23. PHP use a ton of memory during image manipulation. 1 of 2 things: increase the memory_limit (128M+) or start using ImageMagick Easiest solution is to crank the memory_limit up in php.ini
  24. awpti

    "<<<" in php

    NOTE: HEREDOC is very inefficient. Avoid using it.
  25. elseif(isset($show) && $show="all"){ Change to.. elseif(isset($show) && $show === "all"){
×
×
  • 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.