Solved

Building a PHP Function

Posted on 2008-10-20
6
194 Views
Last Modified: 2012-05-05
Hi guys hope you are all well.
Guys im having issues trying to make the following code into a php function.

For example, the following works fine:

<a href="#" onmouseover="Tip('Some text', STICKY, true, EXCLUSIVE, false, CLICKSTICKY, true, CLOSEBTN, true)" onmouseout="UnTip()">Homepage </a><br>      

What Im trying to do is the following....

Hope you guys can assist.


function wz_tooltip_text ($text, $displaynamelink) {
 
	$wz_tooltip_config_text = "STICKY, true, EXCLUSIVE, false, CLICKSTICKY, true, CLOSEBTN, true";	
	
print <<<HERE
<a href="#" onmouseover="Tip('<?php echo {$text}; ?>',<?php echo {$wz_tooltip_config_text}; ?>)" onmouseout="UnTip()"><<?php echo {$displaynamelink}; ?>></a>	
HERE;
}

Open in new window

0
Comment
Question by:Simon336697
  • 3
  • 3
6 Comments
 
LVL 17

Expert Comment

by:psimation
ID: 22756874
function wz_tooltip_text ($text, $displaynamelink) {
 
        $wz_tooltip_config_text = "STICKY, true, EXCLUSIVE, false, CLICKSTICKY, true, CLOSEBTN, true";  
       
$stuff = "<a href=\"#\" onmouseover=\"Tip('$text',$wz_tooltip_config_text)\" onmouseout=\"UnTip()\"><$displaynamelink></a>";

return $stuff;

}
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22757065
Hi psimation..
Thank you mate...still having issues with it.

0
 
LVL 17

Expert Comment

by:psimation
ID: 22757110
What issues are you having? Errors?

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:Simon336697
ID: 22757164
Mate thank you for your help.

It works if i do the following and not use RETURN (I dont know why this is).

I can then call it as follows....

<?php wz_tooltip_text("hi there","Go there"); ?>

The above works fine, but I need to go one step further psim and make the arguments variables like below....

Im trying to retrieve records from a mysql table with

while ($row = mysql_fetch_object($rs)) {
print $row->name_ent;
etc

so

im hoping to do as below...

while ($row = mysql_fetch_object($rs)) {
<?php wz_tooltip_text("< print $row->id_ent;","print $row->name_ent;"); ?>




function wz_tooltip_text ($text, $displaynamelink) {
 
        $wz_tooltip_config_text = "STICKY, true, EXCLUSIVE, false, CLICKSTICKY, true, CLOSEBTN, true";   
			$stuff = "<a href=\"#\" onmouseover=\"Tip('$text',$wz_tooltip_config_text)\" onmouseout=\"UnTip()\">$displaynamelink</a>";
echo $stuff;
}

Open in new window

0
 
LVL 17

Accepted Solution

by:
psimation earned 500 total points
ID: 22757239
while ($row = mysql_fetch_object($rs)) {
<?php wz_tooltip_text("< print $row->id_ent;","print $row->name_ent;"); ?>

should be this?

<?php
while ($row = mysql_fetch_object($rs)) {
wz_tooltip_text($row->id_ent,$row->name_ent);
}
?>
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22757317
Thats great thank you so much psimation................CHAMPION !!!!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
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.

815 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

8 Experts available now in Live!

Get 1:1 Help Now