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
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    In my free time I am working on the following website:

    www.casfa.org

    The site calls for a Resource Directory of builders, suppliers, manufacturers, engineers, etc. Each listing will have specific information including: company name, address, phone number, fax number, a short description, and a url to their website. I'm fairly new to PHP and MySQL, but I like working with it and love learning new things about it. However on this project, I'm stumped.

    1. I'm not sure what the database schema should be for this resource directory.
    I know that the schema is closely related to how to code for the search function, but I'm not sure how to do it most efficiently. I could just have each category be it's own table, but then how do I code for the user to be able to search all the listings without limiting their results to just one category.
    2. I don't know how to code complicated searches in PHP.
    From my understanding this is completely dependent on the schema with some basics. I have read the following tutorial:

    Create dynamic sites with PHP & MySQL by Md. Ashraful Anam

    Despite banging my head overcoming the differences in PHP from the time that the tutorial was written and now, this tutorial helped.

    My question is if anyone is willing to help me with some ideas.

    Thanks,

    Jake

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Well, the different categories (builders, suppliers, manufacturers and so on..) all share the same type of fields, as in company name, address, phone number and so on.

    So, you could include a descriptor field, maybe of type ENUM (which basically means that this field can only be one of a range of values).

    For example, someones age band could be like 0-20, 21-50, 50-100.

    This field would store their profession/category (builder, supplier, etc).

    That way when you search the user would indicate what category they were searching for.

  4. #3
    Member
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    I understand what you're saying. I think I was trying to do that. But I threw in one more variable. They to be able to search by name, and by company. Here's what I have so far:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
    <link rel="stylesheet" type="text/css" href="casfa.css">
    <title>California Steel Framing Alliance - CASFA</title>
    </head>

    <body>

    <div id="container">

    <!-- Header -->
        <div id="header">
                <div class="imageright"><img src="images/treesloveit.jpg" alt="Trees Love Steel Framing" /></div>
                <div class="imageleft"><a href="index.html"><img src="images/casfabanner.jpg" alt="CASFA Banner" /></a></div>
        </div>
    <!-- Nav Menu -->
        <div id="menu">
            <ul id="nav">
                <li><a href="aboutcasfa.html">About CASFA</a></li>
                <li><a href="join.html">Join CASFA</a></li>
                <li><a href="underconstruction.html">Resource Directory</a></li>
                <li><a href="underconstruction.html">Tool Box</a></li>
                <li><a href="contact.html">Contact CASFA</a></li>
                <li><a href="http://www.steelframingalliance.com">SFA</a></li>
            </ul>
        </div>
    <!-- Left -->
        <div id="left">
                <img src="images/sidepic1.jpg" height="100" width="100" alt="Placeholder" />
                <img src="images/sidepic2.jpg" height="100" width="100" alt="Placeholder" />
                <img src="images/sidepic3.jpg" height="100" width="100" alt="Placeholder" />
                <img src="images/sidepic4.jpg" height="100" width="100" alt="Placeholder" />
        </div>
    <!-- Content -->
        <div id="content">
            <h2>Cold-Formed Steel Framing Resources</h2>
            
            <form method="post" action="<?php $_SERVER['PHP_SELF']?>">
            <table id="form">
                <tr>
                    <td class="label"><label for="category">By Category:</label></td>
                    <td>
                        <select type="text" name="category">
                            <option id="all" >Select ALL listings...</option>
                            <option id="manufacturing" value="manufacturing">Manufacturing</option>
                            <option id="supply" value="supply">Supply</option>
                            <option id="engineering" value="engineering">Engineering</option>
                            <option id="architecture" value="architecture">Architecture</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="label"><label for="name">By Name:</label></td>
                    <td><input type="text" id="namestring" /></td>
                </tr>
                <tr>
                    <td class="label"><label for="company">By Company:</label></td>
                    <td><input type="text" id="companystring" /></td>
                </tr>
                <tr>
                    <td colspan="2" class="submit"><input type="submit" name="search" value="Search!"</td>
                </tr>
            </table>
            </form>
            <table>
                <tr>
                    <td>Company</td>
                    <td>Address</td>
                    <td>Tel</td>
                    <td>Fax</td>
                    <td>Desc</td>
                    <td>URL</td>
                </tr>
    <?php
    error_reporting
    (E_ALL);

    $category $_POST['category'];
    $namestring $_POST['namestring'];
    $companystring $_POST['companystring'];

    if(isset(
    $_POST['namestring']))
    {
            
            
    $db mysql_connect('localhost''username''pw')or die (mysql_error());
            
    mysql_select_db('database'$db);
            
    $sql "SELECT * FROM table WHERE column LIKE '%$namestring%'";
            
    $result mysql_query($sql$db)or die(mysql_error());
            
            echo 
    "
                <table>
                    <tr>
                        <td>Company</td>
                        <td>Address</td>
                        <td>Tel</td>
                        <td>Fax</td>
                        <td>Desc</td>
                        <td>URL</td>
                    </tr>"
    ;
            while (
    $myrow mysql_fetch_array($result))
            {
            echo 
    "<tr><td>".$myrow['company']."</td><td>".$myrow['address']."</td><td>".$myrow['telephone']."</td><td>".$myrow['fax']."</td><td>".$myrow['description']."</td><td>".$myrow['url'];
            }
    }
    else if(
    $_POST['companystring'])
    {
            
    $db mysql_connect('localhost''username''pw')or die (mysql_error());
            
    mysql_select_db('database'$db);
            
    $sql "SELECT * FROM table WHERE column LIKE %$companystring%";
            
    $result mysql_query($sql$db)or die(mysql_error());
            
            while (
    $myrow mysql_fetch_array($result))
            {
            echo 
    "<tr><td>".$myrow['company']."</td><td>".$myrow['address']."</td><td>".$myrow['telephone']."</td><td>".$myrow['fax']."</td><td>".$myrow['description']."</td><td>".$myrow['url'];
            }
    }
    else if(
    $_POST['category'])
    {
            
    $db mysql_connect('localhost''username''pw')or die (mysql_error());
            
    mysql_select_db('database'$db);
            
    $sql "SELECT * FROM table WHERE column LIKE %$category%";
            
    $result mysql_query($sql$db)or die(mysql_error());
            
            while (
    $myrow mysql_fetch_array($result))
            {
            echo 
    "<tr><td>".$myrow['company']."</td><td>".$myrow['address']."</td><td>".$myrow['telephone']."</td><td>".$myrow['fax']."</td><td>".$myrow['description']."</td><td>".$myrow['url'];
            }
    }
    echo 
    "</table>";
    ?>
        </div>
    <!-- Footer -->
        <div id="footer">
            &copy California Steel Framing Alliance                    
        </div>
    </div>

    </body>
    </html>
    Here's the errors I get:

    Code:
    Notice: Undefined index: namestring in path on line 82
    
    Notice: Undefined index: companystring in path on line 83
    
    Notice: Undefined index: companystring in path on line 108
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%all%' at line 1
    Any ideas?

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    First, I am not sure if this is the reason, but the undefined index errors, try giving them a name attirbute as same as the id. Such as

    HTML Code:
    <input type="text" id="companystring" name="companystring" />
    Though like I say that may not be it.

    Also, in your form tag you do not have a echo in the action attribute.

    Change
    HTML Code:
    <form method="post" action="<?php $_SERVER['PHP_SELF']?>">
    to
    HTML Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>;">
    And your actual query itself, try putting single quotes around where you use the LIKE keyword. Such as

    PHP Code:
    $sql "SELECT * FROM table WHERE column LIKE '%$companystring%'"
    I notice in some queries you have quoted that section and some you have not.

  6. #5
    Member
    Join Date
    Jan 2004
    Posts
    68
    Member #
    4547
    I've made those corrects, thanks for pointing them out. Any ideas on the undefined indexes?

  7. #6
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Try using isset() in the conditional statements, like you do here
    PHP Code:
    if(isset($_POST['namestring']))

    Include that in your other conditionals, as I think thats the problem, when you first view the page, the first conditional will fail so the flow will fall to the next, and because the form has not been submitted, $_POST['companystring'] will not be there yet.


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 07:31 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com