Jump to content

Changing php display


FUNKAM35

Recommended Posts

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

<?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


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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.