?
Solved

Tooltip linked to PHP database

Posted on 2011-02-14
8
Medium Priority
?
879 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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 

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 750 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 750 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 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