...

View Full Version : want to print in pop up



bufhal
05-02-2004, 09:59 PM
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? :rolleyes: Thank you



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

raf
05-02-2004, 10:09 PM
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.

bufhal
05-02-2004, 10:35 PM
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. :thumbsup:

raf
05-02-2004, 11:08 PM
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:


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.

bufhal
05-03-2004, 02:40 AM
thank you raf.. :thumbsup:

aspdude2004
05-04-2004, 07:06 PM
when you posted your database is it a good idea to display your password?? can other people access it?? :cool: just wonderin

bufhal
05-04-2004, 10:59 PM
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..
.. :thumbsup:

bufhal
05-05-2004, 12:57 AM
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:
// 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

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.. :)

raf
05-05-2004, 01:20 AM
:confused:
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

bufhal
05-05-2004, 01:28 AM
thanks Raf;
but I thought the interaction between the two files was:


$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.. :p

raf
05-05-2004, 01:40 AM
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


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


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>

bufhal
05-05-2004, 02:46 AM
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:
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum