Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 13th, 2004, 8:42 PM   #1
bufhal
Newbie
 
Join Date: May 2004
Posts: 1
Rep Power: 0 bufhal is on a distinguished road
Working on a web page with three dropdowns: Agency, Date and City. When a user clicks on one of the choices from the dropdown, a record(s) with all 11 fields:
(city date day time agency location building_room street zip phone contact) are supposed to be returned in a pop up. I only have Agency City and Date being returned. Both files are below--can someone please take a look and show me in simple terms how to remedy this?
Thank you in advance..Bufhal
<?php 
// Connection to the db server and select active db 
$SQLlink = @mysql_connect("sql.com", "wnyaic", "immunize"); //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 

// 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>"; 

?>
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(".com", "wnyaic", "947"); //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; 

?>
bufhal is offline   Reply With Quote
Old May 14th, 2004, 8:44 AM   #2
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,623
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
well your not really telling the reply.php to print out anything more then date, agency, and city. if you want the rest of the stuff printed they need to be added to the output. that is all i can see as to why its not printing but i could be wrong i will keep looking
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old May 17th, 2004, 4:30 PM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
As fars as i can tell, big_k105 is right.

Quote:

$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;
the problem is where you are outputing your data, the only fields that are being outputed are date, agency and city because those are the on;y ones that you are telling it to output. Anyways, here's how i would do it:

echo "<table border=1>";
if (mysql_num_rows($data) <> 0)
{
     forEach ($agencies as $agency)
     {
           echo "<tr>";
           echo "<td>{$agency['date']}</td>";
           echo "<td>{$agency['agency']}</td>";
           echo "<td>{$agency['city']}</td>";
           echo "<td>{$agency['day']}</td>";
           echo "<td>{$agency['time']}</td>";
           echo "<td>{$agency['location']}</td>";
           echo "<td>{$agency['building_room']}</td>";
           echo "<td>{$agency['street']}</td>";
           echo "<td>{$agency['zip']}</td>";
           echo "<td>{$agency['phone']}</td>";
           echo "<td>{$agency['contact']}</td>";
           echo "</tr>";
      }
}
else
{
      echo "<tr>";
      echo "<td>No Results Found!</td>";
      echo "</tr>";
}

echo "</table>";

But that's just how i would do it. I find this way a little easyer to read, thus making it easyer to debug. Post any questions that you have and i am sure we can get this problem fixed. Happy Codding!

-Pizentios
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC