Solved

PHP Tooltip (nearly there..)

Posted on 2008-10-21
17
379 Views
Last Modified: 2012-05-05
Hi everyone I hope i find you all well.
Firstly, A HUGE THANK YOU to you AWESOMELY KIND PATIENT GURUS on here (you know who you are :>)) who helped me with this question on a previous post. This is a cut down non-spaghetti version of that, which i could not yet get working (most probably due to me being a bit 'slow', and not because of the skillful people who tried to help me on this). I think this time we will have better luck as Ive made some progress now (which is predominantly due to the ever-helpful brilliant minds on here :>))

I have a function guys that displays tooltips.
The function is named:    wz_tooltip_image
I call it by: wz_tooltip_image ($displaynamelink, $title)
I am calling this inside a WHILE LOOP, in order to display images from records in a mysql table.
So a call might look like below:

while ($row = mysql_fetch_object($rs)) {      
wz_tooltip_image($row->name_ent, $row->name_ent);
}
      
The problem I am having with this function is with the $stuffimage variable.

-----------------------------------------------------------------------------------
WHAT DOES WORK IN THE $stuffimage variable:
-----------------------------------------------------------------------------------
In the following, I have just placed part of $stuffimage (the important parts):

1) Sending a variable through a query string to image_fetcher.php: THIS WORKS
onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=102\'>',

2) Hard coding the image name: THIS WORKS
onmouseover=\"Tip('<img src=\'cat.jpg\'>',

-----------------------------------------------------------------------------------
WHAT DOES NOT WORK BUT WHAT I NEED TO GET WORKING
-----------------------------------------------------------------------------------
Although the above 2 points work, I dont want to use these methods
in reality, since Im hard coding either the GET variable, or the image
I want to pull the image records from a mysql table, so I need to get point 1 above, which is:

onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=102\'>',

which DOES WORK, to be slightly changed to push the $row->id_ent to image_fetcher.php

THE BELOW DOES NOT WORK, and errors with 'Unterminated string constant'
THIS IS THE ONLY PART I NEED TO GET WORKING.
onmouseover=\"Tip('<img src=\"imagefetcher.php?id_ent='.$row->id_ent.\'>',

The problem above is with how i am escaping the
?id_ent='.$row->id_ent

Any help on this I would be truly grateful.

Thank you everyone :>)






======================================================

FUNCTION wz_tooltip_image:

======================================================

function wz_tooltip_image ($displaynamelink, $title) {

 

$wz_tooltip_config_image = "

STICKY, true, 

FIX, [740,235], 

WIDTH, 870,  

HEIGHT, 565, 

BGCOLOR, 'black', 

TITLE, 'Image: $title', 

TITLEFONTCOLOR, '#FFC', 

TITLEBGCOLOR, '#664',  

EXCLUSIVE, false, 

CLICKSTICKY, true, 

CLICKCLOSE, false,

CLOSEBTN, true

"; 
 

$styleimage = "style=\"font-family:arial; font-size:xx-small; padding:0; margin:0; border:none;\"";
 

// The following 2 lines work for the variable '$stuffimage' ///////////////////////////////////////////////////////////////
 

// 1) SENDING A VARIABLE THROUGH A QUERY STRING TO IMAGE_FETCHER.PHP:

$stuffimage = "<a href=\"#\" $style onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=102\'>',$wz_tooltip_config_image)\" onmouseout=\"UnTip()\">$displaynamelink</a>";
 

// 2) HARD CODING THE IMAGE NAME:

$stuffimage = "<a href=\"#\" $style onmouseover=\"Tip('<img src=\'cat.jpg\'>',$wz_tooltip_config_image)\" onmouseout=\"UnTip()\">$displaynamelink</a>";

Open in new window

0
Comment
Question by:Simon336697
  • 11
  • 6
17 Comments
 
LVL 25

Accepted Solution

by:
Squinky earned 500 total points
ID: 22774300
The wz library is now very old. You should take a look at more modern replacements like http://livepipe.net/control/window

This syntax should work fine (it's something you have tried above already) - it tested ok for me. The only problem I can see is that line breaks inside $wz_tooltip_config_image will probably break Internet Explorer as it doesn't handle white space properly.

$stuffimage = "<a href=\"#\" $style onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=$row->id_ent\'>',$wz_tooltip_config_image)\" onmouseout=\"UnTip()\">$displaynamelink</a>";
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774352
hi Squinky,

Mate thanks so much for that...

With the $stuffimage you did above, i get the following....

http://localhost/dropdowndbpilot/pagination/paginationpilotdb/image_fetcher.php?id_ent=

0
 
LVL 25

Expert Comment

by:Squinky
ID: 22774370
Check that you don't have a line break in the middle of $row->id_ent
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774388
Mate no line breaks.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774416
Ive tried the following and it breaks..
$okay = "$row->id_ent";
<img src=\'image_fetcher.php?id_ent=\"$okay\"\'>'
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774429
This escaping in php is killing me :>)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774453
This works:

onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=102\'>'

but this doesnt:

onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=$row->id_ent\'>'
0
 
LVL 25

Expert Comment

by:Squinky
ID: 22774472
Try:

var_dump($row->id_ent);

To confirm what is in that var.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:Simon336697
ID: 22774484
Okay bud (thank u so much for your help :>)
I'll Be right back :>)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774500
Output mate is:

string(3) "102"
0
 
LVL 25

Expert Comment

by:Squinky
ID: 22774523
That looks ok. Weird that it works for me. You could give this a go:

onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent={$row->id_ent}\'>'

or drop out of interpolation and concat it yourself:

onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=".$row->id_ent."\'>'
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774545
Squinky, i wonder if it could be the following..

The function im defining has $stuffimage inside of it.

Im calling the function INSIDE a WHILE LOOP,  as follows:

while ($row = mysql_fetch_object($rs)) {      

wz_tooltip_image($row->name_ent, $row->name_ent);      


So im wondering if that is why $row->id_ent

is not being seen in the query string, because:

onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=$row->id_ent\'>'

is defined in the function?

What i get is:

http://localhost/dropdowndbpilot/pagination/paginationpilotdb/image_fetcher.php?id_ent=

when using:

$stuffimage = "<a href=\"#\" $style onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=$row->id_ent\'>',$wz_tooltip_config_image)\" onmouseout=\"UnTip()\">$displaynamelink</a>";

and the above is INSIDE the function, OUTSIDE the WHILE statement.

But, in the WHILE statement, i can do

var_dump($row->id_ent);      

and get the id_ent value.


0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774576
Squinky, i tried both of your suggestions, and still get ?id_ent=

0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774604
<<<<<<<<<<<<<<<<< MATE IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! >>>>>>>>>>>>>>>>>>>>>>

It was because my definition of $row->id_ent was INSIDE THE FUNCTION.

I changed the function to include a 3rd parameter as follows:

function wz_tooltip_image ($displaynamelink, $title, $showme) {

blah blah

onmouseover=\"Tip('<img src=\'image_fetcher.php?id_ent=$showme\'>',

}

then called it with:

wz_tooltip_image($row->name_ent, $row->name_ent, $row->id_ent);      

and it works!!!!!!!!!!!!!!!


MATE THANK YOU SO MUCH FOR YOUR KIND HELP!!

0
 
LVL 25

Expert Comment

by:Squinky
ID: 22774627
Well if $stuffimage is defined inside the function, it won't exist outside it. Similarly, if $row is defined outside the function then it won't be available inside it. Are you echoing $stuffimage inside or outside the function?
0
 
LVL 25

Expert Comment

by:Squinky
ID: 22774635
Dang, me too slow!
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22774697
Thanks so much squinky you were on to it mate :>)
You guys on here are just incredible.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 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

19 Experts available now in Live!

Get 1:1 Help Now