JackW Posted June 29, 2007 Share Posted June 29, 2007 Change text based on database content?I have a database full of items in several categories.Examples are:Cowhide/Leather Milano style FurnitureCowhide/Leather Remington style FurnitureCowhide/Leather Winchester style FurnitureLampsAccessoriesPine FurnitureEtc.What I want to do is write a code so when a link is clicked and the description page comes up the description for any item with Cowhide/Leather in the category name has some different text than what is on all the other pages. Example: This is a special order item.The code I have below seems to work for Cowhide/Leather Milano style Furniture. Is there a way I can write it so that it will echo the correct text for all of the categories that contain the word Cowhide/Leather?Your help will be greatly appreciated. <?php$code=$_GET['code'];$style='Cowhide/Leather Milano style Furniture';@ $db = mysql_pconnect('myserver.net', 'mydatabase', 'password');mysql_select_db('mydatabase') or die( "Unable to select database");{$query= "select * from `table` where `ID` = '".$code."' order by ID DESC";$query_results=mysql_query($query);$match_results=mysql_num_rows($query_results);}for ($i=0; $i < $match_results; $i++){$row=mysql_fetch_array($query_results);if($row ['category'] ==$style){echo '<p class="centerbrown">';echo 'Write Something here';echo '</p>';}else{echo '<p class="centerbrown">';echo'Write something Different';echo '</p>';}}mysql_close($db);?> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 30, 2007 Share Posted June 30, 2007 Instead of this:if($row ['category'] ==$style)You can use this: $style = 'Cowhide/Leather';if (strpos($row['category'], $style) !== false) http://www.php.net/manual/en/function.strpos.php Link to comment Share on other sites More sharing options...
JackW Posted June 30, 2007 Author Share Posted June 30, 2007 Instead of this:if($row ['category'] ==$style)You can use this:$style = 'Cowhide/Leather';if (strpos($row['category'], $style) !== false) http://www.php.net/manual/en/function.strpos.php I do believe that is going to work. The tests so far are all positive.You are a wonder.Thank you so much.Jack Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.