Jump to content
Larry Ullman's Book Forums

jonpugh114

Members
  • Posts

    12
  • Joined

  • Last visited

Posts posted by jonpugh114

  1. Hello,

     

    I'm trying to get into OOP and I'm putting together a class to create and validate form inputs/selects/textarea etc.

     

    The property I want to create is an array to hold errors. When a validation method fails to validate the posted input it will add an element to the array which is picked up by the method to create the input then add a class and an error message.

     

    What I'm stuck on is how to create a property as an array, and how to add elements to that array from within the class. Can anyone point me in the right direction?

     

    Maybe I should have started with "hello world"...

     

    Cheers,

     

    Jon

  2. Hello,

     

    I need to force download a PDF file instead of displaying it in the browser, any idea how I'd do this?

     

    This is what I've tried:

     

          $file = 'file.pdf';
           header('Content-type: application/pdf');
           header ("Content-type: octet/stream");
           header ("Content-disposition: attachment; filename=".$file.";");
           header("Content-Length: ".filesize($file));
           readfile($file);
           exit;
    

     

    This appears to force the download, but when I try to open it I'm told that it's either empty or can't be read. Any ideas?

     

    Thanks,

     

    Jon

  3. The query seems to work, I've tested it and it has returned results as expected.

     

    Regarding the database design, the search is for the whole site, and users would be looking for page content along side category/product information. I'm sure that I could (or maybe should) have designed the database so that all content occupies it's own table and I'll bear that in mind next time it comes up.

     

    Thanks,

     

    Jon

  4. Actually, I think I've got it...

     

    This is what I'm doing, and it seems to work:

     

     

    //$keywords variable from search form

     

    $query = '

    SELECT page_id AS id, "content" AS tablename, MATCH (page_content) AGAINST ("'. $keywords .'") AS score FROM content WHERE MATCH (page_content) AGAINST ("'. $keywords .'") AND deleted = "n"

    UNION

    SELECT cat_id AS id, "category" AS tablename, MATCH (cat_desc) AGAINST ("'. $keywords .'") AS score FROM category WHERE MATCH (cat_desc) AGAINST ("'. $keywords .'")

    UNION

    SELECT prod_id AS id, "products" AS tablename, MATCH (prod_desc) AGAINST ("'. $keywords .'") AS score FROM products WHERE MATCH (prod_desc) AGAINST ("'. $keywords .'") ORDER BY score DESC';

     

    $result = mysqli_query($dbc, $query);

    while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {

     

    if ($row['tablename'] == 'content') {

    echo 'page - '. $row['id'] .'<br />';

    }elseif ($row['tablename'] == 'category') {

    echo 'category - '. $row['id'] .'<br />';

    }elseif ($row['tablename'] == 'products') {

    echo 'product - '. $row['id'] .'<br />';

    }

     

    }

     

     

    I'm just returning id's at the moment, but obviously I'll be creating more meaningful results.

     

    Cheers,

     

    Jon

  5. Hello,

     

    I need to set up fulltext searching using three tables, I can do it fairly easily with one table but I'm struggling with this problem.

     

    I was thinking that if it can't be done using a single query, maybe I could do separate queries for each table and try to return a numerical relevance score, which would allow me to merge the results.

     

    Can anyone point me in the right direction?

     

    Thanks,

     

    Jon

×
×
  • Create New...