Boerboel649 Posted April 4, 2007 Share Posted April 4, 2007 Hi all, I have a roster script that pulls players from a DB, and when clicked on, a new window opens, and it shows that players stats. Here's my code: <?php $query = mysql_query("SELECT id, fname, lname FROM players ORDER BY lname"); while ($result = mysql_fetch_array($query)) { $id = $result['id']; $fname = $result['fname']; $lname = $result['lname']; echo '<a href="info.php?id=' . $id . '">'; echo $fname; echo " "; echo $lname; echo '</a><br>'; } ?> I want to make the window that shows the players stats more customizable (e.g. regulate window size, make it non-resizable, no scrollbars, etc. etc.) Sooo... is this possible, and if so, how? I've tried different stuff to no avail. Thanks!!!!!! Quote Link to comment Share on other sites More sharing options...
dough boy Posted April 4, 2007 Share Posted April 4, 2007 With javascript it is. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 4, 2007 Author Share Posted April 4, 2007 Yes, I've tried implementing Javascript, but it didn't work. So if anyone knows how to get it to work using Javscript in PHP, or another way, please help! Thanks!!!! Quote Link to comment Share on other sites More sharing options...
dough boy Posted April 4, 2007 Share Posted April 4, 2007 Trust me javascript will work. You just have to do it correctly. i.e. <?php $query = mysql_query("SELECT id, fname, lname FROM players ORDER BY lname"); while ($result = mysql_fetch_array($query)) { $id = $result['id']; $fname = $result['fname']; $lname = $result['lname']; echo "<a href=\"javascript:openMyPopUp('info.php?id=". $id ."')>"; echo $fname; echo " "; echo $lname; echo '</a><br>'; } ?> Then just create your javascript function to do the window call and what parameters you want/don't want. http://javascript.internet.com/generators/popup-window.html Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 4, 2007 Author Share Posted April 4, 2007 Thanks! One problem... When I put the <SCRIPT LANGUAGE="JavaScript"> ?In the within the head tags, I beleive it no longer recognizes the PHP code as PHP. What do I do with that? Quote Link to comment Share on other sites More sharing options...
dough boy Posted April 4, 2007 Share Posted April 4, 2007 You should be separating your languages. I.e. don't use php to echo HTML/Javascript. Just putting <script type=text/javascript"></script> within the <head></head> tags should not cause the page to "not be" php. If it has a .php extension, then the file is treated as a php file. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 4, 2007 Author Share Posted April 4, 2007 Thanks, however, it's not working... For one thing, it only pulls up one database entry when I try to use that code. For another thing, it doesn't even open up the window for that one... <head> <SCRIPT LANGUAGE="JavaScript"> function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=600,left = 540,top = 225');"); } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <?php $query = mysql_query("SELECT id, fname, lname FROM players ORDER BY lname"); while ($result = mysql_fetch_array($query)) { $id = $result['id']; $fname = $result['fname']; $lname = $result['lname']; echo "<a href=\"javascript:popUp('info.php?id=". $id ."')>"; echo $fname; echo " "; echo $lname; echo '</a><br>'; } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 The start of the Javascript code should be: <script type="text/javascript"> not <SCRIPT LANGUAGE="JavaScript"> Ken Quote Link to comment Share on other sites More sharing options...
dough boy Posted April 4, 2007 Share Posted April 4, 2007 Do you have a working example? Are you using Firefox? They have a pretty good javascript debugger. Quote Link to comment Share on other sites More sharing options...
ICKelly Posted April 4, 2007 Share Posted April 4, 2007 woot I knew this one... hehe Corey at htmlcode always like to post this one cgiscript link for popup window Quote Link to comment Share on other sites More sharing options...
suttercain Posted April 5, 2007 Share Posted April 5, 2007 I used this one a while back.. http://www.codelifter.com/main/javascript/amazingframelesspopup1.html Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 5, 2007 Author Share Posted April 5, 2007 Hi all, I've been trying to get this to work and it still isn't working... Here's the closest... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript"> <!-- Idea by: Nic Wolfe (Nic@TimelapseProductions.com) --> <!-- Web URL: http://fineline.xs.mw --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=650,left = 515,top = 200');"); } // End --> </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <?php $query = mysql_query("SELECT id, fname, lname FROM players ORDER BY lname"); while ($result = mysql_fetch_array($query)) { $id = $result['id']; $fname = $result['fname']; $lname = $result['lname']; echo "<a href=\"javascript:openpopUp('info.php?id=". $id ."')>"; echo $fname; echo " "; echo $lname; echo '</a><br>'; } ?> </body> </html> But all this is doing is pulling up one result from the database, and nothing happens when you click on that. The following code will pull up all the database entry, and evertyhing works fine, but obviously no pop up window... <?php $query = mysql_query("SELECT id, fname, lname FROM players ORDER BY lname"); while ($result = mysql_fetch_array($query)) { $id = $result['id']; $fname = $result['fname']; $lname = $result['lname']; echo '<a href="info.php?id=' . $id . '">'; echo $fname; echo " "; echo $lname; echo '</a><br>'; } ?> Anyone know what to do? Thanks!!! Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 5, 2007 Share Posted April 5, 2007 just a couple of suggestions: include a database connection and a database selection in your code. make the javascript function name the same in the href link as the function name Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 5, 2007 Author Share Posted April 5, 2007 just a couple of suggestions: include a database connection and a database selection in your code. make the javascript function name the same in the href link as the function name Yes, I do have a database connection and selection in my code, just did not post it here. Like I said, I have code that works wonderfully without the pop up window. Made the function name the same as the function name in the href link, still doesn't work. Anyone? Thanks! Quote Link to comment Share on other sites More sharing options...
Fergusfer Posted April 5, 2007 Share Posted April 5, 2007 This line will output invalid HTML because you aren't closing the quotation on the href value. echo "<a href=\"javascript:openpopUp('info.php?id=". $id ."')>"; It should be echo "<a href=\"javascript:openpopUp('info.php?id=$id')\">"; (Note that I also removed the string concatenation. This is unnecessary inside a double-quoted string, and removing it makes the line clearer. A cleaner syntax, if your server is configured to allow short tags, would be: <?php $query = mysql_query("SELECT id, fname, lname FROM players ORDER BY lname"); while ($result = mysql_fetch_array($query)) { $id = $result['id']; $fname = $result['fname']; $lname = $result['lname']; ?> <a href="javascript:openpopUp('info.php?id=<?=$id ?>')"> <?=$fname . ' ' . $lname ?> </a><br> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.