...

View Full Version : help with too many IF statements



ajetrumpet
10-23-2009, 07:53 PM
hello all,

I have about 100 line blocks of code that look like this:
elseif (substr($array[$i], 0, strpos($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?

oracleguy
10-23-2009, 09:10 PM
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?

ajetrumpet
10-23-2009, 09:22 PM
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.

oracleguy
10-23-2009, 09:24 PM
Is the URL for a given IP address in your Access database already?

ajetrumpet
10-23-2009, 09:27 PM
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.

oracleguy
10-23-2009, 09:50 PM
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)

ajetrumpet
10-23-2009, 09:53 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum