Jump to content

[!!!] This stupid bug is driving me crazy....


phpakos

Recommended Posts

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..

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

....

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.