Jump to content

Pop up window in PHP


Boerboel649

Recommended Posts

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!!!!!!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>';
}
?>

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.