dlf1987 Posted May 29, 2007 Share Posted May 29, 2007 trying to create mysql array... i commented right where the problem is <?php mysql_select_db($database_pixeldecal, $pixeldecal); $query_rsIP = "SELECT * FROM settings"; $rsIP = mysql_query($query_rsIP, $pixeldecal) or die(mysql_error()); $row_rsIP = mysql_fetch_assoc($rsIP); $totalRows_rsIP = mysql_num_rows($rsIP); do { $blockips .= '"'.$row_rsIP['settings_value'].'", '; } while ($row_rsIP = mysql_fetch_assoc($rsIP)); $blockips=substr($blockips,0,-2); if ($blockips == '') $blockips = 0; // STUCK RIGHT HERE // TRYING TO FIGURE OUT HOW TO ADD VALUES TO THE ARRAY BELOW // HERES WHAT THE ABOVE MYSQL QUERY CREATES - "74.240.1.000", "74.120.113.00" // BUT THAT DOESNT WORK // IF I COPY AND PASTE THOSE VALUES STRAIGHT INTO THE ARRAY BELOW IT WORKS FINE THOUGH $include = array($blockips); if (in_array($_SERVER['REMOTE_ADDR'], $include) == false) { echo $blockips; // Crazy Egg echo ' <script type="text/javascript" src="https://cetrk.com/pages/scripts/0000/XXXX.js"></script> '; // Google Analytics echo ' <script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script> <script type="text/javascript"> _uacct = "UA-XXXXX-2"; urchinTracker(); </script> '; } mysql_free_result($rsIP); ?> Thanks, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/ Share on other sites More sharing options...
DanDaBeginner Posted May 29, 2007 Share Posted May 29, 2007 you can use array map to substring all the elements in your $blockips.. $blockips= array_map(functionSubstring,$blockips); then $include = $blockips; //remove the array because its already array... Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263702 Share on other sites More sharing options...
dlf1987 Posted May 29, 2007 Author Share Posted May 29, 2007 what should "functionSubstring" be replaced with? doesnt the array not work because of the way php parses the info into the array? Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263705 Share on other sites More sharing options...
DanDaBeginner Posted May 29, 2007 Share Posted May 29, 2007 try to echo this: $blockips=substr($blockips,0,-2) and it will give you an answer to your question... create a function that will substring: try this: function Substring($element) { return(substr($element,0,-2)) } Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263711 Share on other sites More sharing options...
dlf1987 Posted May 29, 2007 Author Share Posted May 29, 2007 ummmm i think theres a misunderstanding... forget the example i gave you.... try this im not having trouble with the substr, its the values that im putting into the array, thats not working... this works <?php $include = array("74.000.1.168", "74.000.113.72"); if (in_array($_SERVER['REMOTE_ADDR'], $include) == true) { echo ""; } ?> but this doesnt <?php $blockips = '"74.000.1.168", "74.000.113.72"'; $include = array($blockips); if (in_array($_SERVER['REMOTE_ADDR'], $include) == true) { echo ""; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263718 Share on other sites More sharing options...
DanDaBeginner Posted May 29, 2007 Share Posted May 29, 2007 you can use implode... put a delimeter , maybe a comma $blockips = "74.000.1.168,74.000.113.72"; $include = implode(",",$blockips ); Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263724 Share on other sites More sharing options...
dlf1987 Posted May 29, 2007 Author Share Posted May 29, 2007 thats still not what im looking for I'm trying to hide my website stats scripts based on the ip's i have listed in my mysql database... is there another way of doing this? another words... if your ip matches the mysql query ip, don't echo stat scripts... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263857 Share on other sites More sharing options...
taith Posted May 29, 2007 Share Posted May 29, 2007 its MUCH easier to let mysql handle blocked ip's... <?php $query=mysql_query("SELECT * FROM `banned` WHERE `ip`='$_SERVER['REMOTE_ADDR']' LIMIT 1"); if(mysql_num_rows($query)>0) die("you've been banned... GO AWAY! lol"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263863 Share on other sites More sharing options...
dlf1987 Posted May 29, 2007 Author Share Posted May 29, 2007 well the thing is, i'm not trying to ban those ip's. Its my work ip, home ip, and a couple of others ip's that i don't want to be included in my sites statistics. another words if i go to my site, i don't want my google Analytics, and crazy egg scripts to show... hope that makes sense... sorry Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263866 Share on other sites More sharing options...
taith Posted May 29, 2007 Share Posted May 29, 2007 perfect sense... but still a similar fix... lol <?php $query=mysql_query("SELECT * FROM `banned` WHERE `ip`='$_SERVER['REMOTE_ADDR']' LIMIT 1"); if(mysql_num_rows($query)==0){ echo '<script type="text/javascript" src="https://cetrk.com/pages/scripts/0000/XXXX.js"></script>'; echo '<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script> <script type="text/javascript">_uacct = "UA-XXXXX-2";urchinTracker();</script>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53360-solved-php-mysql-array/#findComment-263868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.