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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quickie (hopefully)

    Hello,

    Just hoping to find some help here. I don't know much about PHP/MySQL and what I have done so far is mostly thanks to the help of many websites and manuals.

    I do have a problem now though.

    I am trying to retrieve info from my db (which works fine), to then add buttons to use that retrieved information to generate a new page with even more detailed info.

    In other words: you search using certain values, a new page opens with the results. Each table row has a hidden field with a value that can then be used to retrieve more information by clicking a button. This entire page displays correctly.

    I do however have one problem: if after the initial search only one result comes up, the details page after that opens fine, displaying the correct info.

    However, if after the initial search there is more than one result, no matter what button I click, it will automatically retrieve the detailed info from the last table row (and therefore hidden field). How can I resolve that?

    Here's a snippet of the code of the page that appears after searching

    Code:
    <FORM name="form" action="flightinfo.php" method="post">
    			  <tr>
    				 <td width="30%" align="left"><?echo "$depcity, $std"; ?></td>
    				 <td width="30%" align="left"><?echo "$destcity, $eta"; ?></td>
    				 <td width="2%" align="left"><input type="hidden" name="flightno" style="font-family:trebuchet ms, arial, helvetica;" value="<?echo $flightno;?>"></td>
    				 <td width="15%" align="left"><input type="submit" STYLE="font-family : trebuchet ms,arial,helvetica,sans-serif; font-size : 11px; width: 80px;" value="<?echo $flightno;?>"></td>
    				</tr>

    Then, after clicking submit, it opens a new page with detailed info. Here's the code for the start of the page:


    PHP Code:
    include 'db.php';

    //Convert posted to variable
    $flightnumber $_POST['flightno'];

    // Build SQL Query  
    $sql "SELECT * FROM flights WHERE flightno = '$flightnumber'";

    $result mysql_query($sql);

    //Array the goods
    $user_array mysql_fetch_array($result);

    //Convert goods to variables
    $std $user_array['std'];
    $depcountry $user_array['depcountry'];
    $depcity $user_array['depcity'];
    $depicao $user_array['depicao'];
    $destcountry $user_array['destcountry'];
    $destcity $user_array['destcity'];
    $desticao $user_array['desticao'];
    $ete $user_array['ete'];
    $eta $user_array['eta'];
    $flightno $user_array['flightno'];
    $ac $user_array['ac'];
    $freq $user_array['freq'];
    $airline $user_array['airline'];

    mysql_close($connection); 

    Then I lay-out the page, with <html>, <head> and <body> tags. In body, a table, then some more PHP:


    PHP Code:
    <table width="70%" cellpadding='2' cellspacing='2' align='left'>
       <tr>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Dep Country</b></td>
          <td style="font-size:12px;"><?echo $depcountry;?></td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Dest Country</b></td>
          <td style="font-size:12px;"><?echo $destcountry;?></td>
       </tr>
       <tr>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Dep City</b></td>
          <td style="font-size:12px;"><?echo $depcity;?></td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Dest City</b></td>
          <td style="font-size:12px;"><?echo $destcity;?></td>   
         </tr>   
       <tr> 
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Dep ICAO</b></td>
          <td style="font-size:12px;"><?echo $depicao;?></td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Dest ICAO</b></td>
          <td style="font-size:12px;"><?echo $desticao;?></td>            
       </tr>
       <tr> 
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>&nbsp;</b></td>
          <td style="font-size:12px;">&nbsp;</td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>&nbsp;</b></td>
          <td style="font-size:12px;">&nbsp;</td>            
       </tr>
       <tr> 
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>ETE</b></td>
          <td style="font-size:12px;"><?echo $ete;?></td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>ETA</b></td>
          <td style="font-size:12px;"><?echo $eta;?></td>            
       </tr>     
       <tr> 
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Flight No</b></td>
          <td style="font-size:12px;"><?echo $flightno;?></td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Aircraft</b></td>
          <td style="font-size:12px;"><?echo $ac;?></td>            
       </tr>    
       <tr> 
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>&nbsp;</b></td>
          <td style="font-size:12px;">&nbsp;</td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>&nbsp;</b></td>
          <td style="font-size:12px;">&nbsp;</td>            
       </tr>
       <tr> 
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Frequency</b></td>
          <td style="font-size:12px;"><?echo $freq;?></td>
          <td width="20%">&nbsp;</td>
          <td style="font-size:12px;" width="30%" align="left" valign="top"><b>Operated by</b></td>
          <td style="font-size:12px;">                        <? if ($airline==tze)
                                 { echo 
    "<img src='img/tze.gif'>";
                                 }
                                 elseif (
    $airline==abb)
                                 { echo 
    "<img src='img/abb.gif'>";
                                 }
                                 elseif (
    $airline==tzeabb)
                                 { echo 
    "<img src='img/tzeabb.gif'>";
                                 }
                                 else
                                 { echo 
    "";
                                 }                  
                            
    ?></td>            
       </tr>           
    </table>
    Now that last page actually works when there's only 1 search result after the initial search, so I presume my problem doesn't lie in that bit of code. I think it sits somewhere in the page with all the buttons.

    I hope this makes sense, not really sure how to explain it better/differently.
    The only thing I can think of: go have a look at http://www.flycentralasian.com/timetables.html and see what I mean...

    Any help would be appreciated a lot.

    Many thanks

    Peter

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    We need to to see the code that displays the results.

    When you do your query and put the results into an array, it's an array.
    That means you could be getting one result or 3 results in the array.

    So, take this example ...
    Say there are 2 flights arriving at the same destination at the same time.
    The search would then have found 2 results (2 rows)...

    This is one:
    $flightno[0]['flightno']

    and this is the other:
    $flightno[1]['flightno']

    Arrays always start at zero [0]

    You really won't know how many there are, so you'll have to remember how
    many rows were found when you did the query ... this will tell you how many
    items there are in your array.

    //Array the goods
    $user_array = mysql_fetch_array($result);
    $num_rows = mysql_num_rows($result);

    Now you will know if you found 1 row, or 3 rows by looking at $num_rows.

    Hope that helps you get your "flights" in the right direction.


  •  

    Posting Permissions

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