FUNKAM35 Posted June 25, 2008 Share Posted June 25, 2008 Hi, say I want to change something on my php page in mysql databse. For example I want to change where it is cat in the database to display as dog on the page what is the code I use? Hope this makes sense! Also I need to alter several fields so change cat to dog and pig to cow how would I do this? Thank you all help much appreciated Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/ Share on other sites More sharing options...
vbnullchar Posted June 25, 2008 Share Posted June 25, 2008 @Also I need to alter several fields so change cat to dog and pig to cow how would I do this? -> you do a mysql_query example : mysql_query("UPDATE table SET field='cow' WHERE field='pig' ") that changes all the cow to pig.. Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-573993 Share on other sites More sharing options...
FUNKAM35 Posted June 25, 2008 Author Share Posted June 25, 2008 Hi, I think I didn't explain clearly. I don't want the actual mysql to change, just for one php page I need it to only display cat as dog, but it still remain as cat in the mysql db. Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574000 Share on other sites More sharing options...
zenag Posted June 25, 2008 Share Posted June 25, 2008 u can use switch.. (eg:) $row=$row["field"]; switch ($row) { case 'pig': $var="cow"; break; case 'dog': $var="pig"; break; } Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574002 Share on other sites More sharing options...
Wolphie Posted June 25, 2008 Share Posted June 25, 2008 <?php if($con = mysql_connect('server', 'username', 'password')) mysql_select_db('db_name') or die('MySQL Error: ' . mysql_error()); $sql = mysql_query("SELECT * FROM `db_name` . `table_name`", $con) or die('MySQL Error: ' . mysql_error()); if(mysql_num_rows($sql) > 0) { while($row = mysql_fetch_array($sql)) { if($row['field_name'] == 'cat') print 'dog'; } } // Or you can use switch() as zenag suggested. if(mysql_num_rows($sql) > 0) { switch($row['field_name']) { case 'cat': print 'dog'; break; case 'dog': print 'cat'; break; default: print 'cat & dog'; break; } } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574004 Share on other sites More sharing options...
FUNKAM35 Posted June 25, 2008 Author Share Posted June 25, 2008 u can use switch.. (eg:) $row=$row["field"]; switch ($row) { case 'pig': $var="cow"; break; case 'dog': $var="pig"; break; } Thank you can you please tell me which do I alter do I insert mysql field into $row but what about $var? Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574006 Share on other sites More sharing options...
zenag Posted June 25, 2008 Share Posted June 25, 2008 if(mysql_num_rows($sql) > 0) { while($row = mysql_fetch_array($sql)) { $row=$row["field"]; switch ($row) { case 'pig': $var="cow"; break; case 'dog': $var="pig"; break; } echo $var; } $var is nothing but assigning variable for ...$row["field"] Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574013 Share on other sites More sharing options...
FUNKAM35 Posted June 25, 2008 Author Share Posted June 25, 2008 I can't get them to work!! I need to be able to copy and paste what the code is exactly and also I am inserting into exisitng php script where will it go? Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574014 Share on other sites More sharing options...
zenag Posted June 25, 2008 Share Posted June 25, 2008 can u show ur code to us...we will try to help u... Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574018 Share on other sites More sharing options...
FUNKAM35 Posted June 25, 2008 Author Share Posted June 25, 2008 Hi I have got it to work for the first item but because of the formatiing it messes the display up because the <p> formatting finishes after the switched item. This is what I have got echo"<p class = \"display\"><img src=\"animals/$animal.jpg\" width=\"27\" height=\"21\" alt=\"$animal\" />$animal<br />"; switch ($animal){ case "Dog": echo"TEST</p>"; break; } WHAT i need is to fit the switch into the normal code: echo"<p class = \"display\"><img src=\"animals/$animal.jpg\" width=\"27\" height=\"21\" alt=\"$animal\" />$animal<br />"; but when I try and insert it it goes blank Link to comment https://forums.phpfreaks.com/topic/111817-changing-php-display/#findComment-574076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.