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

Recommended Answers

All 8 Replies

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

Member Avatar for diafol
$chatlog .= $currentchat; //$currentchat appended

//EDIT
Sorry simult. post

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

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

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 />";
Member Avatar for diafol

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

I actually developed my own session code.

Thank you guys for all the help.

Member Avatar for diafol

Good. Mark it solved then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.