Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying All Notes In a Tooltip 2

Status
Not open for further replies.

pastorandy

IS-IT--Management
Nov 2, 2006
84
GB
Hi

I have a CUSTOMER Tbl and a Comments Tbl and a CUSTOMER can have more than one Comment record in their Notes. i.e One to Many from Customer.

I have a Customer_ID in the Comments tbl as a foreign key.

I have a query that produces rows of customers and I have a popup window that displays the Comments in a tooltip.

The problem is I can only display one Comment entry.
Here's a simplified query...

Code:
$query5 = "SELECT contact_comment FROM comments
           WHERE comments.customer_id = 1";
	       
$result5 = mysql_query($query5) or die (mysql_error()); 
$contact_comment = mysql_result($result5,0,'contact_comment');	

$contact_comment = str_replace(Chr(39), " ", $contact_comment );
	$contact_comment = str_replace(Chr(34), " ", $contact_comment );
	$contact_comment = str_replace(Chr(13), " ", $contact_comment );
	$contact_comment = str_replace(Chr(9),  " ", $contact_comment );
	$contact_comment = str_replace(Chr(10), " ", $contact_comment );
	$contact_comment = str_replace("'", " ", $contact_comment );

And then just <?=$contact_comment?>

Any idea on how I might show all the comments and not just one?
 
Hi, you need to loop the recordset, not simply just grabbing the first row (0), as your doing here:
Code:
$contact_comment = mysql_result($result5,0,'contact_comment');

Code:
$blah = "";
   while($row=mysql_fetch_array($result5)) {
       $blah .= $row['contact_comment'];
   }

ps. take this as psuedocode!

Olav Alexander Mjelde
Admin & Webmaster
 
use a while loop and a mysql_fetch_*() function
 
Hi
I did try that first but it added extra columns to my output to display the comments.

I guess it must be something to do with how I am displaying my tooltip variable. I'll have a go at that first and post back if I don't get anywhere.

Thx
 
Code:
$query5 = "SELECT contact_comment FROM comments
           WHERE comments.customer_id = 1";
$array = array(chr(39), chr(34), chr(13), chr(9),"'");
$result5 = mysql_query($query5) or die (mysql_error()); 
$contact_comment = "";
while ($row = mysql_fetch_array($result5)){
 $contact_comment .= str_replace($array, " ", $row[0]) . " ";
}
 
Ps. wont that tooltip look horrible?
Eg. You cant have <hr /> in a tooltip..

I would consider using CSS / AJAX to emulate a "htmltooltip" with html capabilities and maybe scrolling functions?

Olav Alexander Mjelde
Admin & Webmaster
 
that's an interesting idea Olav. Stu at cssplay.co.uk has a number of constructs that would be a neat fit for this.

and if css and the associated cross browser headaches proves too tough, a simple piece of javascript might also improve the presentation layer.
 
ok, I had to get the tooltip onmouseover code on one line for it to work so it is really messy but now displays all the comments.

Code:
  <td class="td_top" onMouseover="ddrivetip('<? while($row5 = mysql_fetch_array($result5)){ $contact_comment = $row5[contact_comment]; $contact_comment = str_replace(Chr(39), " ", $contact_comment ); $contact_comment = str_replace(Chr(34), " ", $contact_comment ); $contact_comment = str_replace(Chr(13), " ", $contact_comment ); $contact_comment = str_replace(Chr(9),  " ", $contact_comment ); $contact_comment = str_replace(Chr(10), " ", $contact_comment ); $contact_comment = str_replace("'", " ", $contact_comment ); $contact_comment = str_replace("\n", "<br>", $contact_comment ); $contact_comment = str_replace("\r", "<br> ", $contact_comment ); $contact_comment = str_replace("CR", "<br> ", $contact_comment ); $contact_comment = str_replace("LF", "<bR> ", $contact_comment ); echo $contact_comment; echo "<br><br>";}?>', 300)"; onMouseout="hideddrivetip()"> <a href="#">Display Comments</a></td>
 
Hi, you dont have to do the variable-code inside the html markup!
You can do the DB stuff in the beginning of the file, before any html.

Then you can add it all to a single variable, using .=, like so:

Code:
$foo .= $row['fieldname'];

(Inside the recordset loop).

You might want to also add some kind of "formatting", add divs, <hr /> or whatever, if you use some of the "htmltooltip" samples we provided above.

Ps. If you add it all in a varible above the html markup, you can still display it in the html doing so:
Code:
<?=$foo?>

ps. you cant use hr, br, etc. for a regular alt="<?$foo?>", but if you use an "htmltooltip", you can do whatever you want.. hyperlinks, images+++.. A great way to impress your coworkers/friends, with little work!

Olav Alexander Mjelde
Admin & Webmaster
 
>>
You cant have <hr /> in a tooltip..
<<

I am using a DHTML tooltip!

Thanks for your help though!

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top