Forum Moderators: coopster

Message Too Old, No Replies

Finding '\n' characters in a mysql_query

It is killing me...

         

grnidone

11:34 pm on Jan 9, 2004 (gmt 0)



All I want to do is find all the items in a database that
begin with any number of characters of any kind
followed by a ':'
followed by a next line character (/n)

So I did this:

select * from table where column_name regexp '^.*:\\n'

This works beautifully if I type it directly into mysql, But if I put it into a mysql_query in a php doc like this:

$result = mysql_query("select * from table where column_name regexp '^.*:\\n'");

I get nothing.

I dug and dug and finally figured it out it was the \n that was throwing the whole thing off, and *only* if I try to use it in a php script.

I am completely stumped. Any suggestions?

justageek

11:54 pm on Jan 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It was probably being escaped in php and then again in mysql.

JAG

jamesa

6:54 am on Jan 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yea, after mysql escapes it the query that the database is seeing would probably look like:
select * from table where column_name regexp '^.*:\n'

See if this works (that's two single quotes at the end):
$result = mysql_query('select * from table where column_name regexp \'^.*:\\n\'');

grnidone

4:46 am on Jan 12, 2004 (gmt 0)



I have to escape the first single quote? *shrug* Hmmm...