Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts

    help with too many IF statements

    hello all,

    I have about 100 line blocks of code that look like this:
    PHP Code:
    elseif (substr($array[$i], 0strpos($array[$i], ",")) == "12.71.118.66") {
         echo 
    '<td style="cursor:pointer; text-align:center; color:#0000FF">
                 <center><strong><u><a onclick=MM_openBrWindow
                 ("http://www.hhsd.org/","","toolbar=yes,location=yes,
                 status=yes,menubar=yes,scrollbars=yes,resizable=yes,
                 width=2000,height=2000")>http://www.hhsd.org/</center></strong></u></a></td>'
    ; } 
    i have an array of concatenated fields imported into DW from Access, and I'm making a bunch of tables from each one.

    the tables list visits to my website. the above code is checking for the part of the strings that's the visitor's name and matching the IP address to it, and then writing a hyperlink above the table's beginning. I have about 115 of these if statements. is there anyway I can consolidate these things?

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Well for one thing, repeating the substr and strpos functions for each evaluation is incredibly wasteful. Do it once, store the result in a variable and compare against the new variable.

    Secondly, you don't say what the difference is between the IPs, like what do you print out differently for each one?
    OracleGuy

  • #3
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by oracleguy View Post
    Well for one thing, repeating the substr and strpos functions for each evaluation is incredibly wasteful. Do it once, store the result in a variable and compare against the new variable.

    Secondly, you don't say what the difference is between the IPs, like what do you print out differently for each one?
    the only that's different is the website address and the display text that you can both find inside the MM_openBrWindow() function. I don't I can change that function, and I will also change the str() functions to a single variable now. I didn't notice that, thanks.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Is the URL for a given IP address in your Access database already?
    OracleGuy

  • #5
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by oracleguy View Post
    Is the URL for a given IP address in your Access database already?
    yes, but I need it for my online report, which I why I transfer it to DW this way.

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    PHP should be able to access your Access database via ODBC, you could just have it pull from it directly. (Assuming your web host is on Windows otherwise you'd have to import the data into a different DB)
    OracleGuy

  • #7
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by oracleguy View Post
    PHP should be able to access your Access database via ODBC, you could just have it pull from it directly. (Assuming your web host is on Windows otherwise you'd have to import the data into a different DB)
    thank you oracle. i appreciate it. i'll have to try something else, as I have no experience with ODBC. it would be a huge learning curve for me to start now.


  •  

    Posting Permissions

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