Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search Feature Coding Problems

    Hi this code is working ok, with one problem, it finds a result but will only bring one search result back. For Example if i have two bakers in my DB and i search for Bakers then it just brings one baker back. Any idea why it's doing this?

    Thanks

    PHP Code:
    <style type="text/css">
    <!--
    .style1 {font-size: 12px}
    .style2 {font-family: Arial, Helvetica, sans-serif}
    body,td,th {
        font-size: 12px;
        color: #000000;
        font-family: Verdana, Arial, Helvetica, sans-serif;
    }
    body {
        background-color: #FFFFFF;
    }
    .style4 {color: #333333}
    .style5 {font-family: Verdana, Arial, Helvetica, sans-serif}
    a:link, a:visited, a:active {
    font-weight: normal;
    border:0;
    padding: 0;
    margin: 0;
    color: #f00;
    background: transparent; 
    text-decoration: none;
    }
    a:hover {
    font-weight: normal;
    color: #0099FF;
    padding: 0;
    margin: 0;
    background: #ddd;
    border:0;
    text-decoration: none;
    }


    .plainlink , a.plainlink , a.plainlink:link , a.plainlink:visited {
    padding: 0;


    a.plainlink:hover {
    padding: 0;
    }
    }
    .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18px; }
    .style11 {color: #0000FF}
    a {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        color: #0033FF;
        font-size: 16pt;
    }
    a:link {
        color: #000000;
        text-decoration: underline;
    }
    a:visited {
        color: #000000;
        text-decoration: underline;
    }
    a:active {
        color: #000000;
        text-decoration: underline;
    }
    -->
    </style>
    <?php include "top_nav.php" ?><br>
    <p><?php
    // set your infomation.
    $dbhost='localhost';
    $dbusername='';
    $dbuserpass='';
    $dbname='test';

    // connect to the mysql database server.
    mysql_connect ($dbhost$dbusername$dbuserpass);
    //select the database
    mysql_select_db($dbname) or die('Cannot select database');

    $rowsPerPage 10;
    $pageNum 1;

    if(isset(
    $_GET['page']))
    {
    $pageNum $_GET['page'];
    }
    if(isset(
    $_GET['search']))
    {
    $search $_GET['search'];
    }

    // counting the offset
    $offset = ($pageNum 1) * $rowsPerPage;

    $keywords explode("industry"$search);

    $query "SELECT id,name,industry,phone FROM yourwom " .
    "WHERE industry LIKE '%".$keywords['0']."%'";

    for (
    $i=1$i<count($keywords); $i++) {
    $query $query." AND industry LIKE '%".$keywords[$i]."%'";
    }
    $query $query." ORDER BY id LIMIT $offset, $rowsPerPage";

    $result2 mysql_query($query) or die(mysql_error());
    ?>
    <center><p>
      <table width="502" border="0" align="left" cellpadding="0" cellspacing="0" style="border:0px solid #000000;">
    <?php
    $keywords 
    explode(" "$search);

    $query "SELECT COUNT(id) AS numrows FROM yourwom " .
    "WHERE industry LIKE '%".$keywords['0']."%'";

    for (
    $i=1$i<count($keywords); $i++) {
    $query $query." AND industry LIKE '%".$keywords[$i]."%'";
    }

    $result mysql_query($query) or die('Error, query failed');
    $row mysql_fetch_array($resultMYSQL_ASSOC);
    $numrows $row['numrows'];

    // how many pages we have when using paging?
    $maxPage ceil($numrows/$rowsPerPage);

    // print the link to access each page
    $self $_SERVER['PHP_SELF'];
    $nav '';

    for(
    $page 1$page <= $maxPage$page++)
    {
    if (
    $page == $pageNum)
    {
    $nav .= " $page ";
    }
    else
    {
    $nav .= " <a href=\"$self?page=$page&search=$search\">$page</a> ";
    }
    }
    // creating previous and next link
    // plus the link to go straight to
    // the first and last page

    if ($pageNum 1)
    {
    $page $pageNum 1;
    $prev " <a href=\"$self?page=$page&search=$search\">[Prev]</a> ";

    $first " <a href=\"$self?page=1&search=$search\">[First Page]</a> ";
    }
    else
    {
    $prev ' ';
    $first ' ';
    }

    if (
    $pageNum $maxPage)
    {
    $page $pageNum 1;
    $next " <a href=\"$self?page=$page&search=$search\">[Next]</a> ";

    $last " <a href=\"$self?page=$maxPage&search=$search\">[Last Page]</a> ";
    }
    else
    {
    $next ' ';
    $last ' ';
    }

    while(
    $row mysql_fetch_assoc($result2))
    {
    $name $row['name'];
    $industry $row['industry'];
    $phone $row['phone'];
    $address $row['address'];
    $locale $row['locale'];
    $postcode $row['postcode'];
    $sypnosis $row['synopsis'];
    $web $row['web'];
    $id $row['id'];
    }
    ?>

    <table width="502" height="46" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#E0DFE3">
      <tr>
        <td height="18" bgcolor="#A3D39C"><span class="style19"><a href="outputformatid.php?id=<?php echo $id?>"><? echo $name?></a></span></td>
        <td width="241" bgcolor="#A3D39C"><span class="style19"><? echo $phone ?></span></td>
      </tr>
      <tr>
        <td height="18" colspan="2" bgcolor="#FFFFFF" class="style19"><p class="style19"><? echo $industry ?><br>
        </p>      </td>
      </tr>
    </table>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p align="left"><? echo "<tr>";
    echo 
    "<td>";
    echo 
    "<center>".$first $prev $nav $next $last."</center>";
    echo 
    "</td>";
    echo 
    "</tr>"?></p>
    </center>
    <?
    $i
    ++;

    echo 
    ?>

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its because the loop that loops through your results is only setting the variables, its not actually outputting the html table (as the table isnt within the curly brackets), this should work:

    PHP Code:
    <style type="text/css">
    <!--
    .style1 {font-size: 12px}
    .style2 {font-family: Arial, Helvetica, sans-serif}
    body,td,th {
        font-size: 12px;
        color: #000000;
        font-family: Verdana, Arial, Helvetica, sans-serif;
    }
    body {
        background-color: #FFFFFF;
    }
    .style4 {color: #333333}
    .style5 {font-family: Verdana, Arial, Helvetica, sans-serif}
    a:link, a:visited, a:active {
    font-weight: normal;
    border:0;
    padding: 0;
    margin: 0;
    color: #f00;
    background: transparent; 
    text-decoration: none;
    }
    a:hover {
    font-weight: normal;
    color: #0099FF;
    padding: 0;
    margin: 0;
    background: #ddd;
    border:0;
    text-decoration: none;
    }


    .plainlink , a.plainlink , a.plainlink:link , a.plainlink:visited {
    padding: 0;


    a.plainlink:hover {
    padding: 0;
    }
    }
    .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18px; }
    .style11 {color: #0000FF}
    a {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        color: #0033FF;
        font-size: 16pt;
    }
    a:link {
        color: #000000;
        text-decoration: underline;
    }
    a:visited {
        color: #000000;
        text-decoration: underline;
    }
    a:active {
        color: #000000;
        text-decoration: underline;
    }
    -->
    </style>
    <?php include "top_nav.php" ?><br>
    <p><?php
    // set your infomation.
    $dbhost='localhost';
    $dbusername='';
    $dbuserpass='';
    $dbname='test';

    // connect to the mysql database server.
    mysql_connect ($dbhost$dbusername$dbuserpass);
    //select the database
    mysql_select_db($dbname) or die('Cannot select database');

    $rowsPerPage 10;
    $pageNum 1;

    if(isset(
    $_GET['page']))
    {
    $pageNum $_GET['page'];
    }
    if(isset(
    $_GET['search']))
    {
    $search $_GET['search'];
    }

    // counting the offset
    $offset = ($pageNum 1) * $rowsPerPage;

    $keywords explode("industry"$search);

    $query "SELECT id,name,industry,phone FROM yourwom " .
    "WHERE industry LIKE '%".$keywords['0']."%'";

    for (
    $i=1$i<count($keywords); $i++) {
    $query $query." AND industry LIKE '%".$keywords[$i]."%'";
    }
    $query $query." ORDER BY id LIMIT $offset, $rowsPerPage";

    $result2 mysql_query($query) or die(mysql_error());
    ?>
    <center><p>
      <table width="502" border="0" align="left" cellpadding="0" cellspacing="0" style="border:0px solid #000000;">
    <?php
    $keywords 
    explode(" "$search);

    $query "SELECT COUNT(id) AS numrows FROM yourwom " .
    "WHERE industry LIKE '%".$keywords['0']."%'";

    for (
    $i=1$i<count($keywords); $i++) {
    $query $query." AND industry LIKE '%".$keywords[$i]."%'";
    }

    $result mysql_query($query) or die('Error, query failed');
    $row mysql_fetch_array($resultMYSQL_ASSOC);
    $numrows $row['numrows'];

    // how many pages we have when using paging?
    $maxPage ceil($numrows/$rowsPerPage);

    // print the link to access each page
    $self $_SERVER['PHP_SELF'];
    $nav '';

    for(
    $page 1$page <= $maxPage$page++)
    {
    if (
    $page == $pageNum)
    {
    $nav .= " $page ";
    }
    else
    {
    $nav .= " <a href=\"$self?page=$page&search=$search\">$page</a> ";
    }
    }
    // creating previous and next link
    // plus the link to go straight to
    // the first and last page

    if ($pageNum 1)
    {
    $page $pageNum 1;
    $prev " <a href=\"$self?page=$page&search=$search\">[Prev]</a> ";

    $first " <a href=\"$self?page=1&search=$search\">[First Page]</a> ";
    }
    else
    {
    $prev ' ';
    $first ' ';
    }

    if (
    $pageNum $maxPage)
    {
    $page $pageNum 1;
    $next " <a href=\"$self?page=$page&search=$search\">[Next]</a> ";

    $last " <a href=\"$self?page=$maxPage&search=$search\">[Last Page]</a> ";
    }
    else
    {
    $next ' ';
    $last ' ';
    }

    while(
    $row mysql_fetch_assoc($result2))
    {
    $name $row['name'];
    $industry $row['industry'];
    $phone $row['phone'];
    $address $row['address'];
    $locale $row['locale'];
    $postcode $row['postcode'];
    $sypnosis $row['synopsis'];
    $web $row['web'];
    $id $row['id'];
    ?>

    <table width="502" height="46" border="0" align="left" cellpadding="0" cellspacing="0" bordercolor="#E0DFE3">
      <tr>
        <td height="18" bgcolor="#A3D39C"><span class="style19"><a href="outputformatid.php?id=<?php echo $id?>"><? echo $name?></a></span></td>
        <td width="241" bgcolor="#A3D39C"><span class="style19"><? echo $phone ?></span></td>
      </tr>
      <tr>
        <td height="18" colspan="2" bgcolor="#FFFFFF" class="style19"><p class="style19"><? echo $industry ?><br>
        </p>      </td>
      </tr>
    </table>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p align="left"><? echo "<tr>";
    echo 
    "<td>";
    echo 
    "<center>".$first $prev $nav $next $last."</center>";
    echo 
    "</td>";
    echo 
    "</tr>"?></p>
    <? 
    }
    ?>
    </center>
    <?
    $i
    ++;

    echo 
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •