SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Some Crappy Code

    Please help, i need to know an efficient way of doing what the code below does. The SQL statment selects a URL which looks like this:
    Code:
    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1
    Then it breaks it up according to the variables. These will control the color of my site if there logged in, else it will use the defaults. Can somehow show me a more efficient way, as this will need to be required on everypage of my site.

    PHP Code:
    <?php

    session_start
    ();
    $_SESSION['uid'] = $uid;
    $gamertag "$uid";

    $linkID5 = @mysql_connect("localhost""buckboa_xbl""xbl");

    mysql_select_db("buckboa_xbl"$linkID5);

    $sql3 "SELECT emblem FROM stat_users WHERE gamertag = '$gamertag'";
    $result3 mysql_query($sql3) or die(mysql_error());
    $isgamertag mysql_num_rows($result3);

    mysql_close($linkID5); 

    if(
    $isgamertag 1)
        {
        
    $primarybg '78070B';
        
    $secondarybg '7F7F7F';
        }
        else
        {
        if(
    $_GET['0']; == 0)
            {
            
    $primarybg 'FFFFFF';
            }
        if(
    $_GET['0']; == 1)
            {
            
    $primarybg '545454';
            }
        if(
    $_GET['0']; == 2)
            {
            
    $primarybg 'B82E2B';
            }
        if(
    $_GET['0']; == 3)
            {
            
    $primarybg 'EE7D1C';
            }
        if(
    $_GET['0']; == 4)
            {
            
    $primarybg 'F2D32C';
            }
        if(
    $_GET['0']; == 5)
            {
            
    $primarybg '9FA959';
            }
        if(
    $_GET['0']; == 6)
            {
            
    $primarybg '258F2C';
            }
        if(
    $_GET['0']; == 7)
            {
            
    $primarybg '265545';
            }
        if(
    $_GET['0']; == 8)
            {
            
    $primarybg '1C9DA1';
            }
        if(
    $_GET['0']; == 9)
            {
            
    $primarybg '38717B';
            }
        if(
    $_GET['0']; == 10)
            {
            
    $primarybg '226EB3';
            }
        if(
    $_GET['0']; == 11)
            {
            
    $primarybg '2B439C';
            }
        if(
    $_GET['0']; == 12)
            {
            
    $primarybg '6B4FB5';
            }
        if(
    $_GET['0']; == 13)
            {
            
    $primarybg '962588';
            }
        if(
    $_GET['0']; == 14)
            {
            
    $primarybg 'F59DC8';
            }
        if(
    $_GET['0']; == 15)
            {
            
    $primarybg '941245';
            }
        if(
    $_GET['0']; == 16)
            {
            
    $primarybg '744A29';
            }
        if(
    $_GET['0']; == 17)
            {
            
    $primarybg 'AE9155';
            }
        if(
    $_GET['1']; == 0)
            {
            
    $secondarybg 'FFFFFF';
            }
        if(
    $_GET['1']; == 1)
            {
            
    $secondarybg '545454';
            }
        if(
    $_GET['1']; == 2)
            {
            
    $secondarybg 'B82E2B';
            }
        if(
    $_GET['1']; == 3)
            {
            
    $secondarybg 'EE7D1C';
            }
        if(
    $_GET['1']; == 4)
            {
            
    $secondarybg 'F2D32C';
            }
        if(
    $_GET['1']; == 5)
            {
            
    $secondarybg '9FA959';
            }
        if(
    $_GET['1']; == 6)
            {
            
    $secondarybg '258F2C';
            }
        if(
    $_GET['1']; == 7)
            {
            
    $secondarybg '265545';
            }
        if(
    $_GET['1']; == 8)
            {
            
    $secondarybg '1C9DA1';
            }
        if(
    $_GET['1']; == 9)
            {
            
    $secondarybg '38717B';
            }
        if(
    $_GET['1']; == 10)
            {
            
    $secondarybg '226EB3';
            }
        if(
    $_GET['1']; == 11)
            {
            
    $secondarybg '2B439C';
            }
        if(
    $_GET['1']; == 12)
            {
            
    $secondarybg '6B4FB5';
            }
        if(
    $_GET['1']; == 13)
            {
            
    $secondarybg '962588';
            }
        if(
    $_GET['1']; == 14)
            {
            
    $secondarybg 'F59DC8';
            }
        if(
    $_GET['1']; == 15)
            {
            
    $secondarybg '941245';
            }
        if(
    $_GET['1']; == 16)
            {
            
    $secondarybg '744A29';
            }
        if(
    $_GET['1']; == 17)
            {
            
    $secondarybg 'AE9155';
            }

        }
        
    ?>
    BKerr

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Try this:

    PHP Code:
     <?php
     
     $colors 
    $_GET['c']; // Make sure you use commas in the url. mysite.com?c=1,2,3
     
    $colors = (explode (",",$colors));
     
     foreach (
    $colors as $key => $value){
         switch(
    $value){
             case 
    1$colors[$key] = "FFFFFF"; break;
             case 
    2$colors[$key] = "545454"; break;
             case 
    3$colors[$key] = "B82E2B"; break;
             
    // ETC.
         
    }
     }
     
     
    $primarybg $colors[0];
     
    $secondarybg $colors[1];
     
    $thirdbg $colors[2];
     
     echo 
    $primarybg.'<br />';
     echo 
    $secondarybg.'<br />';
     echo 
    $thirdbg.'<br />';
     
    ?>
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Url looks like this and cannot be changed:

    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1
    BKerr

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put the primary and seconary bg's as arrays
    PHP Code:
    $pbg_arr = array('FFFFFF','545454''etc.','etc.'); 
    and then call them like this:

    PHP Code:
    $primarybg $pbg_arr[$_GET['0']]; 

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How could i get the variables from the url drawn from the database:

    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1

    Those variables are what needs to control it.
    BKerr

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What?

  7. #7
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im storing URLs in the database, the SQL selects the URL FROM the database, the URL looks like this:

    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1

    Im trying to get the variables from THAT url thats selected from the SQL Statement, not the one in the actual toolbar.
    BKerr

  8. #8
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     <?php
      $var 
    'halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1';
      
    $variables parse_str(str_replace('?'strstr($var'?')));
      
    print_r($variables);
      
    ?>

  9. #9
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would i use that code?
    BKerr

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How fluently do you know PHP? Look up the parse_str, str_replace, and strstr functions in the PHP manual. Oh, and print_r. If you still aren't sure after that, I'll help you, but you won't learn from being spoonfed!

  11. #11
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I looked at the Manual, and according to that, it grabs everything after a certain character specified.

    Im just trying to grab the two higlighted numbers:
    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1
    BKerr

  12. #12
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Is it something you could use ?
    PHP Code:
    $txt='halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1';

    $splits preg_split('/\?|&|=/'$txt);
    echo 
    "URL:{$splits[0]}\n";
    for (
    $i=1$i count($splits); $i +=2) {
        echo 
    "sym {$splits[$i]} is {$splits[$i+1]}\n";

    +
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  13. #13
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BKerr
    I looked at the Manual, and according to that, it grabs everything after a certain character specified.

    Im just trying to grab the two higlighted numbers:
    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1
    PHP Code:
    $var 'halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1';
     
    $variables parse_str(str_replace('?'strstr($var'?')));
     
    $zero $variables[0];
     
    $one $variables[1]; 
    Then $zero = 16, and $one = 11.

  14. #14
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, OK then:
    PHP Code:
    $txt='halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1';

    $splits preg_split('/\?|&|=/'$txt);
    echo 
    "URL:{$splits[0]}\n";
    for (
    $i=1$i count($splits); $i +=2) {
        
    $sym[$splits[$i]] = $splits[$i+1];
    }
    echo 
    "You have {$sym['0']} and {$sym['1']}\n"
    +
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  15. #15
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yooo...is der any ader function except for mail() that send email-add?
    please help!!! tnx..

  16. #16
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He jeolou,
    is it you Some Crappy Coded ?
    What you mean here in this Somehow Crappy Code ?
    +
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  17. #17
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look, if your URLs look like this:
    HTML Code:
    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1
    and you're therefore interested in this:
    PHP Code:
    $_GET['0'], $_GET['1'
    then what don't you understand?
    PHP Code:
     $primary_bg_arr = array('FFFFFF','545454''etc.','etc.'); 
     
    $secondary_bg_arr = array('FFFFFF','545454''etc.','etc.'); 
     
    $primarybg =$primary_bg_arr[$_GET['0']]; 
     
    $secondarybg $secondary_bg_arr[$_GET['1']]; 

  18. #18
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=HardCoded]Look, if your URLs look like this:
    HTML Code:
    halo2emblem.ashx?s=90&0=16&1=11&2=0&3=4&f=9&b=5&fl=1
    Not 100% sure, but I think he said that that string is in the DB, not the requested URL on his site.

  19. #19
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh! I see it now.


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
  •