Tooltip linked to PHP database

I use Dreamweaver CS3

I have several Tooltips on a page linked to a PHP/MYSQL database.

I want to enter a parameter value for each tooltip to bring up separate data. Ie. For tooltip1, I want the RouteNumber to be 2 so it brings up the data for that route, for Tooltip2, I want the RouteNumber to be 5, etc.

I can’t figure out the proper coding to send a value to the database for each tooltip.

Here is the code for two tooltips on one page:

<div class="tooltipContent" id="sprytooltip1">
    <p>Route#: <?php echo $row_WRSRoute['RouteNumber']; ?><br>
    Route Name:<?php echo $row_WRSRoute['ShortDescription']; ?><br>
    Compiler: <?php echo $row_WRSRoute['Compiler']; ?><br>
  </p>
</div>

<div class="tooltipContent" id="sprytooltip2">
    <p>Route#: <?php echo $row_WRSRoute['RouteNumber']; ?><br>
    Route Name:<?php echo $row_WRSRoute['ShortDescription']; ?><br>
    Compiler: <?php echo $row_WRSRoute['Compiler']; ?><br>
  </p>
</div>

The Recordset is set to:

SELECT *
FROM wrsroutes
WHERE RouteNumber = colname

If I enter a value in the WHERE statement instead of a variable, the data displays correctly in the tooltip, but uses the same data for all of the tooltips on the page. So I know the recordset and connections are working. However, I want to be able to have each tooltip send a different value for “RouteNumber.”

I assume it is a simple string, but I cannot find any help on this.

So, how do I pass the RouteNumber to the database for each tooltip?
PaBirdsAsked:
Who is Participating?
 
Shinesh PremrajanConnect With a Mentor Engineering ManagerCommented:
The problem is with the linking java script with HTML page generated dynamically.
<?php
$i=1;
do { ?>
<div class="tooltipContent" id="sprytooltip<?php echo $i++; ?>">
    <p>Route#: <?php echo $row_WRSRoute['RouteNumber']; ?><br>
    Route Name:<?php echo $row_WRSRoute['ShortDescription']; ?><br>
    Compiler: <?php echo $row_WRSRoute['Compiler']; ?><br>
  </p>
</div>
<?php } while ($row_WRSRoute = mysql_fetch_assoc($WRSRoute)); ?>

<script type="text/javascript">
<!--
<?php  if($i>1) {
  do { ?>
var sprytooltip<?php echo $i; ?> = new Spry.Widget.Tooltip("sprytooltip<?php echo $i; ?>", "#sprytrigger<?php echo $i--; ?>", {closeOnTooltipLeave:true, followMouse:true});
<?php } while ($i>0); } ?>

If there are spaces then you need to remove the space between the closing <div> tag and the PHP tags, Sometime there could be chances of spaces left there.

Hope this helps
0
 
Jason C. LevineNo oneCommented:
Hi PaBirds,

The Spry tooltips aren't coded to perform an AJAX lookup so you can't really do it the way you have it set above.  How many tooltips per page and are they predictable?  If they are predictable, you would have to create separate recordsets for each tooltip and echo that single variable back.

You MIGHT be able to do something clever using a repeat region but that would require an ID in the database that matches up to tooltip numbers:

<? do { ?>
<div class="tooltipContent" id="sprytooltip<?php echo $row_WRSRoute['RouteNumber']; ?>">
    <p>Route#: <?php echo $row_WRSRoute['RouteNumber']; ?><br>
    Route Name:<?php echo $row_WRSRoute['ShortDescription']; ?><br>
    Compiler: <?php echo $row_WRSRoute['Compiler']; ?><br>
  </p>
</div>
<? } while ($row_WRSRoute = mysql_fetch_assoc($WRSRoute)); ?>

Open in new window



0
 
PaBirdsAuthor Commented:
That looks interesting, but I don't understand where to put the repeat region?
What code then goes in each individual tooltip?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jason C. LevineNo oneCommented:
When you define a tooltip, Dreamweaver creates a div to hold the tooltip content.  What my code above does is replace the tootltip content divs with a repeating region that pulls the content out of your database and also numbers the sprytooltip ID's with the RouteNumber.  So you will need to do a bit of hand-editing in the code to make sure the IDs match, but it should work.

You will not be able to use WHERE RouteNumber = colname unless you only have one tooltip per page.
0
 
PaBirdsAuthor Commented:
I inserted the code you suggested and delted the tootip code that I had in the original post.
When I go to save it, I get a warning that the tooltips no longer exist. I saved it anyway and ran it in my browser, but no tooltips come up.
So I put the original code back in, but delted the contents. It now displays a small blank baox for the  tooltips.
(Note: The Routenumbers correspond to the tooltip ID)
Here is what I have:

<? do { ?>
<div class="tooltipContent" id="sprytooltip<?php echo $row_WRSRoute['RouteNumber']; ?>">
    <p>Route#: <?php echo $row_WRSRoute['RouteNumber']; ?><br>
    Route Name:<?php echo $row_WRSRoute['ShortDescription']; ?><br>
    Compiler: <?php echo $row_WRSRoute['Compiler']; ?><br>
  </p>
</div>
<? } while ($row_WRSRoute = mysql_fetch_assoc($WRSRoute)); ?>

<div class="tooltipContent" id="sprytooltip2">
</div>
<div class="tooltipContent" id="sprytooltip1">
</div>

<script type="text/javascript">
<!--
var sprytooltip1 = new Spry.Widget.Tooltip("sprytooltip1", "#sprytrigger1", {closeOnTooltipLeave:true, followMouse:true});
var sprytooltip2 = new Spry.Widget.Tooltip("sprytooltip2", "#sprytrigger2", {closeOnTooltipLeave:true, followMouse:true});


What am I missing?
0
 
PaBirdsAuthor Commented:
Tried as I might, I could not get your suggested code to work. It either said the tooltips didn't exist, or did nothing at all.

I don't understand the "do while" loop. If I let it as is, nothing happened. If I inserted a starting or ending number (to correspond to the RouteNumber on that page, such as 361)  I would come back and say Tooltip361 does not exist, Tooltip360 does not exist, Tooltip359 does not exist, etc..
So I assume I am still missing a piece (or pieces) of the puzzle.

So I reverted to your other solution of creating separate recordsets for each tooltip. Not as elegant or concise as the other choice, but at least it works.

0
 
Jason C. LevineConnect With a Mentor No oneCommented:
Yeah, sorry about that.  The problem with trying to troubleshoot this stuff remotely is that while I KNOW what I intend to do, it doesn't always come across in the code.

0
 
PaBirdsAuthor Commented:
I need more experience with java to understand and implement the suggestions offered.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.