Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: $ Sign Decode

  1. #11
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I agree, and I'd like to know what is to be accomplished to see if there's a better workaround.


    Just a random note-- to set a variably-named variable, use this:

    $name = 'myvarname';
    $$name = 'myvarvalue';
    echo $myvarname;
    //returns 'myvarvalue'

    (The $$ must be used, not $some$thing, or you'll get errors.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #12
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Variable variables are almost as ugly as eval(). An associative array would be preferable by far.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #13
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by Twey View Post
    I must say that, as is usual with eval(), there's probably a better way to accomplish whatever it is you're trying to do.
    I have come across a situation in PHP that required code to be generated. I maintain an extension for a CMS that will show the user a screen to help them change values in a config file. As with a lot of PHP programs the config file was written in PHP. So it was necessary to generate PHP code.

  4. #14
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Okay, I'll explain my situation, but it's a long one.
    Every time I delete a user off my MySql db via admin control panel, the ID auto_increment would skip.
    Example if I had users
    1
    2
    3
    4
    5
    6
    7
    and decided to delete 6, the next user's id would be added as "8" and not "7". So I gather the current db content, convert to a php script, write it to a file and run the file. I first DROP TABLE users, then reset all the content. It works well now though, so I guess the discussion doesn't really need to be carried on any more. I hope this expains my situation more.
    - Mike

  5. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm not clear on why you would need to use anything this complex.

    Just run through each result of the query for SELECT * FROM.... ORDER BY ID
    Then with each set the number to $n, then $n++;
    ...you're done.

    I also would be quite wary of a script that actually deletes the entire user list, only to replace it a minute later. What if the page gets corrupted while loading? Oops...?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #16
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Easier still, you can just drop the column then add it again.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #17
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm... but you would you be able to force order by to the original order? Maybe this would be the default. That's the only catch I see there.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #18
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The order is preserved even without a primary key. That's the nature of MySQL (and, indeed, most relational databases).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •