subhomoy Posted January 22, 2014 Share Posted January 22, 2014 Hello every body actually i'm going to create a chat script and i need some idea... suppose two persons ( x and y ) are chatting together... I want to create two different different backgrouns for those messages.. Like x's messages are shown in dark div background and y's background is light..... How can i acheive this... I just need the idea..... Thank u in advance.... Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted January 22, 2014 Share Posted January 22, 2014 (edited) Sounds to me you need to alternate the background color for each message. To do this you'll need to initiate a counter, for this we'll use the variable $i. And we'll define the two background colors $i = 0; // init counter // define background colors $bg_color1 = '#999'; $bg_color2 = '#666'; Now when displaying each messsage you'd do have this $bg_color = (++$i % 2 == 0) ? $bg_color1 : $bg_color2; // alternavte background color echo '<div style="background-color: $bg_color">$message</div>'; // set the background color for the message Edited January 22, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Solution ignace Posted January 22, 2014 Solution Share Posted January 22, 2014 (edited) It's easier if you set the colors specific from the user's perspective. So each user sees his own messages with a green background, while they see all other's messages in different colors. This also means you only need a few colors versus one specific color for each member. Edited January 22, 2014 by ignace Quote Link to comment Share on other sites More sharing options...
subhomoy Posted January 23, 2014 Author Share Posted January 23, 2014 (edited) Thank u guyss for the help... but i think u didn't understood the questions... Ch0cu3r what if same persons sends two message parallery then they will have both different background... I dont want tthat...What i want is that ( x ) will have always the same background irrespective of how many post he posted and this is same for ( Y ) also... Edited January 23, 2014 by subhomoy Quote Link to comment Share on other sites More sharing options...
ignace Posted January 23, 2014 Share Posted January 23, 2014 (edited) We understood it correctly, you misinterpreted. My solution solves that problem. Simply assign a color to each person in the chat. Edited January 23, 2014 by ignace Quote Link to comment Share on other sites More sharing options...
subhomoy Posted January 23, 2014 Author Share Posted January 23, 2014 Thanks for the help..... 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.