SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
-
Jan 29, 2005, 13:33 #1
- Join Date
- Aug 2004
- Location
- Albuquerque, NM
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
display a popup using users id with php
I have been trying to display info from a mysql table with php and insert that info using javascript into a popup. the popup works but the info displayed is for the lowest id number.
Example if page games.php?id=150 is selected games.php?id=72 is displayed.
If I don't use the popup script then it works as desired, games.php?id=150 is selected games.php?id=150 is displayed.
Here is the code I have been working with.
PHP Code:if ($games != '') {
$gotgames = "<SCRIPT LANGUAGE='JavaScript'>
function games()
{
window.open('games.php?id=$id','games',
'toolbar=no,location=no,directories=no,
status=no,menubar=no,copyhistory=no,
width=525,height=400');
}
</script>
<a href= javascript:games()>
<img src='images/icon_trophy.gif' border='0' width='24' height='24''></a>";
} else{
$gotgames = "";
}
Steve
-
Jan 29, 2005, 15:52 #2
- Join Date
- Mar 2001
- Posts
- 3,537
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Shouldn't this:
window.open('games.php?id=$id','games', ....
be something like:
window.open('games.php?id=" + $id + "','games', ...
-
Jan 29, 2005, 16:32 #3
- Join Date
- Aug 2004
- Location
- Albuquerque, NM
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the odd thing about it, is when I view the source code of the page on the web the correct address is displayed correctly but still goes to the wrong page
when trying your code i get an error "id is undefined".
The way I am doing it $id is a place holder for php.
-
Jan 29, 2005, 17:56 #4
- Join Date
- Mar 2001
- Posts
- 3,537
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The way I am doing it $id is a place holder for php.
when trying your code i get an error "id is undefined".
-
Jan 30, 2005, 01:12 #5
- Join Date
- Aug 2004
- Location
- Albuquerque, NM
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Could be your right, thats why I am asking for help. The if statment is part of the php code and the javascript is nested in it. The function resides in the header and was moved near the trigger for testing. Alas it behaves the same in or out of the header.
-
Jan 30, 2005, 02:04 #6
- Join Date
- Mar 2001
- Posts
- 3,537
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Look at the color of the text in your first post. Which parts are php, and which parts are a string? How can $id be php?
echo "My name is $name.";
So, having $id in there should be ok.
Example if page games.php?id=150 is selected games.php?id=72 is displayed.
If I don't use the popup script then it works as desired, games.php?id=150 is selected games.php?id=150 is displayed.
The content of the popup depends solely on what's in the file games.php. The main page, presumably the one that contains the code above, has to insert a value for $id, so that games.php can react to that value.
I suggest you forget about $id for the time being, and just get your main php page to open in a browser and display the popup link. When that works, work on getting your link to open up games.php in the popup window. Once you have those two steps functioning correctly, you can add the query string to the url in the window.open() call on the main page. As a first try, hard code the query string, e.g.
games.php?id=10;
Then, try extracting the id from the query string using php on the games.php page. When you can do that, try altering the content in games.php using '10'. When you get all that to work, go back and replace '10' with $id.Last edited by 7stud; Jan 30, 2005 at 03:46.
-
Jan 30, 2005, 11:28 #7
- Join Date
- Aug 2004
- Location
- Albuquerque, NM
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am totaly baffeld.
I hard coded it and it opens the box just as it should with no errors.
after adding $id in place of 150 it goes to 72. To check to see if php is loosing it I added title='$teamname $id' so that when the mouse is over the trophey icon so I can see if the proper identifiers are displayed, and they are. I added a new team with a lower id number and now the javascript sends it to that page.
you can view the page to see what is happening here
http://www.iconmatrix.com/SoCalMgr/10UpremiumTest.php
one more thing there is a player icon that is not using javascript and it opens the proper page. This is for testing the php portion at the moment and is intended to be converted to a popup when I resolve this.
-
Jan 30, 2005, 12:20 #8
- Join Date
- Oct 2004
- Location
- Birtley, UK
- Posts
- 2,439
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
well in asp you usually do this:
<a href="games.asp?ID=<%= Recordsetname("ID") %>"><%= Recordsetname("Title") %></a>
Providing you have defined Recordsetname as a recordset and given it an connection.
php shouldn't be that different,
Gav
-
Jan 30, 2005, 12:53 #9
- Join Date
- Aug 2004
- Location
- Albuquerque, NM
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
As I stated I am not having any problem geting or posting in php. The problem I am experiancing is in passing the variable to javascript or at least passing it correctly to acheive the desired results.
Thanks for your Help
-
Jan 30, 2005, 16:38 #10
- Join Date
- Aug 2004
- Location
- Albuquerque, NM
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I figured it out! I chucked the function and instead use <form>
PHP Code:if ($games != '') {
$gotgames = "<form method=\"post\" action=\"games.php?id=$id\" target=\"_blank\" onsubmit=\"window.open('', 'processor_window', 'width=400,height=400'); this.target = 'processor_window'\">
<input type=\"image\" src=\"images/icon_trophy.gif\" alt=\"$teamname are hosting games, click for info\" border='0' width='24' height='24' name=\"games\"></form>
";
} else{
$gotgames = "";
}
Steve
Bookmarks