Jump to content
Larry Ullman's Book Forums

deadbeat

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by deadbeat

  1. Thanks Larry!!

     

    This is what I came up with, for anyone who might be interested.

     

    $fp = fopen("../data/bookings.txt", "r");

    $search = $_POST['search'];

    $match = FALSE;

     

    while ($details = fgetcsv($fp, 1000, "\t")) {

    if ($details[0] == $search){

    $match = TRUE;

    break;

    }

    }

    fclose($fp);

     

    $code = $details[0];

    $hotel = $details[1];

    $tour = $details[2];

    $day = $details[3];

    $month = $details[4];

    $year = $details[5];

    $persons = $details[6];

    $lunch = $details[7];

     

    if ($match) {

    print "<p>Booking Code: $code</p>";

    print "<p>Hotel Pick Up: $hotel</p>";

    print "<p>Tour: $tour</p>";

    print "<p>Tour Date: $day/$month/$year</p>";

    print "<p>Number of Persons: $persons</p>";

    print "<p>With Lunch: $lunch</p>";

    } else {

    print '<p class="error">Booking code not found!</p>';

    }

     

    Works a treat!

  2. Hi,

    Firstly, I just got the book, was having some troubles in a class I'm taking at uni and this has helped me heaps so far. Thankyou!

     

    So what I am trying to acheive, is to be able to read from a .txt file and print info from one line if what was put in the text input form is in that line, if not print an error.

     

    So I already have a page that is a form that writes data to a .txt file. It puts each input from the form on the same line, spaced by a tab and then a new form completion will be the same but on a new line.

     

    ie.

    B0001 Medina Great Ocean Road 01 01 2011 2 Yes

    B0002 Stamford Penguin Parade 01 01 2011 3 No

     

    So I want to be able to have another page with a text input box where i can search for "B0001" and then it will print the results like so:

     

     

    Booking Code: B0001

    Hotel Pick Up: Medina

    Tour: Great Ocean Road

    Tour Date: 01/01/2011

    Number of Persons: 2

    With Lunch: Yes

     

    But if I where to input say "B1" into the text input it would give an error message.

    I can do all of the above fine at the moment.

     

    But I can't get it to search past the first line of the .txt file.

     

    This is the code I have at the moment.

     

     

    $fp = fopen("../data/bookings.txt", "r");

    $details = fgetcsv($fp, 1000, "\t");

     

    if (($details [0]) == $_POST['search']){

    print "<p>Booking Code: {$details [0]}</p>";

    print "<p>Hotel Pick Up: {$details [1]}</p>";

    print "<p>Tour: {$details [2]}</p>";

    print "<p>Tour Date: {$details [3]}/{$details [4]}/{$details [5]}</p>";

    print "<p>Number of Persons: {$details [6]}</p>";

    print "<p>With Lunch: {$details [7]}</p>";

    } else {

    print '<p class="error">Booking code not found!</p>';

    }

    I'm not sure how to approach the next step to get what I want. Any help would be greatly appreciated!!

×
×
  • Create New...