Simple PHP Variable Issue.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidshq
Forum Newbie
Posts: 12
Joined: Mon May 05, 2008 10:47 pm
Location: Pennsylvania

Simple PHP Variable Issue.

Post by davidshq »

I've got a database that contains some phrases. I grab these phrases from the database and then display them one by one. But initially I don't want any of the text to show. Then as each line shows you have to click a link to display the next line. Pulling from the database works fine, but I'm using prototype/scriptaculous to make these hidden divs visible. It works fine on the first time, but when I dynamically generate the link code - it doesn't work. The script in its entirety is below. Any thoughts?

Code: Select all

<html>
<head>
<script src="/lordsprayer/javascripts/prototype.js" type="text/javascript"></script>
<script src="/lordsprayer/javascripts/scriptaculous.js" type="text/javascript"></script>
</head>
<body>
<?php
include_once "ez_sql_core.php";
include_once "ez_sql_mysql.php";
$db = new ezSQL_mysql('***','***','***','localhost');
$phrases=$db->get_results("SELECT phrase FROM phrases");
?>
<a href="#" onClick="Effect.toggle('1','appear');">Show.</a>
<?php
$i=0;
$j=0;
foreach ( $phrases as $phrase )
{
    $i=$i+1;
    $j=$i+1;
    echo "<div id='".$i."' style='display:none'>";
    echo $i; ' Just checking the value of $i.
    echo $phrase->phrase;
    echo "<br />";
    echo "<a href='#' onClick='Effect.toggle('". $j ."','appear');'>Show.</a>";
    echo $j;  ' Just checking the value of $j.
    echo "</div>";
 
}
?>
 
<?php
    $db->debug();
?>
</body>
</html>
davidshq
Forum Newbie
Posts: 12
Joined: Mon May 05, 2008 10:47 pm
Location: Pennsylvania

Re: Simple PHP Variable Issue.

Post by davidshq »

So, the answer was simple. I needed to change the quotes I was using and escape some of them. The changed code is:

Code: Select all

    echo '<a href="#" onClick="Effect.toggle(\''.$j.'\',\'appear\');">Show.</a>';
Post Reply