?
Solved

PHP Tooltip (nearly there..)

Posted on 2008-10-21
17
Medium Priority
?
391 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
[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
  • 11
  • 6
17 Comments
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 2000 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:Marcus Bointon
ID: 22774370
Check that you don't have a line break in the middle of $row->id_ent
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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:Marcus Bointon
ID: 22774472
Try:

var_dump($row->id_ent);

To confirm what is in that var.
0
 
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:Marcus Bointon
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:Marcus Bointon
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:Marcus Bointon
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

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

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…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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

743 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