SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict caddyfixr's Avatar
    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 "";

    Thanks for looking!
    Steve

  2. #2
    SitePoint Wizard
    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', ...

  3. #3
    SitePoint Addict caddyfixr's Avatar
    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.

  4. #4
    SitePoint Wizard
    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.
    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?

    when trying your code i get an error "id is undefined".
    Then, I think that is your php code's fault.

  5. #5
    SitePoint Addict caddyfixr's Avatar
    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.

  6. #6
    SitePoint Wizard
    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?
    ...ooops. Sorry about that--my php is very rusty. I didn't remember that you can do this in 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 same page gets displayed in the popup no matter what, and that page is games.php.

    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 02:46.

  7. #7
    SitePoint Addict caddyfixr's Avatar
    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.

  8. #8
    SitePoint Wizard gRoberts's Avatar
    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

  9. #9
    SitePoint Addict caddyfixr's Avatar
    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

  10. #10
    SitePoint Addict caddyfixr's Avatar
    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 "";

    Thanks for helping and I hope this helps someone else
    Steve


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •