Results 1 to 10 of 10

Thread: Is there a way...?

  1. #1
    Join Date
    Dec 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Is there a way...?

    Hi,

    I have a small html site where I write reviews of books I've read and I am try to find a way to keep a track of the number of reviews by genre (horror,crime).

    Is there a way that i can insert a php script into each table (each review is in a table box) so I can later display at the top of the genre page "There is ... reviews in this section." ?

    And if thats possible, would it be possible to display the total amount of reviews in the whole site like "We have read a total of ... books." ? Sorry I'm a total php newbie, only good with html.

    Thanks for your help,

    Mav

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Absolutely, though it will take some re-structuring, I'm sure. First off, all of your reviews will need to be in a MySQL Database (are they in HTML tables now?) and then you can use PHP to retrieve the information. Another advantage is that users can search your reviews. But again, this will take some re-structuring. If you need to learn about PHP, you can take a crash-course with video tutorials at www.phpvideotutorials.com or www.sampsonresume.com (I would also recommend reading up on it with google searches). Otherewise, have fun
    Last edited by Jas; 07-05-2007 at 03:26 AM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #3
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Yes you can do this easily in php. Since you are a newbie @ php, you may have a little difficulty at first, but practice makes perfect

    First off, in your web hosting control panel, create a user, and a database, and add them together with ALL permissions set. Next, go to your administration for mysql (if you have one, usually it is phpMyAdmin), click on the database name you created to the left, and click on the SQL tab on the top.

    From there, run this query:
    PHP Code:
    CREATE TABLE `reviews` ( 
      `
    idint(11NOT NULL auto_increment
      `
    genrevarchar(255collate latin1_general_ci NOT NULL
      `
    horrorvarchar(255collate latin1_general_ci NOT NULL
      
    PRIMARY KEY  (`id`) 
    ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=

    Then, to add stuff to the DB, make a page called 'insert.php', and cut and paste this code into it:
    PHP Code:
    <?php

    mysql_connect
    ("YOUR_HOST""YOUR_DB_USER""YOUR_DB_PASS") or die(mysql_error());
    mysql_select_db("YOUR_DB_NAME") or die(mysql_error());

    $mystery $_POST['mystery'];
    $horror $_POST['horror'];

    mysql_query("INSERT INTO reviews (mystery, horror) VALUES('$mystery, '$horror') ") or die(mysql_error());

    ?>
    <html>
    <form action=insert.php method=post>
    Review for genre: <input type=text name=genre><br />
    Review for horror: <input type=text name=horror><br />
    <input type=submit value='Submit Review To Database'></form>
    </html>
    From that, you will have information orgranized into a nice and neat format in mysql. Hope you enjoy PHP!
    Last edited by JShor; 07-06-2007 at 02:17 AM. Reason: mistake

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
      `genre` varchar(255) collate latin1_general_ci NOT NULL,  
      `horror` varchar(255) collate latin1_general_ci NOT NULL,
    Hm? This looks rather odd to me... what exactly do you expect the "horror" column to contain? Personally, I'd just have "genre" and give it values like "horror."
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Your right Twey, my mistake....just change the 'genre' table to something else such as mystery or whatever.

  6. #6
    Join Date
    Dec 2004
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for replying so to add a movie to the database I just put the name of the movie in the "Review for .....:" form box?

    How would I add new categories to the insert.php, just add another line of
    PHP Code:
    $genrename $_POST['genrename']; 
    and add it aswell to
    PHP Code:
    mysql_query("INSERT INTO reviews (mystery, horror,genrename) VALUES('$mystery', '$horror', '$genrename') ") or die(mysql_error()); 
    ?

    What code do I use to display the amount of reviews in each category and the total amount in all categories?

    Thanks for your help

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    JShor, beware, you haven't escaped that SQL properly.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    this seems like a good idea, I could use something like that on my site aswell,would it be possible to add sub genres?

  9. #9
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This does seem useful ...

    I have visited dynamicdrive often but never signed up for forum until about 10 minutes ago. I was searching how to call single file to multiple pages when I stumbled across this question. I'll have to mark it for later when I get to the MySql point.

    Meanwhile, Mav, I tried to email you direct but couldn't. Wanted to ask you a ?

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You really do need to escape those variables with mysql_real_escape_string(). As it stands, an attacker can execute arbitrary queries against your database.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •