Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    want to print in pop up

    Hello;
    I am trying to create three dropdowns with options for City, Date and Agency that a user can click, recive the entire row from database in a pop up window.
    I want to be able to do this all from this index.php page. I keep getting parse errors-can anyone tell me what I am doing wrong? Thank you

    PHP Code:
    <?PHP
    $hostName 
    "db.com";
    $userName "wny";
    $password "immunize";
    $dbName "wnyorg";
    mysql_connect($hostName$userName$password) or die("Unable to connect to host $hostName");

    mysql_select_db($dbName) or die("Unable to select database $dbName"); 

    $i 0

    $data mysql_query("SELECT date, agency, city FROM agencies"); 
    while(
    $rs mysql_fetch_array($data)) 

       
    $date[$i] = $rs['date']; 
       
    $agency[$i] = $rs['agency'];   
       
    $city[$i] = $rs['city']; 

       
    $i++; 


    $date_out =                   '<select name="date" onchange="window.open('results.php?date='+this.value, 'agencyWin', 'location=yes,left=20,top=20');"> 
    '

    foreach(
    $date as $key => $val

       
    $date_out .= '<option>'.$val.'</option>'

    $date_out .=                        '</select>'

    $agency_out .=                    '<select name="agency" onchange="window.open('results.php?agency='+this.value, 'agencyWin', 'location=yes,left=20,top=20');">'
    foreach(
    $agency as $key => $val

       
    $agency_out .=             '<option>'.$val.'</option>'

    $agency_out .='</select>'

    $city_out =                     '<select name="city" onchange="window.open('results.php?city='+this.value, 'agencyWin', 'location=yes,left=20,top=20');"> 
    '

    foreach(
    $city as $key => $val

       
    $city_out .= '<option>'.$val.'</option>'

    $city_out .='</select>'

    echo 
    $date_out
    echo 
    $agency_out
    echo 
    $city_out;
    ?>
    Thank you
    Last edited by Spookster; 05-02-2004 at 10:31 PM.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please enclose the code in [PHP ] and [/PHP ] tags (without the spaces)
    Can you tell us which errors you get + the lines they are on ? I also don't see the code to select and diplay the record.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you raf. All future posts will have the appropriate tags. Here is the error:
    Parse error: parse error, unexpected T_STRING in E:\www\immunizewny_org\index4.php on line 126
    Regarding the code to select and display-I am unclear on how to proceed. When a user clicks an entry in the dropdown, I want the results for the entire row in the db to be displayed in pop up. I have the selects pointing to results.php, but do I need to have a seperate file (results.php) or can my index.php do it all?
    Thanks for you help.
    Last edited by bufhal; 05-02-2004 at 09:41 PM.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need a seperate file.. Because your javascript opens this new windw and will load the results.php inthere. (You could reopen a second index.php page inthere and set it up as a multipurpose page, but there would be no point in doing it like that)

    About the parse-error --> can't help you with that since you did not post 126 lines here


    About the select --> you need to dynamically create the selectquery. Like this:
    PHP Code:
    sql="SELECT var1, var2, var3 FROM yourtable 
          WHERE yourdatevariable='" 
    $_POST['date'] . "' and  
          yourcityvariable ='" 
    $_POST['city'] . "' and 
          youragencyvariable = '" 
    $_POST['agency'] . "'" 
    The rest is just the regular execuing of the query etc.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you raf..

  • #6
    New Coder
    Join Date
    Apr 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Is it a good idea to print your password?

    when you posted your database is it a good idea to display your password?? can other people access it?? just wonderin
    ...not bad for a thirteen year old

  • #7
    New Coder
    Join Date
    Apr 2004
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.. I changed all the log in info before I posted
    By the way..do you know how to get the returned results (from the code earlier in this post) to print to a pop up. I need a new file, results.php and I do not know how to write it?
    Thanks for any assistance..
    ..
    Last edited by bufhal; 05-04-2004 at 10:01 PM.

  • #8
    New Coder
    Join Date
    Apr 2004
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello;
    I have these two scripts( index.php and results.php) working about 90%, but I cannot understand one thing.
    1) How can I get ALL 12 fields to display in results pop up window, instead of just date, agency city?
    Here are the fields:
    Id | city | date | day | time | agency | location | building_room | street | zip | phone | contact
    Here is index.php:
    PHP Code:
    // perform query 
    $data   mysql_query("SELECT date, agency, city FROM agencies"); 

    if (!
    $data
      Die(
    mysql_error());                        // display MySQL error message on error 

    $agencies = Array(); 

    while(
    $row mysql_fetch_array($data)) {     // assign results into arrays 
      
    $dates[]    = $row["date"]; 
      
    $agencies[] = $row["agency"]; 
      
    $cities[]   = $row["city"]; 


    $dates Array_Unique($dates);               // remove duplicate values 
    $agencies Array_Unique($agencies); 
    $cities Array_Unique($cities); 

    Sort($dates);                                // sort arrays 
    Sort($agencies); 
    Sort($cities); 

    $date_out   "<select name='date'   onchange=\"window.open('results.php?action=date&value='+this.value, 'agencyWin', 'location=yes,left=20,top=20');\">"
    $agency_out "<select name='agency' onchange=\"window.open('results.php?action=agency&value='+this.value, 'agencyWin', 'location=yes,left=20,top=20');\">"
    $city_out   "<select name='city'   onchange=\"window.open('results.php?action=city&value='+this.value, 'agencyWin', 'location=yes,left=20,top=20');\">"

    $date_out   .= "<option>-- select date ---</option>"
    $agency_out .= "<option>-- select agency ---</option>"
    $city_out   .= "<option>-- select city ---</option>"

    forEach (
    $dates as $value
      
    $date_out   .= "<option value='$value'>$value</option>"

    forEach (
    $agencies as $value
      
    $agency_out .= "<option value='$value'>$value</option>"

    forEach (
    $cities as $value
      
    $city_out   .= "<option value='$value'>$value</option>"


    $date_out   .= "</select>\n"
    $agency_out .= "</select>\n"
    $city_out   .= "</select>\n"

    echo 
    $date_out."<BR>"
    echo 
    $agency_out."<BR>"
    echo 
    $city_out."<BR>"

    ?> 
    and here is results.php:

    PHP Code:
    <?php 

    if (!IsSet($action) || !IsSet($value))       // check if both vars are set 
      
    Die("Both vars must be set"); 

    if (
    Trim($value) == "")                      // check if value is non-blank 
      
    Die("Value can't be left blank"); 

    if (
    $action != "date" && $action != "agency" && $action != "city"
      Die(
    "Unknown action requested"); 

    // Connection to the db server and select active db 
    $SQLlink = @mysql_connect("sql.rgbinternet.com""wnyaic""immunize947"); //creates a connection 

    if (!$SQLlink
      Die(
    "Couldn't connect to the db server."); // display error message on error 

    if (!mysql_select_db("immunizewnyorg"$SQLlink)) 
      Die(
    "Couldn't access database.");          // display error message on error 

    // escape data from user 
    if (ini_get('magic_quotes_gpc')) {           // unescaping data if needed 
      
    $value StripSlashes($value); 

    $value mysql_escape_string($value);        // escaping data for MySQL db 


    $data  mysql_query("SELECT date, agency, city FROM agencies WHERE $action = '$value'"); // perform a query 

    if (!$data
      Die(
    mysql_error());                        // display MySQL error message on error 

    $agencies = Array(); 

    while(
    $row mysql_fetch_array($data)) { 
      
    $agencies[] = $row


    $output "<table border=1>\n"
    if (
    mysql_num_rows($data) == 0) {            // in the case of no results found - display alert message 
      
    $output .= "<tr><td colspan=3>No results found</td></tr>"
      
    } else { 
      forEach (
    $agencies as $agency) {           // display row for each result (eg. you can have more agencies in one town) 
        
    $output .= "<tr>"
        
    $output .= "<td>".$agency["date"]."</td>"
        
    $output .= "<td>".$agency["agency"]."</td>"
        
    $output .= "<td>".$agency["city"]."</td>"
        


    $output .= "</tr>\n"
      } 


    $output .= "</table>\n"

    echo 
    $output

    ?>
    Greatly appreciate your help..

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts

    You're only selecting these three fields. So you need to select all these 12 fields from the table and then echo them like the other three you have now

    But i nowhere see any formtags in the html of index.php so nothing can be posted to results and i don't see you setting $action and $value inthere.

    All that happens now is that you run a new select inside results.php without any interaction of the data from index.php
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #10
    New Coder
    Join Date
    Apr 2004
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks Raf;
    but I thought the interaction between the two files was:

    Code:
    $date_out   = "<select name='date'   onchange=\"window.open('results.php?action=date&value='+this.value, 'agencyWin', 'location=yes,left=20,top=20');\">";
    The way you describe the functionality is the way this thing should work.

    I am unclear where I need to make the adjustments to get all 12 fields back in results..(both files index.php and results.php?)..and where to get the files to work together.
    Thanks for your patience..for some of us that are learning, this is rocket science..
    Last edited by bufhal; 05-05-2004 at 12:30 AM.

  • #11
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm. Dont get me wrong but i think you should read a turorial or so on basic form-handling. Try www.hotscripts.com or so.

    Anyway, the formfields inside index.php shoudl be inside formtags. Like
    PHP Code:
    echo '<form id="mainform" name="mainform" action="results.php" method="post">' 
                  
    $date_out '<br />' .  
                  
    $agency_out '<br />' .  
                  
    $city_out .'<br />
              </form>'

    and then inside results.php, you can acces them like
    PHP Code:
    echo $_POST['date']; 
    <edit> about the opning of the popup --> the onchange should be a submit();
    and inside the formtags, you should set a target to open the page in </edit>
    Last edited by raf; 05-05-2004 at 12:46 AM.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #12
    New Coder
    Join Date
    Apr 2004
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will certainly take your advice regarding form handling. I need alot of study to catch up. Could you please incorporate your suggestions in an edit of the previous post that has the entire 2 files? I am not quite sure where to put the form, and in the results, not sure of where to put the:
    Code:
    echo $_POST['date'];
    and to add the other fields so all fields are returned for each query of Agency, Date or City. I assure you I am trying to understand, however, I do not know where to "put it all together" so I can get this thing working efficiantly.
    I admire your knowledge and will try to understand your suggestions..
    bufhal


  •  

    Posting Permissions

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