If statement...

Discussion in 'PHP' started by le007, Jun 6, 2008.

  1. #1
    (I have input boxes asking data)

    How can I have it that if status = BOOKED that the font for status ONLY is in red? How can I put an if statement for that in here somehow
    <?php
      $saving = $_REQUEST['saving'];
      if ($saving == 1) { 
        $data = '<table width=300 bgcolor=silver><tr><td>' . $_POST['datefrom1'] .'</td><td>'. $_POST['dateto1'] .'</td><td>'. $_POST['status1'] .'</td><td>'. 
    
    $_POST['price1'] . '</td></tr>'
     . '<tr><td>' . $_POST['datefrom2'] .'</td><td>'. $_POST['dateto2'] .'</td><td>'. $_POST['status2'] .'</td><td>'. $_POST['price2'] . '</td></tr>'
     . '<tr><td>' . $_POST['datefrom3'] .'</td><td>'. $_POST['dateto3'] .'</td><td>'. $_POST['status3'] .'</td><td>'. $_POST['price3'] . '</td></tr>'
     . '<tr><td>' . $_POST['datefrom4'] .'</td><td>'. $_POST['dateto4'] .'</td><td>'. $_POST['status4'] .'</td><td>'. $_POST['price4'] . '</td></tr>'
     . '<tr><td>' . $_POST['datefrom5'] .'</td><td>'. $_POST['dateto5'] .'</td><td>'. $_POST['status5'] .'</td><td>'. $_POST['price5'] . '</td></tr></table>';
    	$file = "test.txt"; 
     
        $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); 
        fwrite($fp, $data) or die("Couldn't write values to file!"); 
     
        fclose($fp); 
        echo "Saved to $file successfully!";
      }
    ?>
    PHP:
    ?


    Thank you
     
    le007, Jun 6, 2008 IP
  2. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #2
    hi there,

    
    <?php  
    function color ($status) {
    	if ($status == 'BOOKED') {
    		echo '<font color="#FF0000">' .$status. '</font>';
    	} else {
    		echo $status;
    	}
    }
    
    $saving = $_REQUEST['saving'];  
    if ($saving == 1) {     
    $data = '<table width=300 bgcolor=silver><tr><td>' . $_POST['datefrom1'] .'</td><td>'. $_POST['dateto1'] .'</td><td>'. color($_POST['status1']) .'</td><td>'. $_POST['price1'] . '</td></tr>' . '<tr><td>' . $_POST['datefrom2'] .'</td><td>'. $_POST['dateto2'] .'</td><td>'. $_POST['status2'] .'</td><td>'. $_POST['price2'] . '</td></tr>' . '<tr><td>' . $_POST['datefrom3'] .'</td><td>'. $_POST['dateto3'] .'</td><td>'. $_POST['status3'] .'</td><td>'. $_POST['price3'] . '</td></tr>' . '<tr><td>' . $_POST['datefrom4'] .'</td><td>'. $_POST['dateto4'] .'</td><td>'. $_POST['status4'] .'</td><td>'. $_POST['price4'] . '</td></tr>' . '<tr><td>' . $_POST['datefrom5'] .'</td><td>'. $_POST['dateto5'] .'</td><td>'. $_POST['status5'] .'</td><td>'. $_POST['price5'] . '</td></tr></table>';   
     $file = "test.txt";      
     $fp = fopen($file, "w") or die("Couldn't open $file for writing!");    
     fwrite($fp, $data) or die("Couldn't write values to file!");      
     fclose($fp);     echo "Saved to $file successfully!";  
    }
    ?>
    
    PHP:
    I hope this helps..
     
    mehmetm, Jun 6, 2008 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Thats fantastic...... thanks, I really appreciate the help :D
     
    le007, Jun 6, 2008 IP
  4. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    Sorry I need the booked to be RED when its shown on the page I open the text file from?
     
    le007, Jun 6, 2008 IP