Jump to content

tully87

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tully87's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks WebStyles !!!!!! It worked....had to change the ' ' marks in explode('',$kwords); to " " marks but other than that it works a treat. Thank you so much
  2. <?php $items = odbc_exec($odbc, "SELECT keywords FROM faq WHERE visible = 'true'") or die (odbc_errormsg()); while ($detail = odbc_fetch_array($items)) { $exploded = explode(" ",$detail['keywords']); $unique = array_unique($exploded); foreach($unique as $unique) { var_dump($unique); } } ?>
  3. I'm trying to search a "keywords" field in a Microsoft Access database which can contain more than one word. E.g. "Cat", "Dog", "Cat Dog" etc. All of the keywords will then be listed on a page and when clicked will display any record containing that keyword. The problem I'm having is getting only one isntance of each word displayed and cannot figure out how to do it. So with the example "Cat", "Dog", "Cat Dog", "Mouse Dog" the only listed words should be "Cat" "Dog" "Mouse". When using the following code: <?php $items = odbc_exec($odbc, "SELECT keywords FROM faq WHERE visible = 'true'") or die (odbc_errormsg()); while ($detail = odbc_fetch_array($items)) { $exploded = explode(" ",$detail['keywords']); $unique = array_unique($exploded); foreach($unique as $unique) { var_dump($unique); } } ?> It returns: string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" string(3) "Dog" string(3) "Cat" string(3) "Dog" string(3) "Cat" string(3) "Dog" string(3) "Cat" string(5) "Mouse" string(3) "Cat" string(3) "Dog" I've attached a word document of other examples I have tried but with no luck If anyone can provide any help I'd really appreciate it. Many thanks [attachment deleted by admin]
  4. Thanks, I do want to remove duplicates from that array as I want to then link each single "keyword" to any record that contains that word. I tried $distinct = array_unique($splitcategory); but unfortunately it didnt work. If I use: $splitcategory = preg_split('/ /', $category); print_r($splitcategory) I get: Array ( [0] => Archive ) Array ( [0] => Calendars ) Array ( [0] => P&V) Array ( [0] => P&V[1] => Test ) Array ( [0] => ICQ ) Array ( [0] => Macro ) Array ( [0] => Mailbox ) Array ( [0] => Printing ) Array ( [0] => Signature ) Array ( [0] => Workbook )
  5. Apologies but I'm quite new at using PHP and need some help From an Access Database I want to search a field for "keywords". However one record can have multiple "keywords" so I want to search this field, select the distinct values, split them wherever a space occurs, put this list of values (a string) into an array and then select the distinct values again. The code I have so far is: <?php $items = odbc_exec($odbc, "SELECT DISTINCT keywords FROM faq WHERE visible = 'true'") or die (odbc_errormsg()); echo "<span class=titles'>FAQ Categories</span><br /><br />"; while ($detail = odbc_fetch_array($items)){ $category = $detail['keywords]; $splitcategory = preg_split('/ /', $category); foreach($splitcategory as $categories) { echo "$categories"; } echo ("<a href='index.php?l1=support&l2=faq&l3=catdetail&cat=".urlencode($detail['keywords'])."'>".$detail['keywords']."</a><br />"); } ?> So when I "echo $categories" I get: ArchiveCalendarsICQMacroMailboxP&VP&VTestPrintingSignatureWorkbook - (P&V Test) are in the same record So what I need to do (I think) is put these in an array and then select the distinct values but I can't figure out how to create an array and populate it with $category. Any ideas? Please note that the database only contains a sample of data at the minute and will continue to be updated regularly so the number of values in $category will never have a set amount.
×
×
  • 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.