1. objects, data sets, and html

    Date: 07/28/06     Keywords: html, database

    Say I have an object called ListStudents which queries a database for all known students. My first (procedural) impulse is to loop through the dataset and store each row in pre-formatted html rows. But something tells me there is a better way of handling it with OOP. Can someone help me?

    Source: http://community.livejournal.com/php/477035.html

  2. animated gifs

    Date: 07/27/06     Keywords: no keywords

    how would one go about resizing animated gifs, my current methodology

    $newimage = imagecreatefromgif($_FILES['img_file']['tmp_name']);
    imagecopyresampled($newimagebg, $newimage, 0, 0, 0, 0, $imgdimes['width'], $imgdimes['height'], $imagewidth, $imageheight);
    $newfilename = $this->settings['imgdir'] . "/" . intval($_POST['u']) . "_" . intval($this->jid) . "_" . TIMENOW . ".gif";
    imagegif($newimagebg, $newfilename);

    seems to only save the first frame, i'm not sure what i've missed?

    Source: http://community.livejournal.com/php/476309.html

  3. Regex help

    Date: 07/25/06     Keywords: no keywords

    Is there a way to check, with a regular expression, that only numerics, commas and dashes exist in a string -- and that it begins and ends with a numeric?

    I tried:

    /^[0-9\-\,]$/

    but this expression rejects strings that contain only numerics, commas and dashes ( ex: 06072501796-06072501798, 06072501799 )

    Source: http://community.livejournal.com/php/475414.html

  4. Points and coordinates and all that

    Date: 07/25/06     Keywords: php, browser

    I need a script, or the (mathematical?) insight so I can write a script, that can determine if a point is in a series of coordinates. My prime example: browsers using the tag.

    I found this script, and it works great...for convex polygons. I could, theoretically, keep using this script and just make a series of convex polygons that add up to a more complex object... but I imagine there's an easier way.

    Is there anything already written in PHP for this?

    Source: http://community.livejournal.com/php/475198.html

  5. Mail Function & HTTP Errors

    Date: 07/25/06     Keywords: php, web

    I've discovered two things about using the PHP mail function on a page where there's an HTTP Error. First, I discovered that it's not allowed. By this I mean, the mail function just refuses to work when I put it on my error handling page (the objective here is for me, the webmaster, to get an email when somebody encountered an HTTP error). Why the mail function is disabled when there's an error, I haven't the slightest clue. There's nothing about it on php.net either.

    Secondly, and more importantly, I discovered that there's a quick and easy way to overcome this quirk: simply place the mail code in another file and then include that file on your error-handling page. Works like a charm, and now I know when people are having problems with my site. For example, I discovered that bots were searching for (a non-existent) robots.txt and getting 404'd, potentially hurting my visibility to search engines, a problem I was able to quickly correct.

    (Originally posted here.)

    Source: http://community.livejournal.com/php/475121.html

  6. why isn't this unsetting?

    Date: 07/24/06     Keywords: no keywords

    echo "

    ";
    print_r($formdetails['taglist']);
    echo "
    ";

    foreach ($formdetails['taglist'] AS $k => $v)
    {
        if ($v == $tagtodelete)
        {
            echo $v . $tagtodelete;
            unset($formdetails['taglist'][$tagtodelete]);
        }
    }
    echo "

    ";
    print_r($formdetails['taglist']);
    echo "
    ";




    is giving me
    Array
    (
    [0] => admining
    [1] => amazon
    [2] => another tag
    [3] => ebs
    [4] => ex-girlfriend
    [5] => life
    [6] => meme
    [7] => music
    [8] => retest
    [9] => singledom
    [10] => test
    [11] => test again
    [12] => wishlist
    [13] => work
    )

    retestretest

    Array
    (
    [0] => admining
    [1] => amazon
    [2] => another tag
    [3] => ebs
    [4] => ex-girlfriend
    [5] => life
    [6] => meme
    [7] => music
    [8] => retest
    [9] => singledom
    [10] => test
    [11] => test again
    [12] => wishlist
    [13] => work
    )

    Source: http://community.livejournal.com/php/474762.html

  7. fopen

    Date: 07/23/06     Keywords: google

    I'm trying to use fopen but it says it can't open the file. I've tried chmoding the file and the directory it sits in. I've finger traced the heck out of my little code to find errors. I can't find anything on all of google about this sort of issue in particular (lots of others, though). Here's the code:



    Anyone have any ideas? Many thanks.

    Source: http://community.livejournal.com/php/474427.html

  8. For everyone who was interested in the CLE stuff

    Date: 07/23/06     Keywords: php

    Since I got a few interested replies on this community for the CLE stuff, here it is, the code for taking input and making use of it, either in the middle of the script, or as an option.


    Here's the on-demand input:
    function readline($prompt="") {
      print 
    $prompt$out=""$key="";
      
    $key=fread(STDIN,1);
      while (
    $key!="\n") {
        
    $out.=$key$key=fread(STDIN,1);
      }
      return 
    $out;
    }

    This code can be used in the case of, say we have an exception occur in our script, but we want to check if the user wants to retry, we can do this:
    $continue=readline("Exception has occurred! Would you like to continue? (YES/NO) ");
    Ths script will then pause and wait for input from end-user. Please beware that anytime you use readline (or whatever you rename it to), that the script halts and waits for input in the form of a newline before the function completes. I am still trying to find a way to ignore such input until it is nessicary, and so far all i've found is piggybacking scripts, one with this input code, and the other with the code we want to actively run, connected through proc_open's STDIN and STDOUT.

    And here's the code to take -switches like --help and stuff, as well as alterable=options
    array_shift($argv); $in=$argv;
    if (
    count($in)) {
      foreach (
    $in as $null => $input) {
        if (
    preg_match('/.+[=]{1}.+/',$input)) {
          
    //This is a variable, store it for later
          
    list($key,$data) = explode("=",$input);
          
    $_OPTION["$key"]=$data;
        }
        if (
    preg_match('/[-]{1,2}.+/',$input)) {
          
    //This is a switch, let's go ahead and trigger it
          
    $_SWITCH["{$input}"]=TRUE;
        }
      }
    }

    Example:
    After you've chmodded your_script to be executeable, and added the #!/path/to/php as the first line, you can use it like such.
    "./your_script -stop" will give you $_SWITCH["stop"]==TRUE, and "./your_script option1=variable1" will give $_OPTION["option1"]=="variable1", just to note, the options CAN be encapsulated with quotes to intake an entire string.
    Example: ./your_script option1="full string input can also be done"
    Returns: $_OPTION["option1"]=="full string input can also be done"


    I hope somebody can use this for their projects and make some use out of it all.

    Source: http://community.livejournal.com/php/474193.html

  9. I need a few pointers (...no, bad pun. I'm sorry.)

    Date: 07/23/06     Keywords: no keywords

    I'm almost certain that the answer to my problem can be found somewhere in the documentation, however, I can't seem to find it. In fact, the documentation is just confusing me. So I'm asking here. Can someone help?


    I've created a loop which, in theory, should cycle through each element in an array, extract a specific number of elements from a second array, then insert those elements as a new array into the current element of the first array. In other words, I'm going from this:

    $first_array[] = array();
    $first_array[] = array();
    $first_array[] = array();

    $second_array[] = "string1";
    $second_array[] = "string2";
    $second_array[] = "string3";
    $second_array[] = "string4";
    $second_array[] = "string5";
    $second_array[] = "string6";
    $second_array[] = "string7";

    ...to this:

    $first_array[] = array(string1, string2, string3);
    $first_array[] = array(string4, string5);
    $first_array[] = array(string6, string7);


    Here's the problem. I can extract the appropriate number of elements from the second array easily enough, but I can't extract the specific ones I want. The second array's internal pointer seems to be resetting itself each time the loop moves to a new element in the first array, so I end up with this:

    $first_array[] = array(string1, string2, string3);
    $first_array[] = array(string1, string2);
    $first_array[] = array(string1, string2);


    What I can't figure out is why. I'm not sure if the internal pointer is actually resetting itself on each iteration, or if it never moves in the first place. I somewhat suspect the latter, as nothing I've tried in an attempt to push it back to the appropriate key seems to work. But if it's not moving, how on earth is it fetching any elements at all? Argh, does anyone know what's going on here? Here's the actual code, if it makes things clearer:


    Note: "chapters" refers to the first array; "pages" to the second.

       $i = 0;
       $number_of_chapters = count($chapters);
    
       foreach ($pages as $key => $value)
       {
         for ($current_chapter = $i; $current_chapter < $number_of_chapters; $current_chapter++)
         {
           if ($key < $number_of_pages_in_current_chapter)
           {
             $chapters[$current_chapter][] = $value;
           }
         }
       }

    I know the documentation warns that foreach automatically resets the pointer, however using each() and list() instead made no difference. Furthermore, I can't quite see how or why it should reset after each iteration of the for loop, since that's nestled within the foreach. Foreach shouldn't reset until its *own* iteration is complete, should it?


    ...I just bet the answer to this is going to be something ridiculously simple like "you've got an extra semicolon". DAMN THOSE SEMICOLONS.

    Source: http://community.livejournal.com/php/474003.html

  10. Input variable checking

    Date: 07/22/06     Keywords: no keywords

    A question about input fields:

    Is there a way to check a $_POST[''] value to see if there are symbols in it?

    Like, say, I want it to be required that there is a @ and a . somewhere in the string to make sure that it's a proper email address.

    How would I go about doing that?

    Source: http://community.livejournal.com/php/473819.html

  11. You're never going to believe what's kicking my butt this time...

    Date: 07/21/06     Keywords: php, database, java, google

    Hello, My favorite PHPers! I come to you once again with one of the easiest things I could ever imagine you've been asked, but it just...doesn't...like...me.

    And really, I should have figured this out ages ago.

    All I need to do is verify whether a checkbox has been checked.

    I've googled it, but unfortunately everything that's popped up has been for JavaScript. Which isn't used in this project.

    The status of the checkbox (either checked or unchecked) is going into a database (They're boolean fields that just get set to 0 or 1 it looks like) for use in another part of this app that I, hopefully, won't have to write (like that'll happen).

    So here's what my conditional statement looks like:

    if ($_POST['docAction1'] == checked)
      $query .= "'1', ";
    else
      $query .= "'0', ";


    Unfortunately, where it says 'checked', I don't know what is supposed to go there. I've tried many things, like "true", "on", "checked", "1", etc etc etc. But nothing gets updated in the database. So, I come to you, humbled by the simple stuff.

    Please be kind.

    p.s. The checkbox names (docAction1) will be changed at a later date to better reflect the text that will be associated with the checkbox. Right now they're just labeled as "checkbox 1, 2, 3" etc. So hush you variable-name hounds!

    Source: http://community.livejournal.com/php/473486.html

  12. missing something stupid...

    Date: 07/21/06     Keywords: mysql, sql

    i have this function the reads a csv file (it's actually a pipe-separated file...), exported from access and dumped into mysql. after some formatting and setting things up, i start a while... loop, reading each line of the file and updating or inserting into the table as necessary. my problem is that after the while loop, the script seems to just die. everything is updated/inserted correctly, but it just stops after the loop. the "report" code never happens. the stuff that executes outside of the function after i call it never happens. can anyone see anything wrong with this? i can post the entire function if you'd like.



    Source: http://community.livejournal.com/php/473329.html

  13. error in PHP & MySQL in a loop

    Date: 07/21/06     Keywords: php, mysql, html, database, sql

    The following has been providing a bit of a problem for me over the past few days. I have an initial display page with the HTML form and text fields, however the number of text fields can be controlled by the user. As such they are all placed into an array within the $_POST array, to be retrieved later. I've tried doing this, and this alone works fine. The problem is when I try to loop through them to insert them into the database, for some reason while they will display through echo fine, only the first one will insert into the database, then throw an error. Below is a loose sample of the code.

    The text fields in the HTML file are named as follows : $name[]

    The code in the PHP file is as follows, excluding anything not necessary for the example :




    $conn = db_connect(); // establishes a database connection
    if (!conn)
    {
    echo "database error";
    exit;
    }

    $i = 0;

    while(isset($_POST['name'][$i])){

    $name[] = $_POST['name'][$i];

    $i++;
    }

    $i = 0;

    foreach($name as $name_current){

    echo $name[$i];

    echo $name_current;

    $query = mysql_query("insert into names values ('$other_variable','$other_variable2', '$name_current', '', '', '')");

    $i++;

    if(!$query){
    echo "Database Error";
    exit;
    }else{
    echo "Name added successfully!";
    }
    }



    if anyone can spot something I'm overlooking please let me know, I'm still at a loss for why it will only insert into the query on the first pass through the loop, however if I'm just echoing the values it will work fine.

    Thanks,
    Exeyel

    Source: http://community.livejournal.com/php/472928.html

  14. Dear PHP Community

    Date: 07/21/06     Keywords: php

    Dear PHP Community:

    You made this possible.  Thank you very much.

    Sincerely, Mirth

    Source: http://community.livejournal.com/php/472801.html

  15. J'ai une question.

    Date: 07/20/06     Keywords: mysql, sql

    I have a question.

    If I have a user enter their email at a login screen with their email and password, the following should work to match the password with the e-mail, correct?

    $ema = $_POST['ema'];
    $pw = mysql_query("SELECT password FROM users WHERE email = '$ema'");

    I mean, it's only logical.  It's not just me, is it?  I swear, I'm going crazy trying to figure out why this isn't working.

    I'm getting results like Resource id#3 and Resource id#4 instead of the fields that should be called when I used those commands.

    Any ideas?

    Source: http://community.livejournal.com/php/472517.html

  16. Picture of the Day script

    Date: 07/19/06     Keywords: php

    Hey,

    I've wrote the Picture of the Day script.
    I'm looking forward for your opinion of what should be improved there.

    It's free: http://usefulclasses.com/index.php?prc=readArticle&aid=potd

    With best regards,
    Eugene

    Source: http://community.livejournal.com/php/472021.html

  17. Just saying thanks.

    Date: 07/18/06     Keywords: php

    I just want to thank you guys for those tips.

    What I did instead of search for sites that gave me line-by-line explanations, I figured out what I wanted to do and found the appropriate commands and related tutorials and did them.

    So, I owe the creation of this homemade guestbook made from scratch to you guys.

    I am now much more interested in PHP now that I have an alternate learning method!

    I'll probably post here if I have any major problems.

    Actually, I DO have a problem now!

    Files are Pastebin'd here:

    I'm trying to make Sex work, here.  Everything else works flawless.

    Here's what I have set up:

    Two radio buttons, both with the name 'sex.'

    The Male button has the value 'Male' and the Female, 'Female.'

    On the register.php you'll see the following:

    $sex = $_GET["sex"];

    if ($sex = 'Male') {
        $s = 1;
    }
    if ($sex = 'Female') {
        $s = 2;
    }

    Which should, logically, work.

    So what's the problem?

    Oh, in index.php I have this:

    if ($row['sex'] = 1) {
        $sex = 'Male';
    }

    if ($row['sex'] = 2) {
        $sex = 'Female';
    }

    What the hell was I doing?  Nevermind, haha.  Wow, I'm stupid.

    Source: http://community.livejournal.com/php/471617.html

  18. Address Bar Masking?

    Date: 07/17/06     Keywords: php

    I want to host my wife's domain on my server account, but I don't want the exposed address to say www.myaccount.com/herSite.php. It would be much better if the address said www.herSite.com.

    I can set up the domain forwarding with the registrar, no problem, but is there any way to change what users see in the Address Bar?

    Thanks.

    Source: http://community.livejournal.com/php/471065.html

  19. Tutorial Sites

    Date: 07/15/06     Keywords: php

    I've been putting off learning PHP for quite some time now.  Occasionally, I'll get a random hair in my ass and decide to start learning, searching places like Digg and PHP.net for tutorials and such, but I've never found a site that explains simple code line by line, explaining each command and why certain things are in the order they're in.  I know it's a specific want, but for whatever reason I feel I simply can't learn well without that kind of site.  I bought the O'Reilly book on PHP, and that didn't help much because they'd give you the code but they wouldn't entirely explain it.  And if they did, it would always be in a very large, very intimidating block of text (not to say I'm not a good reader, it's just that things like that tend to turn me off of learning.)

    So I was wondering:

    What are some places that explain code line-by-line or at least do a better job of teaching PHP?

    Thanks in advance,
    Darby.

    Source: http://community.livejournal.com/php/470776.html

  20. register_globals=off

    Date: 07/15/06     Keywords: php

    I'm aware that register_globals=off at the ISP problem will not let me use $PHP_AUTH_USER which is dangerous anyway. I think I got around it by the first two lines in my code below, but I just keep failing authentication. This use to work on my old server. Any ideas?

    Source: http://community.livejournal.com/php/470277.html

Previous page  ||  Next page


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home