Re: verify text in field
| From: | Shawn McKenzie | Date: | Thu, 26 Feb 2009 23:34:19 +0000 |
| Subject: | Re: verify text in field | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288888@lists.php.net to get a copy of this message | ||
PJ wrote:
> Is there a shorter way of determining if a field contains text?
> This works but I wonder if I can K.I.S.S. it? I really only need to know
> if there is or is not a field containing the text specified. I don't
> need to see it.
> <?php
>
> // Request the text
> $text = "Joe of Egypt";
> $sql = "SELECT title FROM book WHERE title LIKE '$text'";
> $result = mysql_query($sql);
> if (!$result) {
> echo("<P>Error performing query: " .
> mysql_error() . "</P>");
> exit();
> }
>
> // Display the text
> while ( $row = mysql_fetch_array($result) ) {
> echo("<P>" . $row["title"] . "</P>");
> }
> if ($row["title"] == "")
> echo ("Empty!")
>
> ?>
>
// Request the text
$text = "Joe of Egypt";
$sql = "SELECT title FROM book WHERE title LIKE '%$text%'";
$result = mysql_query($sql);
if (!$result) {
die("<P>Error performing query: " . mysql_error() . "</P>");
}
if (mysql_num_rows($result) > 0) {
// you found text
}
--
Thanks!
-Shawn
http://www.spidean.com