/    Sign up×
Community /Pin to ProfileBookmark

PHP in my Javascript help…

I am using the setTimeout() function to reload a javascript function. I then start php up to get new messages from the database. I finally got it to display the text but that is it. It doesn’t output any of the other information. Here is my code.

[code=php]
<?PHP
error_reporting(E_ALL^E_NOTICE);
mysql_connect(“localhost”);
mysql_select_db(“maddChatter”);
?>
<html>

<head>

<title>maddChatter 1.0</title>

<link href=”style.css” rel=”stylesheet” type=”text/css”>

</head>

<body style=”background-color: transparent;” onLoad=”refresh();”>

<div id=”messages”>

<script type=”text/javascript”>
function refresh() {

<?PHP

$getmessages=mysql_query(“SELECT * from messages order by messageId desc”);
echo mysql_error();

while($a=mysql_fetch_array($getmessages)) {

//GET USER NAMES
$getusers=mysql_query(“SELECT * from users where userId=’$a[userId]'”);
$b=mysql_fetch_array($getusers);
echo mysql_error();

if($a[userId]==Notice) {
echo “document.writeln(‘<strong style=”color: #333333;”>Notice:</strong> $a[message]<br>’)”;
}else { echo “document.writeln(‘<strong style=”color: #333333;”>$b[userName]:</strong> $a[message]<br>’)”; }

//echo “alert(“$b[userName]: $a[message]”); “;
}

?>

setTimeout(“refresh()”, 4000); }
</script>

</div>

</body>
</html>
[/code]

Thanks,
[url]www.maddDidley.com[/url]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@blah1985Nov 22.2005 — From what I understang about PHP, all commands MUST be executed before the page displays, meaning PHP will not work if generated, or activated from Javascript. But Js can be activated by PHP. Lemme know if I'm wrong.. but Im pritty sure.
Copy linkTweet thisAlerts:
@madddidleyauthorNov 22.2005 — hmm.....I am looking to reload information from my database without having to refresh the page. Does anyone know a cool trick to do that?


Thanks,
Copy linkTweet thisAlerts:
@blah1985Nov 22.2005 — check another forum.. can't be done with javascript
×

Success!

Help @madddidley spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...