Play a sound when new comment is detected on AJAX refreshWhich one of these PHP and Mysql scripts is safer security wise?PHP alternating colorsHow do I show a user's credit based on their sessionphp time messed upRails detect if request was AJAXAJAX and playing a sound oncePHP code execution sequenceSql error in my php sourceManipulating retrieved data that is being echoed by an external PHP scriptPlaying sound when new message comes in
Will 700 more planes a day fly because of the Heathrow expansion?
What does 'made on' mean here?
Why are UK Bank Holidays on Mondays?
Would glacier 'trees' be plausible?
Did we get closer to another plane than we were supposed to, or was the pilot just protecting our delicate sensibilities?
Where are the "shires" in the UK?
Should I decline this job offer that requires relocating to an area with high cost of living?
Word for Food that's Gone 'Bad', but is Still Edible?
Nominativ or Akkusativ
Understanding trademark infringements in a world where many dictionary words are trademarks?
Frequency of specific viral sequence in .BAM or .fastq
How to write a 12-bar blues melody
exec command in bash loop
How I can I roll a number of non-digital dice to get a random number between 1 and 150?
Decoupling cap routing on a 4 layer PCB
Wrong answer from DSolve when solving a differential equation
Does it make sense for a function to return a rvalue reference
Can you Ready a Bard spell to release it after using Battle Magic?
Can I use a fetch land to shuffle my deck while the opponent has Ashiok, Dream Render in play?
What does this wavy downward arrow preceding a piano chord mean?
Point of the Dothraki's attack in GoT S8E3?
Emotional immaturity of comic-book version of superhero Shazam
Why do people keep telling me that I am a bad photographer?
US born but as a child of foreign diplomat
Play a sound when new comment is detected on AJAX refresh
Which one of these PHP and Mysql scripts is safer security wise?PHP alternating colorsHow do I show a user's credit based on their sessionphp time messed upRails detect if request was AJAXAJAX and playing a sound oncePHP code execution sequenceSql error in my php sourceManipulating retrieved data that is being echoed by an external PHP scriptPlaying sound when new message comes in
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm making a live chat system for my site. Any help with solving this issue is greatly appreciated =). I have a page ticket.php with a div #reply-holder where I fetch the comments for that ticket using AJAX:
<script type="text/javascript">
function loadlink()
$('#reply-holder').load('ajax.php',function ()
$(this).unwrap();
);
loadlink(); // This will run on page load
setInterval(function()
loadlink() // this will run after every 5 seconds
, 15000);
</script>
My ajax.php page where the comments are fetched from the MYSQL db and display is:
<?php
require_once 'inc/config.php';
session_start();
$ticketid = $_SESSION['ticketid'];
$username = $_SESSION['username'];
$getticketid = "SELECT * FROM orders where id = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result = $link->query($getticketid);
$row = $result->fetch_array(MYSQLI_NUM);
$active = $row[2];
$created_at = $row[3];
$message = $row[4];
$price = $row[5];
?>
<?php
$getcomments = "SELECT * FROM comments where orderid = ".$ticketid." ORDER BY id DESC"
or die(mysql_error());
$result2 = $link->query($getcomments);
while($row2 = mysqli_fetch_array($result2))
echo '<div class="reply">';
echo '<p>'.$row2[2].' replied:</p>';
echo '<h3>'.$row2[3].'</h3></div>';
$lastMessageIdWePlayedSoundFor = $row2[0] - 1;
?>
I've tried the following code, but the sound isn't working, no sound is played even if a new comment is inserted.. I first tried it on ajax.php but it would just play the sound after every refresh even if no new comment was inserted.
I'm pretty sure the code is alright, I just don't know exactly where to place it.
<?php
$playsound = "SELECT COUNT(*) FROM comments where orderid = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result2 = $link->query($playsound);
$row2 = $result2->fetch_array(MYSQLI_NUM);
$lastMessageId = $row2[0];
if($lastMessageId!=$lastMessageIdWePlayedSoundFor)
$myAudioFile = "notification.mp3";
echo '<EMBED SRC="'.$myAudioFile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>';
$lastMessageIdWePlayedSoundFor = $lastMessageId;
?>
php ajax
add a comment |
I'm making a live chat system for my site. Any help with solving this issue is greatly appreciated =). I have a page ticket.php with a div #reply-holder where I fetch the comments for that ticket using AJAX:
<script type="text/javascript">
function loadlink()
$('#reply-holder').load('ajax.php',function ()
$(this).unwrap();
);
loadlink(); // This will run on page load
setInterval(function()
loadlink() // this will run after every 5 seconds
, 15000);
</script>
My ajax.php page where the comments are fetched from the MYSQL db and display is:
<?php
require_once 'inc/config.php';
session_start();
$ticketid = $_SESSION['ticketid'];
$username = $_SESSION['username'];
$getticketid = "SELECT * FROM orders where id = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result = $link->query($getticketid);
$row = $result->fetch_array(MYSQLI_NUM);
$active = $row[2];
$created_at = $row[3];
$message = $row[4];
$price = $row[5];
?>
<?php
$getcomments = "SELECT * FROM comments where orderid = ".$ticketid." ORDER BY id DESC"
or die(mysql_error());
$result2 = $link->query($getcomments);
while($row2 = mysqli_fetch_array($result2))
echo '<div class="reply">';
echo '<p>'.$row2[2].' replied:</p>';
echo '<h3>'.$row2[3].'</h3></div>';
$lastMessageIdWePlayedSoundFor = $row2[0] - 1;
?>
I've tried the following code, but the sound isn't working, no sound is played even if a new comment is inserted.. I first tried it on ajax.php but it would just play the sound after every refresh even if no new comment was inserted.
I'm pretty sure the code is alright, I just don't know exactly where to place it.
<?php
$playsound = "SELECT COUNT(*) FROM comments where orderid = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result2 = $link->query($playsound);
$row2 = $result2->fetch_array(MYSQLI_NUM);
$lastMessageId = $row2[0];
if($lastMessageId!=$lastMessageIdWePlayedSoundFor)
$myAudioFile = "notification.mp3";
echo '<EMBED SRC="'.$myAudioFile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>';
$lastMessageIdWePlayedSoundFor = $lastMessageId;
?>
php ajax
in functionloadlink
you should check whather there are new comments or not, then play the sound (by invoking a play method on embed elelement).
– Jeff
Mar 22 at 23:10
in php$lastMessageIdWePlayedSoundFor
doesn't persist through the several calls you do (in setTimeout), because you don't save it in session or something similar. In this/your case php should not manage the UI logic.
– Jeff
Mar 22 at 23:12
@Jeff If i started a session for the$lastMessageIdWePlayedSoundFor
would the current code work? I'm not sure how to edit theloadlink
so if I can do it in php i'd prefer it.
– Ralph
Mar 22 at 23:16
you started a session, right, but you don't store any values into$_SESSION['somevaluename'] = $value;
– Jeff
Mar 22 at 23:34
add a comment |
I'm making a live chat system for my site. Any help with solving this issue is greatly appreciated =). I have a page ticket.php with a div #reply-holder where I fetch the comments for that ticket using AJAX:
<script type="text/javascript">
function loadlink()
$('#reply-holder').load('ajax.php',function ()
$(this).unwrap();
);
loadlink(); // This will run on page load
setInterval(function()
loadlink() // this will run after every 5 seconds
, 15000);
</script>
My ajax.php page where the comments are fetched from the MYSQL db and display is:
<?php
require_once 'inc/config.php';
session_start();
$ticketid = $_SESSION['ticketid'];
$username = $_SESSION['username'];
$getticketid = "SELECT * FROM orders where id = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result = $link->query($getticketid);
$row = $result->fetch_array(MYSQLI_NUM);
$active = $row[2];
$created_at = $row[3];
$message = $row[4];
$price = $row[5];
?>
<?php
$getcomments = "SELECT * FROM comments where orderid = ".$ticketid." ORDER BY id DESC"
or die(mysql_error());
$result2 = $link->query($getcomments);
while($row2 = mysqli_fetch_array($result2))
echo '<div class="reply">';
echo '<p>'.$row2[2].' replied:</p>';
echo '<h3>'.$row2[3].'</h3></div>';
$lastMessageIdWePlayedSoundFor = $row2[0] - 1;
?>
I've tried the following code, but the sound isn't working, no sound is played even if a new comment is inserted.. I first tried it on ajax.php but it would just play the sound after every refresh even if no new comment was inserted.
I'm pretty sure the code is alright, I just don't know exactly where to place it.
<?php
$playsound = "SELECT COUNT(*) FROM comments where orderid = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result2 = $link->query($playsound);
$row2 = $result2->fetch_array(MYSQLI_NUM);
$lastMessageId = $row2[0];
if($lastMessageId!=$lastMessageIdWePlayedSoundFor)
$myAudioFile = "notification.mp3";
echo '<EMBED SRC="'.$myAudioFile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>';
$lastMessageIdWePlayedSoundFor = $lastMessageId;
?>
php ajax
I'm making a live chat system for my site. Any help with solving this issue is greatly appreciated =). I have a page ticket.php with a div #reply-holder where I fetch the comments for that ticket using AJAX:
<script type="text/javascript">
function loadlink()
$('#reply-holder').load('ajax.php',function ()
$(this).unwrap();
);
loadlink(); // This will run on page load
setInterval(function()
loadlink() // this will run after every 5 seconds
, 15000);
</script>
My ajax.php page where the comments are fetched from the MYSQL db and display is:
<?php
require_once 'inc/config.php';
session_start();
$ticketid = $_SESSION['ticketid'];
$username = $_SESSION['username'];
$getticketid = "SELECT * FROM orders where id = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result = $link->query($getticketid);
$row = $result->fetch_array(MYSQLI_NUM);
$active = $row[2];
$created_at = $row[3];
$message = $row[4];
$price = $row[5];
?>
<?php
$getcomments = "SELECT * FROM comments where orderid = ".$ticketid." ORDER BY id DESC"
or die(mysql_error());
$result2 = $link->query($getcomments);
while($row2 = mysqli_fetch_array($result2))
echo '<div class="reply">';
echo '<p>'.$row2[2].' replied:</p>';
echo '<h3>'.$row2[3].'</h3></div>';
$lastMessageIdWePlayedSoundFor = $row2[0] - 1;
?>
I've tried the following code, but the sound isn't working, no sound is played even if a new comment is inserted.. I first tried it on ajax.php but it would just play the sound after every refresh even if no new comment was inserted.
I'm pretty sure the code is alright, I just don't know exactly where to place it.
<?php
$playsound = "SELECT COUNT(*) FROM comments where orderid = '".$ticketid."' ORDER BY id DESC LIMIT 1"
or die(mysql_error());
$result2 = $link->query($playsound);
$row2 = $result2->fetch_array(MYSQLI_NUM);
$lastMessageId = $row2[0];
if($lastMessageId!=$lastMessageIdWePlayedSoundFor)
$myAudioFile = "notification.mp3";
echo '<EMBED SRC="'.$myAudioFile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>';
$lastMessageIdWePlayedSoundFor = $lastMessageId;
?>
php ajax
php ajax
asked Mar 22 at 23:05
RalphRalph
227210
227210
in functionloadlink
you should check whather there are new comments or not, then play the sound (by invoking a play method on embed elelement).
– Jeff
Mar 22 at 23:10
in php$lastMessageIdWePlayedSoundFor
doesn't persist through the several calls you do (in setTimeout), because you don't save it in session or something similar. In this/your case php should not manage the UI logic.
– Jeff
Mar 22 at 23:12
@Jeff If i started a session for the$lastMessageIdWePlayedSoundFor
would the current code work? I'm not sure how to edit theloadlink
so if I can do it in php i'd prefer it.
– Ralph
Mar 22 at 23:16
you started a session, right, but you don't store any values into$_SESSION['somevaluename'] = $value;
– Jeff
Mar 22 at 23:34
add a comment |
in functionloadlink
you should check whather there are new comments or not, then play the sound (by invoking a play method on embed elelement).
– Jeff
Mar 22 at 23:10
in php$lastMessageIdWePlayedSoundFor
doesn't persist through the several calls you do (in setTimeout), because you don't save it in session or something similar. In this/your case php should not manage the UI logic.
– Jeff
Mar 22 at 23:12
@Jeff If i started a session for the$lastMessageIdWePlayedSoundFor
would the current code work? I'm not sure how to edit theloadlink
so if I can do it in php i'd prefer it.
– Ralph
Mar 22 at 23:16
you started a session, right, but you don't store any values into$_SESSION['somevaluename'] = $value;
– Jeff
Mar 22 at 23:34
in function
loadlink
you should check whather there are new comments or not, then play the sound (by invoking a play method on embed elelement).– Jeff
Mar 22 at 23:10
in function
loadlink
you should check whather there are new comments or not, then play the sound (by invoking a play method on embed elelement).– Jeff
Mar 22 at 23:10
in php
$lastMessageIdWePlayedSoundFor
doesn't persist through the several calls you do (in setTimeout), because you don't save it in session or something similar. In this/your case php should not manage the UI logic.– Jeff
Mar 22 at 23:12
in php
$lastMessageIdWePlayedSoundFor
doesn't persist through the several calls you do (in setTimeout), because you don't save it in session or something similar. In this/your case php should not manage the UI logic.– Jeff
Mar 22 at 23:12
@Jeff If i started a session for the
$lastMessageIdWePlayedSoundFor
would the current code work? I'm not sure how to edit the loadlink
so if I can do it in php i'd prefer it.– Ralph
Mar 22 at 23:16
@Jeff If i started a session for the
$lastMessageIdWePlayedSoundFor
would the current code work? I'm not sure how to edit the loadlink
so if I can do it in php i'd prefer it.– Ralph
Mar 22 at 23:16
you started a session, right, but you don't store any values into
$_SESSION['somevaluename'] = $value;
– Jeff
Mar 22 at 23:34
you started a session, right, but you don't store any values into
$_SESSION['somevaluename'] = $value;
– Jeff
Mar 22 at 23:34
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308868%2fplay-a-sound-when-new-comment-is-detected-on-ajax-refresh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308868%2fplay-a-sound-when-new-comment-is-detected-on-ajax-refresh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
in function
loadlink
you should check whather there are new comments or not, then play the sound (by invoking a play method on embed elelement).– Jeff
Mar 22 at 23:10
in php
$lastMessageIdWePlayedSoundFor
doesn't persist through the several calls you do (in setTimeout), because you don't save it in session or something similar. In this/your case php should not manage the UI logic.– Jeff
Mar 22 at 23:12
@Jeff If i started a session for the
$lastMessageIdWePlayedSoundFor
would the current code work? I'm not sure how to edit theloadlink
so if I can do it in php i'd prefer it.– Ralph
Mar 22 at 23:16
you started a session, right, but you don't store any values into
$_SESSION['somevaluename'] = $value;
– Jeff
Mar 22 at 23:34