SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Buffalo
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    intermittent results from dropdowns

    Hello;
    I hope someone can offer some feedback to a newbie struggling. I have 3 dropdowns on a webpage which are populated with a MySQL database. When I upload a text file via PHPMyAdmin, I get intermittent results back in the Javascript pop up. I leave the first column blank for auto incrment and when I look at it in PHPMyAdmin, evrything looks ok, however on the webpage I only get a few querys back--the others say "no result found". The kicker is-when I manually insert one row at a time via PHPMyAdmin, it works 99% of the time.
    I have been through this code countless times and I am stuck.
    If someone could take a look, I would greatly appreciate it. I can either post the relevant code or-zip and email (I would rather zip and email if possible).
    I will do whatever is needed upon a responce.
    Thank you,
    bufhal

  2. #2
    SitePoint Zealot mcahill's Avatar
    Join Date
    May 2002
    Location
    Manchaug, MA, USA
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Your select query...

    for the dropdown. How does it work when you run it through PHP myadmin.

    Without looking at the code, I suspect you've got something amiss in the select statement you use to populate the dropdown box. Either you're missing a bit of information you need, or you've got a limit statement in there that is restricting how many rows you return.

    Perhaps if we saw the code that populates the drop down and the basic table structure, it might help.
    mcahill
    Reel-Time.com - Saltwater Fly Fishing
    The Vario Blog
    VarioCreative.com 1 2 3 4 5 6 7

  3. #3
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Buffalo
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dropdown problems

    Thank you, mcahill.
    I do not know if you can explain it but when I manually insert the records one at a time through phpmyadmin, the dropdown querys work, but when I upload a textfile, they do not.
    Anyways, here is the code..Thank you.
    Here is the relevant code from the webpage with dropdowns:
    index.php
    PHP Code:
    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 ($dates as $value
    $date_out .= "<option value='$value'>".date('m/d/Y',strtotime($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.""
    echo 
    $agency_out.""
    echo 
    $city_out."<BR>";
    ?> 
    Here is the results.php for printing the results in pop up:

    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("13.com""_wnyaic""jlyn"); //creates a connection

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

    if (!mysql_select_db("wnyaic"$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 * 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=4>No results found</td></tr>"
      
    } else {
        
    $output .= "<tr>";
        
    $output .= "<td align=\"center\"><b>Date</b></td>";
        
    $output .= "<td align=\"center\"><b>Agency</b></td>";
        
    $output .= "<td align=\"center\"><b>City</b></td>";
        
    $output .= "<td align=\"center\"><b>Time</b></td>";
        
    $output .= "<td align=\"center\"><b>Day</b></td>";
        
    $output .= "<td align=\"center\"><b>Location</b></td>";
        
    $output .= "<td align=\"center\"><b>Building or Room</b></td>";
        
    $output .= "<td align=\"center\"><b>Street</b></td>";
        
    $output .= "<td align=\"center\"><b>Zip</b></td>";
        
    $output .= "<td align=\"center\"><b>Phone</b></td>";
        
    $output .= "<td align=\"center\"><b>Contact</b></td>";
        
    $output .= "</tr>";
      forEach (
    $agencies as $agency) {           // display row for each result (eg. you can have more agencies in one town) 

        
    $output .= "<tr>";
        
    $output .= "<td align=\"center\">".$agency["date"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["agency"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["city"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["time"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["day"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["location"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["building_room"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["street"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["zip"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["phone"]."</td>";
        
    $output .= "<td align=\"center\">".$agency["contact"]."</td>";

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

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

    ?>


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
  •