Redapple Posted January 30, 2009 Share Posted January 30, 2009 Hello everybody, I have an problem debugging a script I made. I will explain what this script does and what its used for and hopefully someone can help me fix my problem. I have a database table and in that table there is a row that is named login_ip. Quick example of the current table name login_ip example1 127.0.0.1-172.20.35.1 example2 127.0.0.1-172.20.35.1 example4 172.20.35.55 Now user `example1` is logged in on the website and wants to see on what IP's he have been logged in, So this script I made should display that but it is not working like it should be, It does not display all the names that matches but only example2 in the list if example1 is logged in. You get what I want? The problem is that I want to let explode fetch all the names matching the IP's but I think it does not search all names because now it does only search if the first ip is the same as the currently of `example1` but I want to olso show `example2` in the list. $sql = "SELECT login_ip FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; $query = mysql_query($sql); $row = mysql_fetch_object($query); $login_ip = explode("-", "$row->login_ip"); foreach($login_ip as $name_array) { $sql = "SELECT * FROM users WHERE login_ip='$name_array'"; $query = mysql_query($sql); while($row = mysql_fetch_array( $query )) { $usedname = $row['name']; echo " <tr>\n"; echo " <td bgcolor=\"#000033\"><font color=\"#999999\"><div align=\"center\"><a href=\"/viewprofile.php?user=$usedname\">$usedname</a></div></td>\n"; echo " </tr>\n"; } } Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 31, 2009 Share Posted January 31, 2009 That's what you get when you have flawed database design. Don't store several IPs in one field. Quote Link to comment 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.