Jump to content

dlyles

Members
  • Posts

    41
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dlyles's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi all, I am using the below coding for a full text search. It works fine on my other search page, but it's not workign here. Any suggestions? I pasted the sql in phpmyadmin and got no results, however I KNOW that there's matching data. case "search": searchForm(); echo '<font size=3 face=arial>Search Results:</font><br />'; $searchstring = mysql_escape_string($_GET['words']); switch($_GET['mode']) { case "normal": $sql = "SELECT *, MATCH(shelf) AGAINST ('$searchstring') AS score FROM parts WHERE MATCH(shelf) AGAINST ('$searchstring') ORDER BY score DESC"; break; case "boolean": $sql = "SELECT *, MATCH(shelf) AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM parts WHERE MATCH(shelf) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC"; break;
  2. Ok, I've gotten almost where I need to be.  Here's the problem.  Everything APPEARS to be working but it's only working for one particular search word (I dont understand why) and one result.  I'm confused as to why that's happening, so here's what I'm using.  Straight for the tutorial on this site. [code] function searchForm() {   // Re-usable form     // variable setup for the form.   $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');   $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );   $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );     echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';   echo '<input type="hidden" name="cmd" value="search" />';   echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';   echo 'Mode: ';   echo '<select name="mode">';   echo '<option value="normal"'.$normal.'>Normal</option>';   echo '<option value="boolean"'.$boolean.'>Boolean</option>';   echo '</select> ';   echo '<input type="submit" value="Search" />';   echo '</form>'; } // Create the navigation switch $cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : ''); switch($cmd) {   default:     echo '<h1>Search Database!</h1>';     searchForm();     break;       case "search":     searchForm();     echo '<h3>Search Results:</h3><br />';         $searchstring = mysql_escape_string($_GET['words']);     switch($_GET['mode'])     {       case "normal":         $sql = "SELECT PartName, description,                MATCH(PartName, description)                AGAINST ('$searchstring') AS score FROM parts               WHERE MATCH(PartName, description)                AGAINST ('$searchstring') ORDER BY score DESC";       break;             case "boolean":         $sql = "SELECT PartName, description,                MATCH(PartName, description)                AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM parts                WHERE MATCH(PartName, description)                AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";       break;     }          // echo $sql;         $result = mysql_query($sql) or die (mysql_error());         while($row = mysql_fetch_object($result))     {       echo '<strong>Title: '.stripslashes(htmlspecialchars($row->PartName)).'</strong><br />';       echo 'Score:'. number_format($row->score, 1).' <br />';       echo '<p>'.stripslashes(htmlspecialchars($row->description)).'</p>';       echo '<hr size="1" />';     }   break; } ?> </body> </html> [/code]
  3. I did that and get the following: Parse error: syntax error, unexpected T_VARIABLE in /var/opt/data/rgbdata/apache/htdocs/theindex.php on line 5 I also put this query into phpmyadmin and got this #1191 - Can't find FULLTEXT index matching the column list I checked and confirmed that the fields have been set for FULLTEXT.  any ideas?  anybody HELP :(
  4. I've done that already.  But still...
  5. Ok, I've looked. I created my indexes and have the following code (that isn't working). I used the word "work" as a test word to search for. [code]       $sql = "SELECT PartName, description MATCH(PartName, description)                AGAINST ('work' IN BOOLEAN MODE) AS score FROM parts                WHERE MATCH(PartName, description)                AGAINST ('work' IN BOOLEAN MODE) ORDER BY score DESC"; [/code]
  6. Ok, I worked through this problem, but what I'm wondering is how can I take a phrase like "HP Workstations computer" and look for anything with any word.  Not the words as a phrase, but any word or combination.
  7. Ok, I would like to do a basic search using a keyword.  I'm trying to query the db for a like match, but I think my like statement is wrong. [code] $query="select * from parts where PartName LIKE '%$model%' "; [/code] Any ideas? Also, if someone can point me in a good direction as to doing a better search.
  8. Never mind.  I forgot to include [code] $row = mysql_fetch_assoc($newresult); [/code] Thanks.  and for the debugging tip.
  9. Ok, will do. Because things are still screwed up  ???.  I am now getting it to add to the db when it should and it tells me it added.  When it should update it tells me it updated, but it doesn't.  I'm telling it to add the old balance to the current amoundreceived where the partname equals the partname in the form.  If I have it insert all the data, it will.  Since I only want the new balance it tells me when I echo the statement that it's updating the balance to "50" when the old balance was 50 and the new amountreceived is 50.  Meaning the balance s/b 100.  What the heck am I doing wrong? here's what I have [code] $sql = "insert into receiveditems (ReceivedAmount, ReceivedNote, ReceivedBy, InspectedBy, ReceiveDate)           VALUES ('" . mysql_real_escape_string($_POST['amountreceived']) .                       "', '" . mysql_real_escape_string($_POST['comments']) .                       "', '" . mysql_real_escape_string($_POST['receiveby']) .                       "', '" . mysql_real_escape_string($_POST['inspby']) .                       "', '" . mysql_real_escape_string($_POST['recdate']) . "')"; $result = mysql_query($sql) or die("Error 1: query: $sql<br>" . mysql_error()); echo "1 record added"; $partname=mysql_real_escape_string($_POST['partname']); $newquery="select * from parts where PartName = '" . $partname . "'"; $newresult=mysql_query($newquery); $count=mysql_num_rows($newresult); if($count == 0){ $sql = "insert into parts (GroupID, ModelID, PartName, Cost, balance)           VALUES ('".$mygroup."',                       '".$mymodel."',                       '".mysql_real_escape_string($_POST['partname'])."',                       '".mysql_real_escape_string($_POST['cost'])."',                       '".mysql_real_escape_string($_POST['amountreceived'])."')"; $nresult = mysql_query($sql) or die("Error 2: query: $nsql<br>" . mysql_error()); echo "Insert record added"; } else { $oldbalance = mysql_real_escape_string($_POST['amountreceived']); $balance = $row['balance'] + $oldbalance; $sql = "update parts set balance = '" . $balance . "' where PartName = '" . $partname . "'"; $newwresult=mysql_query($sql); echo $sql; // $nresult = mysql_query($sql) or die("Error 3: query: $sql<br>" . mysql_error()); echo "Update record added"; } [/code]
  10. Never mind.  I found my problem.  I was trying to update where I should've inserted.  So once you sent the corrected code, it was trying to update a non-existing record. Thanks.
  11. Good point, however I'm still not getting this Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/opt/data/rgbdata/apache/htdocs/receiveaction.php on line 28 from [code] $row = mysql_fetch_assoc($newresult); [/code] Removing this line brings me back to no data being inserted.
  12. I'm trying to run two queries to update two tables bases on one form.  Below is the code [code] $sql = "insert into receiveditems (ReceivedAmount, ReceivedNote, ReceivedBy, InspectedBy, ReceiveDate)           VALUES ('" . mysql_real_escape_string($_POST['amountreceived']) .                       "', '" . mysql_real_escape_string($_POST['comments']) .                       "', '" . mysql_real_escape_string($_POST['receiveby']) .                       "', '" . mysql_real_escape_string($_POST['inspby']) .                       "', '" . mysql_real_escape_string($_POST['recdate']) . "')"; $result = mysql_query($sql) or die("Error 2: query: $sql<br>" . mysql_error()); echo "1 record added"; $partname=mysql_real_escape_string($_POST['partname']); $newquery="select * from parts where PartName = '" . $partname . "'"; $newresult=mysql_query($newquery); if ($newresult){ $balance = $row['balance'] + mysql_real_escape_string($_POST['amountreceived']); $sql = "update parts set Group ID = '" . $mygroup . "', partname = '" . mysql_real_escape_string($_POST['partname']) . "', ModelID = '" . $mymodel . "', Cost = '" . mysql_real_escape_string($_POST['cost']) . "', balance = '" . $balance . "'"; echo $sql; // $nresult = mysql_query($sql) or die("Error 2: query: $sql<br>" . mysql_error()); echo "Update record added"; } else { $sql = "insert into parts (GroupID, ModelID, PartName, Cost, balance)           VALUES ('".$mygroup."',                       '".$mymodel."',                       '".mysql_real_escape_string($_POST['partname'])."',                       '".mysql_real_escape_string($_POST['cost'])."',                       '".mysql_real_escape_string($_POST['amountreceived'])."')"; $nresult = mysql_query($nsql) or die("Error 2: query: $nsql<br>" . mysql_error()); echo "Insert record added"; } [/code] The first query that inserts into "receiveditems" works with no problem.  The second echos the result I want but there is no data in the database.  If it's a new record it treats it like a new one and tells me it inserted.  If it's supposed to update it tells me it updated, but it's doing neither.
  13. Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /var/opt/data/rgbdata/apache/htdocs/receiveaction.php on line 24 Line 24 is [code]     VALUES ('" . $mygroup . [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.