Can you see if a DB field contains only a certain character?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Can you see if a DB field contains only a certain charac

Post by Celauran »

You've copied it wrong.

Code: Select all

$query = "SELECT photos FROM property WHERE (photos REGEXP '^\\|+$' OR photos = '' OR photos IS NULL) AND id = '$row->id'";
You've got

Code: Select all

$query = mysql_query ("SELECT photos FROM property WHERE (photos REGEXP '^\\|+$' OR photos = '' OR photos IS NULL) AND id = '$row->id'");
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you see if a DB field contains only a certain charac

Post by simonmlewis »

My bad!

Here's an example of what it produces:
[text]SELECT photos FROM property WHERE (photos REGEXP '^\|+$' OR photos = '' OR photos IS NULL) AND id = '16'[/text]
This section of the code does it if the photoprimary fields is NULL or just empty.
If it's not empty, then it just throws up the "Alert" script anyway. Basically stopping it deleting a field if an image is found.

The one I am looking at that shows no 'Delete' button at all, DOES have text in the 'photos' field:
[text]b1.jpg|b3.jpg|Bm 6 kitchen.jpg|BM 6 bedroom two.jpg[/text]
So it should be producing the "else" part

Code: Select all

 else 
          { 
          echo "<input type='button' onclick=
\"alert('You have PHOTOS stored.  Click Edit, delete all photos, then delete item.')\" 
value='Delete'>"; 
          }
.... should it not?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you see if a DB field contains only a certain charac

Post by simonmlewis »

Any other ideas?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Can you see if a DB field contains only a certain charac

Post by tr0gd0rr »

Don't you need 4 backslashes since you are in a php string and MySQL needs 2 backslashes?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you see if a DB field contains only a certain charac

Post by simonmlewis »

I do coz it's javascript inside PHP.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply