#1
  1. No Profile Picture
    jasj
    Guest
    Devshed Newbie (0 - 499 posts)
    Does anyone know where I can find a very functional module/class/script that's pre-written in PHP for a MySQL/SQL database?

    Thanks for your time.

    John
  2. #2
  3. No Profile Picture
    Ulf.Wendel
    Guest
    Devshed Newbie (0 - 499 posts)
    Hi John,

    phplib.netuse.de provides you database abstraction and many other great things.
    It will be easy to to database queries using it.

    Ulf
  4. #3
  5. No Profile Picture
    jasj
    Guest
    Devshed Newbie (0 - 499 posts)
    Bleh. The web site's a bit confusing and all the documentation is written as if I were running my own server (which I'm not). Any other suggestions or helpful hints?

    My main goal is to create a keyword search (both exact word and boolean) on a MySQL database.

    Thanks again.

    John
  6. #4
  7. No Profile Picture
    A T Clarke
    Guest
    Devshed Newbie (0 - 499 posts)
    I asked the same thing, albeit with a few more words, earlier. Checked with the resident PHP "expert" at my hosting outfit, and PHPLIB is 'unworkable' under such an environment. So I second this: any alternatives by way of classes/functions/tips in general that piece together many of the perks of PHPLIB? In my case, I need session management... badly...

    jasj: If you're just looking for simple boolean/word searches, check out

    http://px.sklar.com/

    They have a few sets of classes/functions primed for these sorts of searches under the database script archive.
  8. #5
  9. No Profile Picture
    Robman
    Guest
    Devshed Newbie (0 - 499 posts)
    You might try http://www.phpbuilder.com
  10. #6
  11. No Profile Picture
    Randy
    Guest
    Devshed Newbie (0 - 499 posts)
    You might want to take a look at the current featured clipscripts, UdmSearch. It uses PHP and MySQL along with a C-based indexer. If nothing else, you should be able to find some good methods of searching a mysql database there.

    Randy
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    16
    Rep Power
    0
    I know this is an old thread, but I've been trying to modify a piece of php to work with my database to do a keyword search with and, or, and not, but I can't get it to work. The database connnection is fine; I just get the "There was a problem with the query syntax" error. So I guess there is something wrong with the contents of the variable $strWhere but I can't figure what.

    Any nice person out there want to help me? Or else refer me to a decent piece of php that will get me started setting up keyword searching?

    Thank you, nice person!

    This is the whole thing:
    <?
    if ($search) {
    echo "<tr><td colspan=2 align=center>Search for: $search</td></tr><tr colspan=2><td></td></tr>";
    $dbname="*******";
    $dbserver="******";
    $dbuser="*******";
    $dbpass="*******";
    $arrSearch=explode(" ", $search);
    for ($i=0; $i<count($arrSearch); $i++) {
    if (strToUpper($arrSearch[$i])=='AND' or strToUpper($arrSearch[$i])=='OR' or strToUpper($arrSearch[$i])=='NOT') {
    if (strToUpper($arrSearch[$i])=='NOT') {
    $i++;
    $strWhere=$strWhere." and not like '%".$arrSearch[$i]."%'";
    } else {
    $strWhere=$strWhere." ".$arrSearch[$i]." ";
    }

    } else {
    $strWhere=$strWhere." like '%".$arrSearch[$i]."%'";
    }

    }

    $cn=mysql_connect($dbserver, $dbuser, $dbpass);
    mysql_select_db($dbname,$cn);
    $sql="SELECT * FROM Articles WHERE ".$strWhere." ORDER BY ID";
    $rsCat_query=mysql_query($sql, $cn);

    if (!(mysql_errno()==0)) {
    echo "<tr><td colspan=2 align=center><big>There was a problem with the query syntax</big></td></tr>";
    echo "<tr><td colspan=2 align=center><a href=search.php3>Back</a></td></tr></table>";
    exit;
    }

    if (mysql_num_rows($rsCat_query)==0) {
    echo "<tr><td colspan=2 align=center><big>No items were found matching the criteria</big></td></tr>";
    echo "<tr><td colspan=2 align=center><a href=search.php3>Back</a></td></tr></table>";
    exit;
    }

    while($rsCat = mysql_fetch_array($rsCat_query)) {
    ?>

    <tr><td>Iterate through your fields here</td></tr>
    <tr><td>Field_1 Value:</td><td><? echo $rsCat["ArticleText"] ?></td></tr>


    <?
    }
    } else {
    ?>

    <form action=search.php3 method=post>
    <tr><td align=center colspan=2>&nbsp;&nbsp;<input type=text name=search id=search size=25>
    <input type=submit name=submit value=Submit></td></tr>
    <tr><td colspan=2 align=center>Enter the criteria you wish to search for. The search is not case sensitive.</td></tr>
    <tr><td colspan=2 align=center>You may use 'And' or 'Or' or 'Not' between keywords.</td></tr>
    <tr><td align=right width=100>Example 1:</td><td>this and that</td></tr>
    <tr><td align=right>Example 2:</td><td>this not that</td></tr>
    <tr><td align=right>Example 3:</td><td>this and that not those</td></tr>
    <tr><td align=right>Example 4:</td><td>this and that or those</td></tr>
    </form>
    </table>
    <? } ?>
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    This is one that I wrote that works great and fast, feel free to use it and modify it for your own uses:
    ##################################################################################

    function Display_Search_Results($searchwords, $offset) {
    global $dbhost, $dbuser, $dbpass, $dbname, $db, $result, $myrow, $dbrow1, $dbrow2, $rowcolor, $PHP_SELF, $delim, $i, $count;
    //Setup initial delimiter
    if (eregi("and", $searchwords)) {
    $delim = "and";
    $takeout = "and";
    $boolean = 1;
    }
    elseif (eregi("or", $searchwords)) {
    $delim = "or";
    $takeout = "or";
    $boolean = 1;
    }
    else {
    $delim = "and";
    }
    $realsql = "SELECT * from listings where ";
    $countsql = "SELECT count(ID) as num from listings where ";
    if ($boolean == 1) {
    $query = eregi_replace("$takeout", ",", $searchwords);
    $query = strtolower($query);
    $query = split(",", $query);
    } else {
    $query = strtolower($searchwords);
    if (count ($query) == 1) {
    $query = split(" ", $query);
    }
    }

    $count = count ($query);
    for ($i=0; $i < count ($query); $i++) {
    if ($i < (count ($query) - 1)) {
    $sql .= '((Name like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(City like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(Address like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(Type like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(Metawords like '%'. trim($query[$i]) .'%')) ';
    $sql .= $delim .' ';
    } else {
    $sql .= '((Name like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(City like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(Address like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(Type like '%'. trim($query[$i]) .'%') OR ';
    $sql .= '(Metawords like '%'. trim($query[$i]) .'%'))';
    }

    }
    $sql = ereg_replace(".$delim.$", "", $sql);
    $statusdo = " AND (status = '1') ";
    $countsql = $countsql.$sql.$statusdo;

    $limit = 15;
    $numresults = mysql_query("$countsql", $db);
    $numrows = mysql_result($numresults, 0, num);

    // next determine if offset has been passed to script, if not use 0
    if (!isset($offset)) {
    $offset=0;
    }
    $newsql = $realsql.$sql . " AND (status = '1') ORDER by Name LIMIT " . $offset .",". $limit;
    //print $countsql ."<br>";
    //print $newsql ."<br>";
    if (!($db = mysql_connect($dbhost, $dbuser, $dbpass))) echo "error connecting to ". $dbname ."on ". $dbhost;
    mysql_select_db($dbname,$db);
    $result = mysql_query("$newsql", $db);
    $dbrow1 = "#ffffff";
    $dbrow2 = "#eeeeee";
    $rowcolor = $dbrow1;
    printf('<table width=%s cellspacing=0 cellpadding=6 border=0>', "100%");
    printf('<tr><td colspan=2><h1>%s</h1></td></tr>', ucwords($type));
    print "<tr><td colspan=2><hr></td></tr>n";

    if (mysql_num_rows($result) > 0) {
    printf('<tr align="center"><td colspan=2 align="center"><span class="category">%s listings found for %s</span></td></tr>%s', $numrows, $searchwords, "n");
    if ($numrows > $limit) {
    // calculate number of pages needing links
    $pages=intval($numrows/$limit);

    // $pages now contains int of pages needed unless there is a remainder from division
    if ($numrows%$limit) {
    // has remainder so add one page
    $pages++;
    }
    if (($offset + $limit) > $numrows) {
    $lastnum = $numrows;
    }
    else {
    $lastnum = ($offset + $limit);
    }
    printf('<tr><td colspan=3 align="center"><span class="listing">Showing records <b>%s - %s</b></span></td></tr>', ($offset + 1), $lastnum);
    print '<tr><td colspan=3><table align="center" cellspacing="0" cellpadding="4" border="0"><tr><td><span class="listing">Page </span></td>';

    for ($i=1;$i<=$pages;$i++) { // loop thru
    $newoffset=$limit*($i-1);
    if ($newoffset != $offset) {
    printf('<td><a href="%s?offset=%s&searchwords=%s&city=search">%s</a></td>%s', $PHP_SELF, $newoffset, $searchwords, $i, "n");
    }
    else {
    print "<td><span class=offset>". $i ."</td></span>";
    }
    }
    print '</tr></table></td></tr>';
    }
    while ($myrow = mysql_fetch_array($result)) {
    if ($myrow["Name"] == "") $myrow["Name"] = '&nbsp;';
    if ($myrow["Address"] == "") $myrow["Address"] = '&nbsp;';
    if ($myrow["Phone"] == "") $myrow["Phone"] = '&nbsp;';
    if ($myrow["map"] == "") {
    $maplink = "";
    }
    else {
    $maplink = sprintf('<a href="maps/maptest.phpid=%s">View on map</a>', $myrow["ID"]);
    }
    if ($myrow["URL"] == "none") {
    print '<tr bgcolor='. $rowcolor .'>';
    printf('<td width="%s"><span class="basic"><b>%s</b></span><br><span class="listing-detail">%s</span></td>%s', "70%", $myrow["Name"], $myrow["Address"], "n");
    printf('<td width="%s"><span class="listing-detail">%s</span><br><span class="listing-detail">%s</span><br>%s</td>%s', "30%", $myrow["City"], $myrow["Phone"], $maplink, "n");
    print '</tr>';
    }
    else {
    print '<tr bgcolor='. $rowcolor .'>';
    printf('<td width="%s"><a href="http://%s" target="_blank">%s</a><br><span class="listing-detail">%s</span></td>%s', "70%", $myrow["URL"], $myrow["Name"], $myrow["Address"], "n");
    printf('<td width="%s"><span class="listing-detail">%s</span><br><span class="listing-detail">%s</span><br>%s</td>%s', "30%", $myrow["City"], $myrow["Phone"], $maplink, "n");
    print '</tr>';
    }
    //Change row colors
    if ($rowcolor == $dbrow1) {
    $rowcolor = $dbrow2;
    } else {
    $rowcolor = $dbrow1;
    }
    $i++;
    }//End while statement

    print '</table>';
    }//End search results

    ##################################################################################
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    16
    Rep Power
    0
    Wow. I really appreciate it, but I need the bozo version. I tried my best to tweak it, but I just couldn't figure out.

    All I'm trying to do is search for keywords using and, or, not in two text columns of a single mysql table in a single database.

    Is it better/faster to have some kind of function that sucks the keywords out and sticks them in their own little lookup table?

    I also tried the Quick and Dirty search engine tutorial, but it's all about blobs and I don't have any blobs, just text in a database table.

    Thanks again.

Similar Threads

  1. Highlight search result from mysql database search
    By Gurt in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 04:39 AM
  2. Check MySQL Version thru PHP
    By wolftrap1 in forum PHP Development
    Replies: 2
    Last Post: February 11th, 2004, 09:51 PM
  3. Replies: 5
    Last Post: February 3rd, 2004, 02:59 PM
  4. Replies: 0
    Last Post: January 31st, 2004, 03:15 AM
  5. Replies: 0
    Last Post: January 30th, 2004, 02:22 PM

IMN logo majestic logo threadwatch logo seochat tools logo