Solved

Tooltip linked to PHP database

Posted on 2011-02-14
8
871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
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…

737 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