Solved

Tooltip linked to PHP database

Posted on 2011-02-14
8
864 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

773 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