Re: verify text in field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



admin@xxxxxxxxxxxxxxxxxxx wrote:
> Try
> $text = "Joe of Egypt";
> $sql = "SELECT title FROM book WHERE title LIKE '$text'";
> $result = mysql_query($sql);
> If(mysql_num_rows($result) >= '1')
> {
> while ( $row = mysql_fetch_array($sql) ) {
> echo("<P>" . $row["title"] . "</P>");
> }
> }
>
> My Ideas my not make some people happy with my design but I use it and it
> works very well
>
>
>
> -----Original Message-----
> From: PJ [mailto:af.gourmet@xxxxxxxxxxxx]
> Sent: Thursday, February 26, 2009 5:07 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  verify text in field
>
> 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!")
>
> ?>
>
I think I was not precise in my question.
I meant that I do need to be able to use an if condition to determine
which instruction will be executed next: e.g. if the $return is ""(empty
or 0) then I INSERT data somewhere; if the $return is a string or text
or 1, then I either do a different insert or I abort the operation and
ask to restart it with different criteria.
I was just wondering if there was conditional operation I could use that
would replace this:
=============
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!")
============
-- 

Phil Jourdan --- pj@xxxxxxxxxxxxx
http://www.ptahhotep.com
http://www.chiccantine.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux