SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: search page

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Lincoln NE
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Please Help guys!! (search page)

    I am able to view all the records when I hit submit(without entering any value for in the fields on the search page), but I'm not getting any results when I enter any value in any of the text fields or if I select something from the drop down menu.
    Any suggestions?


    here is my code for my results page.

    <?php

    $dbcnx = mysql_connect();
    mysql_select_db('roula');

    // The basic SELECT statement
    $select = 'SELECT DISTINCT ID, COMPANY, CODE, MDATE'
    $from = ' FROM LBL';
    $where = ' WHERE 1=1';

    $compsearch = $_POST['compsearch'];
    if ($compsearch != '') { // A company is selected
    $where .= " AND COMPANY='$compsearch'";
    }

    $codesearch = $_POST['codesearch'];
    if ($codesearch != '') { // Some code was specified
    $where .= " AND CODE LIKE '$codesearch'";
    }
    $textsearch = $_POST['textsearch'];
    if ($textsearch != '') { // Some search text was specified
    $where .= " AND COMPANY LIKE '%$textserch%'";
    }
    ?>

    <!-- table goes here>

    <?php
    $query1 = @mysql_query($select . $from . $where);
    if (!$query1) {
    echo('</table>');
    die('<p>Error retrieving results from database!<br />'.
    'Error: ' . mysql_error() . '</p>');
    }

    $i = 0;
    $c = 0;
    while ($results = mysql_fetch_array($query1)) {

    // you can change the colours here
    $rowcolor = ($i++ % 2 == 0) ? '#FFFFFF' : '#F2F2F2';

    $id = $results['ID'];
    $company = $results['COMPANY'];
    $code = $results['CODE'];
    $address = $results['ADDRESS'];
    $date = $results['MDATE'];

    echo "<TR bgcolor='$rowcolor'><TD ALIGN='left'>$company</TD>
    <TD ALIGN='center'>$code</TD>
    <TD ALIGN='left'>$address</TD>
    <TD ALIGN='center'>$date</TD>
    <TD ALIGN='center'><a href='edit.php?id=$id'>EDIT</A></TD>
    <TD ALIGN='center'><a href='delete.php?id=$id'>DELETE</A></TD></TR>";
    }
    ?>


    Any help is appericated.
    Last edited by chafikb; May 18, 2003 at 16:39.

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $select should be a string. Check 6th line of your code.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Lincoln NE
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would you please help me with an example. thanks!

  4. #4
    SitePoint Addict
    Join Date
    Jul 2002
    Location
    Sooner Nation
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $select = @mysql_query('SELECT DISTINCT ID, COMPANY, CODE, MDATE FROM LBL ORDER BY COMPANY');
    should be

    $select = 'SELECT DISTINCT ID, COMPANY, CODE, MDATE FROM LBL ORDER BY COMPANY';
    The only function of business is to create customer value and to innovate. - Peter Drucker

  5. #5
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    since you are using

    @mysql_query($select . $from . $where);

    $select should be

    $select = 'SELECT DISTINCT ID, COMPANY, CODE, MDATE FROM LBL ORDER BY COMPANY'

    instead of

    @mysql_query('SELECT DISTINCT ID, COMPANY, CODE, MDATE FROM LBL ORDER BY COMPANY');

    Paul

  6. #6
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, your problem is this line

    $from = ' FROM LBL';

    then $select.$from would be

    'SELECT DISTINCT ID, COMPANY, CODE, MDATE FROM LBL ORDER BY COMPANY FROM LBL'

    Which is an invalid query statement. To fix it just write

    $select = 'SELECT DISTINCT ID, COMPANY, CODE, MDATE';

    and the use this

    $query1 = @mysql_query($select . $from . $where. ' ORDER BY COMPANY');

    Paul

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Lincoln NE
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am able to view all the records when I hit submit(without entering any value for in the fields on the search page), but I'm not getting any results when I enter any value in any of the text fields or if I select something from the drop down menu. What do you think is causing this.
    Any suggestions?


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
  •