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 Quote Link to comment 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.. Quote Link to comment 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. Quote Link to comment 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; } Quote Link to comment 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); ?> Quote Link to comment 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? Quote Link to comment 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"] Quote Link to comment 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? Quote Link to comment 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... Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.