views:

178

answers:

4

Hello,

I have a php page that displays rows from a mysql db as a table. One of the fields contains HTML markup, and I would like to amke this row clickable and the html would open in a new popup window. What is the best way to do it, and is there a way to do it without writing the html to a file?

edit: this php page is actually part of an ajax app, so that is not a problem. I do not want to use jquery, as I would have to rewrite the application.

edit:

I have tried this again using the example below, and have failed. I know my script tag is wrong, but I am just echoing out row2 at the moment, so I think my logic is wrong before it ever gets to the javascript.

$sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'";
$sql2="SELECT ARTICLE_DESC FROM Auctions WHERE ARTICLE_NO ='$pk'";
$htmlset = mysql_query($sql2);
$row2 = mysql_fetch_array($htmlset);
echo $row2;
/*echo '<script> child1 = window.open ("about:blank")
child1.document.write("$row2['ARTICLE_DESC']");
child1.document.close()*/
+4  A: 
child1 = window.open ("about:blank")
child1.document.write("Moo!");
child1.document.close()
Diodeus
Are you saying I could replace "Moo!" with the database field variable?
Joshxtothe4
Yes indeed. You could even load your data via Ajax + JSON and feed it a JavaScript variable if you wanted.
Diodeus
I am sorry for my nativity. Would I put your exmaple in script tags, and onclick call call the function?
Joshxtothe4
if I have javascript at the top of the html page generated by the php file, will it be able to access the result of an sql query declared after it?
Joshxtothe4
Hmm, I have messed up something, can you check what I have pasted above?
Joshxtothe4
The last echo statement has your variable ($row2['ARTICLE_DESC']) as a string inside the text block, as opposed to being part of the PHP code itself.
Diodeus
Otherwise the logic is fine?
Joshxtothe4
I guess. The problem lies in your PHP, not your Javascript. I don't know much PHP, so I'm not the one to ask.
Diodeus
A: 

If you don't require a browser window (this suggestion involves a css modal box), you might want to consider one of the "lightbox" variations.

Thickbox can be used to load inline content from the page into a modal window. The link provides demo/details in how to implement inline content as well as other variations.

HectorMac
A: 

I would suggest using a Javascript library like jQuery since it simplifies this type of code and is cross browser compatible.

$(document).ready( function() {

$('#clicker').click( function() {
    myWindow=window.open('','','width=200,height=100')
    myWindow.document.write($("#content"));
    return false;
});

});

The html will be:

 <table>
    <tr>
       <td><div id="clicker">Click Here</div></td>
       <td><div id="content">This is the content</div></td>
     </tr>
 </table>
Vincent Ramdhanie
A: 

if its a lot of data, worth thinking about loading it up via ajax when viewed to save selecting it and sending it to the user on every page load - which would be fairly easy with something like jquery as suggested already.

benlumley