Jump to content

CroNiX

Staff Alumni
  • Posts

    1,469
  • Joined

  • Last visited

  • Days Won

    12

Posts posted by CroNiX

  1. in form_action.php, you'd do:

    //grab start/end times, and force them to integers
    $start = (int)$_GET['startpoint'];
    $end = (int)$_GET['endpoint'];
    
    //build the filename
    $filepath = '/path/to/file/';
    $filename = $start . $end . '.pdf';
    
    //check to see that it actually exists first
    if (file_exists($filepath . $filename))
    {
      //send file to browser
      header('Content-type: application/pdf');
      header('Content-Disposition: attachment; filename="' . $filename . '"');
      header('Content-Transfer-Encoding: binary');
      header('Content-Length: ' . filesize($filepath . $filename));
      header('Accept-Ranges: bytes');
    
      readfile($filepath . $filename);
    }
  2. So the user can only select 1, or 2, timeslots from the same day? Do they need to be consecutive time slots?

     

    One problem in helping with this stuff is only you know the business logic required for this application. So our answers may or may not fit into that since we don't know the requirements. We can answer specific questions posed, but the answers may not fit into how the app is supposed to logically work.

  3. If all of these pdf's are being uploaded into a single directory, you can just use PHP's glob() function to retrieve all filenames from that dir.

     

    Let's say you had a dir, like 

    /home/user/pdfs

     

    And in that dir you had:

    MyFilename_Jan2015.pdf

    MyFilename_Feb2015.pdf

    MyFilename_Mar2015.pdf

     

    And you wanted to list them all as links:

    foreach(glob('/home/user/pdfs/*.pdf') as $filename)) //grab all ".pdf" filenames from this dir
    {
      echo '<a href="/path/to/pdf/' . $filename . '">$filename</a><br>';
    }
    • Like 1
  4. One question I have is, assuming you only want to allow a user to be able to book a single timeslot, why you are using checkboxes and allowing them to select multiple timeslots? What happens if I select them all?

     

    It might be better to use links instead, along with a querystring which would be comprised of the date, start time and end time.

    <a href="/book.php?date=2015-1-22&start=0800&end=0830">8:00am - 8:30am</a>

    and then in book.php, grab the date, start and end times

    $date = $_GET['date'];
    $start = $_GET['start'];
    $end = $_GET['end'];

    Then check the database to see if that timeslot is indeed free based on the date, start and end times

    If it is free, book the timeslot

    If not, show error message with a link back to the calendar page.

  5. Yes, but the original mysql extension is being removed from php, so all the code you are writing today using the older mysql functions won't work with an upcoming new version of PHP. So it's really best to not use that extension on a new project and to use PDO or mysqli (like Barand showed) unless you want to rewrite all of this stuff when a newer version of PHP comes out and you upgrade to it (or your host does).

  6. Not going to pretend to be an expert with glob(), but it wouldn't be easy and maybe not possible due to the way your filenames are, and glob's regex is inclusive (can't exclude results).

     

    So, I'd either rename your regular non-thumbnail files to something like:

    q123456-1_full.jpg,  q123456-1_tn.jpg

    and then you can use:

    foreach (glob('/path/to/images/' . $ID . '-*_full.jpg') as $filename) {

    or just test each filename when outputting to see if it contains "_tn.jpg" before outputting

    $ID = 'q123456';
    foreach (glob('/path/to/images/' . $ID . '-*') as $filename)
    {
       //make sure it's not a thumbnail
       if (stripos($filename, '_tn.jpg') === FALSE)
       {
          echo "$filename</br>";
       }
    }

    Another option is to put your "full" files in a separate dir from the thumbnails. Then grab all of the full files, and when you need to output the thumbnails you can add the "_tn" to the filename and just change the path.

  7. No. Again having a table per company would be the same as having a table per user. I'm assuming that you will have/require the same info for each company and it wouldn't change from company/company. That's not what a relational database is supposed to do. Please research "relational database" and I think you'll get a better understanding. You'd have a companies table with the fields for the company information. Each company will have a unique ID.

     

    Something like:

    Companies

    -id (unique company ID)

    -name

    -address

    -website

     

    Then users, and the user references the company they work for

    Users

    -id (unique user id)

    -company_id (references companies.id)

    -first_name

    -last_name

    -email

     

    So this allows multiple companies, and multiple users per company. Same idea as with the invoices.

     

    If a user with an ID of 4 logs in, you look up what company they belong to in the companies table by getting "WHERE companies.id = users.company_id" and load the company data.

  8. Only form fields get transmitted in forms, not stuff from other html. There are no form fields with the name of start or end.

    Try this:

    Set the VALUE of the checkbox (the value is what gets transmitted along with the NAME)

    <input class='fields' type='checkbox' name="booked[]" value="08:00 - 08:15"/>

    Since you are naming those checkboxes 'booked[]', and allow multiple checkboxes to be submitted, you will need to loop over the array in php.

    //grab all transmitted "booked" entries from the $_POST array
    $timeslots = $_POST['booked'];
    
    //iterate over the array
    foreach($timeslots as $timeslot)
    {
      //remove spaces from the timeslot as it's in the format of "xx:xx - yy:yy"
      $timeslot = str_replace(' ', '', $timeslot); //Now looks like "xx:xx-yy:yy"
      
      //get the "start" and "end" times, by splitting the string on the dash
      list($start, $end) = explode('-', $timeslot);
    
      //$start now = xx:xx, $end now = yy:yy
      //just echo out each start/end time to see that it's working
      echo "Start: $start, End: $end<br>";
    }
    • Like 1
  9. That's because you're printing the whole array using print_r, which stands for "print array". If you want just the file, then do:

     

    if ($_POST) {
     echo $_POST['file']; //only echos the 'file' index from the $_POST array
    }
  10. Well, you'd have a registration system. Once their data is saved in the db, they now have a unique ID (auto-incrementing ID column). You wouldn't have a different database for each user. Just one for all. You'd use their ID in all of the other tables.

     

    Like in the invoices table, you'd have a user_id column in addition to your other regular fields. Then when querying the database, you just grab everything for that user_id, or store it using their user_id, or whatever.

     

    That's the purpose of a relational database.

  11. Sorry, that's still pretty vague since you used "select *" instead of listing the actual column names. What does $row look like after you perform the query?

     

    Do you have a separate table to store the image names? If you did then you could just use a JOIN and not store 'PIX' at all in the listings table. That's the purpose of a relational database.

     

    listings:

    -id

     

    listing_images:

    -ID

    -listing_id (references listings.id)

    -image_name

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.