Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member kennedrw's Avatar
    Join Date
    Mar 2006
    Posts
    72
    Member #
    12717
    I am searching for a simple script that:

    1) Allows users to scroll through a simple form with a bunch of subjects in it and then once they select the subject, it outputs all the books in that subject in a table or something? It also would be good if they could just run a search for the books. I'm using it to mantain a collection of mine online.
    my site: textbookpower.com
    my email: rkennedy@ [domain above]

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Start time: 1:40 PM EST

    Database script:
    Code:
    CREATE TABLE subject (
        id INT NOT NULL,
        name VARCHAR(64) NOT NULL,
        PRIMARY KEY (id)
    );
    
    INSERT INTO subject (id, name) VALUES (1, 'Novel');
    INSERT INTO subject (id, name) VALUES (2, 'Automotive');
    INSERT INTO subject (id, name) VALUES (3, 'History');
    INSERT INTO subject (id, name) VALUES (4, 'Web Design');
    
    CREATE TABLE author (
        id INT NOT NULL AUTO_INCREMENT,
        name VARCHAR(64) NOT NULL,
        PRIMARY KEY (id)
    );
    
    INSERT INTO author (name) VALUES ('Steven Moseley');
    
    CREATE TABLE book (
        id INT NOT NULL AUTO_INCREMENT,
        subject_id INT NOT NULL REFERENCES subject (id),
        author_id INT NOT NULL REFERENCES author (id),
        title VARCHAR(256) NOT NULL,
        PRIMARY KEY (id)
    );
    
    INSERT INTO book (subject_id, author_id, title) VALUES (4, 1, 'How to Create a Book Script in 15 minutes');
    index.php
    PHP Code:
    <?php

        $connectionLink 
    mysql_connect("localhost""username""password");
        
        if (isset(
    $subject_id)) {
            
    $sql "SELECT * FROM book WHERE subject_id = $subject_id";
            
    $resultLink mysql_query($sql$connectionLink);
            echo 
    "<ul>";
            while (
    $fields mysql_fetch_array($resultLinkMYSQL_BOTH) {
                echo 
    "<li>{$fields['title']}</li>";
            }
            echo 
    "</ul>";
        } else {
            
    $sql "SELECT * FROM subject";
            
    $resultLink mysql_query($sql$connectionLink);
            echo 
    "<form action=\"$PHP_SELF\">";
            echo 
    "<select name=\"subject_id\" size=\"10\">";
            while (
    $fields mysql_fetch_array($resultLinkMYSQL_BOTH) {
                echo 
    "<option value=\"{$fields['id']}\">{$fields['name']}</option>";
            }
            echo 
    "</select>";
            echo 
    "<input type=\"submit\" value=\"Look up\" />";
            echo 
    "</form>";
        }
    ?>
    End time: 1:54 PM EST

    (Untested... no debugging in 15 minute coding. :-D)

  4. #3
    Member kennedrw's Avatar
    Join Date
    Mar 2006
    Posts
    72
    Member #
    12717
    That was amazingly fast. How long have you been developing with PHP?
    my site: textbookpower.com
    my email: rkennedy@ [domain above]

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Is it just me, or is that relying on register_globals being enabled? O_O

  6. #5
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    nah, it's a code segment... variable was assigned somewhere much earlier, lol ;-)

    Sean

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Ok ok, add this at the beginning of the PHP to make it work without register globals..

    $subject_id = $_POST['subject_id'];


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:02 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com