phpakos Posted June 30, 2007 Share Posted June 30, 2007 i have setup a database with this table structure: $query = "CREATE TABLE entry ( entryID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID), URL varchar(4096), name varchar(1024), kw tinytext )"; I have filled in the database with data: entryID 1 URL http://www.bmwdealer.info/kwngat/9 Hite 6 Princesh... name 02-Poni - Thashethemet-9 Hite 6 Princesha kw 9 (data copied from a sample row from phpmyAdmin). Now this is my code: $term = '1'; $term2 = '9'; $query = "SELECT * FROM entry WHERE entryID = '$term' AND kw='$term2' "; $result = mysql_query($query); $numresults = mysql_num_rows($result); echo $numresults."<br>"; if(!$result) { die('Invalid query: ' . mysql_error()); } else { //something was found.. while($row = mysql_fetch_array($result)) { echo "-Entry-<br>"; echo $row['entryID']."<br>"; echo $row['URL']."<br>"; echo $row['name']."<br>"; echo $row['kw']."<br>"; } }; THIS CODE DOESNT GIVE ANY RESULTS AND THE PROBLEM APPEARS TO BE THE: AND kw='$term2' part of the QUERY because if i remove it, it DOES produce the expected result. Any idea what is going on? Why is it not matching the kw field? Please help me out with this thanks alot, in advance.. Quote Link to comment https://forums.phpfreaks.com/topic/57845-this-stupid-bug-is-driving-me-crazy/ Share on other sites More sharing options...
phpakos Posted June 30, 2007 Author Share Posted June 30, 2007 The problem appears to be that i am loading the database info from a text file and it appears that at the end of each word there is a type of delimiter.... A new line character maybe? What's the best solution for those cases? Thanks alot! Quote Link to comment https://forums.phpfreaks.com/topic/57845-this-stupid-bug-is-driving-me-crazy/#findComment-286653 Share on other sites More sharing options...
wildteen88 Posted June 30, 2007 Share Posted June 30, 2007 Does the kw column only contain numbers? If it does then there is not much point in setting it to TINYTXT data type Instead you should set it to INT or TINYINT Quote Link to comment https://forums.phpfreaks.com/topic/57845-this-stupid-bug-is-driving-me-crazy/#findComment-286662 Share on other sites More sharing options...
phpakos Posted June 30, 2007 Author Share Posted June 30, 2007 wildteen: it also contains text... it can be whatever... i used this code: $b = fgets($fh); $a = substr($b,0,-1); the second line removes the character which was causing the bug.. any idea what that character is? I tried removing specifically the newline character but that wouldnt work.. so i figured it is another type of character... the $b variable is loaded from a file of this format: ... 7 9 Hite 6 Princesha .... Quote Link to comment https://forums.phpfreaks.com/topic/57845-this-stupid-bug-is-driving-me-crazy/#findComment-286668 Share on other sites More sharing options...
wildteen88 Posted June 30, 2007 Share Posted June 30, 2007 You should use trim which will remove whitespace characters at the beginning and end of a string. Depending on the OS the file was created on it could have \r\n or \n or \r whitespace characters for newlines using trim removes all possibilities giving you clean string/line Quote Link to comment https://forums.phpfreaks.com/topic/57845-this-stupid-bug-is-driving-me-crazy/#findComment-286798 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.