I do this:

if($_SESSION['level'] == 1) { echo "[.$row['date'].]<font color="#ff0000">.$row['username'].</font>.$row['message']."; } else { echo "[".$row['date']."]".$row['username']." : ".$row['message'];} } 

But there is no effect, please tell me the error. But the chat itself:

 <script type="text/javascript"> setTimeout("window.location.reload()",10000);//Обновление раз в 5 секунд </script> <?php session_start(); $db = mysql_connect("")or die(mysql_error()); mysql_select_db("")or die(mysql_error()); $result = mysql_query("SELECT * FROM messages ORDER BY id DESC LIMIT 50"); while ($row = mysql_fetch_array($result)){ ?> <html> <head> <style> body{ border-color: #CCCCFF/*верхний цвет*/ #CCCCFF/*правый цвет*/ #CCCCFF/*нижний цвет*/ #CCCCFF/*левый цвет*/; border-style: border-width: 1px/*в.г*/ 2px/*п.г*/ 4px/*н.г*/ 3px/*л.г*/; background-color: #CCCCFF; text-align: center; } </style> </head> <body> <div align="left"> <?php if($_SESSION['level'] == 1) { echo $row['date'] . '<font color="#ff0000">' . $row['username'] . '</font>' . $row['message']; } else { echo $row['date'] . $row['username'] . ':' . $row['message']; } </div> </body> </html> 
  • Judging because, as the output should be in any case, I think the query to the database is incorrectly carried out or before the if () condition there are still other conditions. - Yoharny Babay
  • Did you leave blank quotes, or was it? $ db = mysql_connect ("") or die (mysql_error ()); mysql_select_db ("") or die (mysql_error ()); And then your logic is wrong, you deduce 50 times <html> ... </ html> and all that is in it ... - Fucking Babay
  • Well then it is clear, in this case, there is a lack of "}" brackets at the end of the if () {....} else {....}} condition - this bracket is not enough - it closes the WHILE cycle. and the condition of the cycle should be lowered to the IF level in order not to repeat the page body code 50 times. - Yoharny Babay

3 answers 3

UPDATE

 <?php session_start(); $db = mysql_connect("")or die(mysql_error()); mysql_select_db("")or die(mysql_error()); $result = mysql_query("SELECT * FROM messages ORDER BY id DESC LIMIT 50"); ?> <html> <head> <style> body{ border-color: #CCCCFF/*верхний цвет*/ #CCCCFF/*правый цвет*/ #CCCCFF/*нижний цвет*/ #CCCCFF/*левый цвет*/; border-style: border-width: 1px/*в.г*/ 2px/*п.г*/ 4px/*н.г*/ 3px/*л.г*/; background-color: #CCCCFF; text-align: center; } </style> <script type="text/javascript"> setTimeout("window.location.reload()",10000);//Обновление раз в 5 секунд </script> </head> <body> <div align="left"> <?php while ($row = mysql_fetch_array($result)){ if($_SESSION['level'] == 1) { echo "[".$row['date']."]" . "<font color=\"#ff0000\">" . $row['username'] . "</font>" . " :" . $row['message']; }else{ echo "[".$row['date']."]". $row['username'] . " :" . $row['message']; } } ?> </div> </body> </html> 
  • No, it does not show - k0mar
  • Why? - Fucking Babay
  • you ban !!! - Yoharny Babay
  • five
    @Fatahan - great job ^^ - Zowie
  • 3
    thanks Alex ^^ - DO NOT BAN! I teach a person to do Backups: DDD - BomBom

Slightly not correct ... Especially if there are many levels. It will be better to use the SwitchCase construction here.

As for the record itself, try:

 echo $row['date'] . '<font color="#ff0000">' . $row['username'] . '</font>' . $row['message']; 

If that ... Then you just put other quotes in quotes ... This is not correct ... Therefore, they should either be escaped with \ (Example: \ "text \") or single quotes should be put '' (The last option can be applied only with text and HTML and variables in single quotes are not displayed.

     if($_SESSION['level'] == 1) { echo $row['date'] . '<font color="#ff0000">' . $row['username'] . '</font>' . $row['message']; } else { echo $row['date'] . $row['username'] . ':' . $row['message']; } 
    • No, it does not, here's a pancake =) - k0mar