0

Hello, Daniweb members. I've been watching your community forever, and I finally decided to join it.

I am currently designing a bot that can talk to users intelligently. The only issue I am having right now is creating a chat log for my members. I need to be able to call a string inside itself and add to it to keep a steady for. Code example below.

$chatlog=$chatlog.$currentchat;

Is this possible? I am only getting the second part of the string. It replaces itself instead of just adding to it.

Thank you in advance,

Resentful

4
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by diafol
0

Yes, this is possible.

I think you could write your variable initialization in loop . thats why your string variable is re-initialized..

try this:

$chatlog="";
// your loop starts here
{
    $chatlog.=$currentchat;
}

or post required code ..

Edited by Shanti C: n/a

0
$chatlog .= $currentchat; //$currentchat appended

//EDIT
Sorry simult. post

Edited by diafol: n/a

0

I seem to be having the same problem with the above methods.

It just works with one chat, and clears it out each time.

Thank you for the replies,

Resentful

0

I believe the error is because the page is refreshing and not storing the variables.

0

A good way to test it is simply by printing out the variable to make sure they are what you think.

Try...

echo "Current Chat: " . $currentchat ."<br />";
echo "Chatlog before: " . $chatlog  ."<br />";
$chatlog .= $currentchat;
echo "Chatlog after: " . $chatlog ."<br />";
1

If you are refreshing the page, place the variable in a session:

<?php
session_start();
if(isset($_SESSION['chatlog'])){
  $chatlog = $_SESSION['chatlog'];
}else{
  $chatlog = "";
}
..rest of code...

$chatlog .= $currentchat;
$_SESSION['chatlog'] = $chatlog;
?>
0

I actually developed my own session code.

Thank you guys for all the help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.