Solved

Tooltip linked to PHP database

Posted on 2011-02-14
8
861 Views
Last Modified: 2013-12-13
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?
0
Comment
Question by:PaBirds
  • 4
  • 3
8 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34890190
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
 

Author Comment

by:PaBirds
ID: 34890430
That looks interesting, but I don't understand where to put the repeat region?
What code then goes in each individual tooltip?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34891036
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
 

Author Comment

by:PaBirds
ID: 34891195
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 17

Accepted Solution

by:
shinuq earned 250 total points
ID: 34895680
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
 

Author Comment

by:PaBirds
ID: 34929396
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
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 250 total points
ID: 34929644
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
 

Author Closing Comment

by:PaBirds
ID: 35055697
I need more experience with java to understand and implement the suggestions offered.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now