1

I would be very grateful if somebody would take the time to read my code and could tell me a way to put variable $kakka in the script below, so that it works. As of now variable $kakka has no value because the php code is down there. Sorry I understand nothing about jQuery but I need this function to work.

Markup and jQuery

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
var refreshId = setInterval(function()
{
  $('#puu').fadeOut("slow").text($kakka).fadeIn("slow");
}, 5000);
</script>
</head>
<body>

PHP

<?php
$rs = mysql_query("SELECT * FROM users WHERE id='$_SESSION[user_id]'");
  while 
    ($row= mysql_fetch_array($rs))
    {$starter= $row['id'];
     $user_name= $row['user_name'];}


$starterID=$starter;
$companyID=$_GET['id'];


$input = $_POST['viesti'];


date_default_timezone_set('Europe/Helsinki');
$timestamp = date('h:i', time());


$file = $companyID." and ".$starterID.".txt";


if (file_exists($file)) {
$kakka = $companyID." and ".$starterID.".txt";
} else {
$kakka = $starterID." and ".$companyID.".txt";
}


$current = file_get_contents($kakka);

if(isset($_POST['viesti']) && $_POST['viesti'] != null){
$currents= $current. "<b>$user_name</b> <br> $input $timestamp\n<br>";
$shipuli= "<b>$user_name</b> <br> $input $timestamp\n<br>";
file_put_contents($kakka, $currents);
}
echo '<div id="puu">'.$current.$shipuli.'</div>';

?>
2

2 Answers 2

2
<?php
$rs = mysql_query("SELECT * FROM users WHERE id='$_SESSION[user_id]'");
  while 
    ($row= mysql_fetch_array($rs))
    {$starter= $row['id'];
     $user_name= $row['user_name'];}


$starterID=$starter;
$companyID=$_GET['id'];


$input = $_POST['viesti'];


date_default_timezone_set('Europe/Helsinki');
$timestamp = date('h:i', time());


$file = $companyID." and ".$starterID.".txt";


if (file_exists($file)) {
$kakka = $companyID." and ".$starterID.".txt";
} else {
$kakka = $starterID." and ".$companyID.".txt";
}


$current = file_get_contents($kakka);

if(isset($_POST['viesti']) && $_POST['viesti'] != null){
$currents= $current. "<b>$user_name</b> <br> $input $timestamp\n<br>";
$shipuli= "<b>$user_name</b> <br> $input $timestamp\n<br>";
file_put_contents($kakka, $currents);
}
echo '<div id="puu">'.$current.$shipuli.'</div>';

?>

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
var refreshId = setInterval(function()
{
  $('#puu').fadeOut("slow").text('<?php echo $kakka;?>').fadeIn("slow");
}, 5000);
</script>
</head>
<body>

Some things to consider

  • mysql_query is deprecated
  • The use of jquery latest is not recommended in production
Sign up to request clarification or add additional context in comments.

Comments

0

Just echo it into a variable -

var refreshId = setInterval(function()
{ 
  var kakka = '<?php echo $kakka; ?>';
  $('#puu').fadeOut("slow").text(kakka).fadeIn("slow");
}, 5000);

1 Comment

This won't work because $kakka is a string. You have to put define it like this in the script: var kakka = '<?php echo $kakka;?>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.