Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF ELSE Query

Status
Not open for further replies.

meeble

Programmer
Sep 24, 2002
137
GB
Hello,

I am pulling stuff out the database with:

$sql = "SELECT uid,pic_small,title,text_short FROM tbl_products WHERE prod_type='$prod_type' order by prod_type";
$res = mysql_query($sql);

<?
//loop through all results and show them...
while ($item = mysql_fetch_array($res)) {
//if no pic set use default..
if ($item[&quot;pic_small&quot;] == &quot;&quot;) $item[&quot;pic_small&quot;]=&quot;no_pic_small.jpg&quot;;
?>

print $item[text_short]

}


What I would like is, if $item[text_short] contains a specific phrase, such as 'T shirt' then it prints another phrase underneath, such as 'Best Buy'. If it doesn't match the phrase exactly then nothing is printed.

How can this be done please?

Cheers

James


__________________
It has been said that if you were to put 100 monkeys in a room for an infinite amount of time and gave each one a typewriter, eventually they would reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know that's not true...

James Fielding

 
PHP provides lots of ways to look for a string within another.

strstr() ( will look for the existence of one string in another.

preg_match() ( and ereg() ( will do the same thing using regular expressions. ______________________________________________________________________
TANSTAAFL!
 
probably another good one to look at is the php function switch()

It works like a series of if / thens , so you have more options depending on whats returned by the query

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top