Jump to content

darkminos

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

darkminos's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm not sure but your problem might be the function below or the SQL query within it, although what you are trying to do may seem similar, the function viewUserHouses($option) and showCategory( $catid, $printItem) a completely different to each other... function showCategory( $catid, $printItem ) { ... } Hope this helps...
  2. Works perfectly, thank you very much!
  3. Ok... I see now, in_array is looking for an exact match... while what I have to do is probably divide $keyword and $myArray into strings and compare this way... am I on the right track?
  4. Yes, it will update a textbox, on the following page... Unlike Javascript, PHP requires the page to be reloaded in order for the script to be re-run by the server. Not sure if Javascript is your only option, but probably the best/easiest.
  5. Should it not be foreach ($myArray as $subArray) { if(in_array($keywords, $subArray['title']) ) { var_dump($subArray); } } Anyhow ... no results displayed. This is what the array looks like array(925) { [0]=> array(9) { ["pic"]=> string(53) "http://ecx.images-amazon.com/images/I/21HPIhRQNFL.jpg" ["link"]=> string(225) "http://www." ["from"]=> string(6) "A" ["title"]=> string(99) "20 x 18W, PAR38, AC100-240V, E27 Edison ES, LED Lamp, Warm White, 75W-100W Equivalent, Non-Dimmable, Bulb" ["cost"]=> string(6) "7.80" ["description1"]=> string(37) "Direct replacement for 75W-100W bulbs" ["description2"]=> string(23) "Energy saving up to 80%" ["description3"]=> string(18) "High quality light" ["category"]=> string(3) "LED" } And now if the search keyword is "led bulb" it should look for "led" and "bulb" in the ['title'], if one of the keywords is identified the result should be positive.
  6. Thanks for the reply, unfortunately in_array doesn't work with multidimensional arrays...
  7. Nope, results are pulled from various websites, serialized into multiple files, on search - unserialized into one array and sorted. And now I want to display only the results of an array which ['title'] contains 'oil OR painting'
  8. Hi, I have a multidimensional (2 levels) array and would like to filter the results where: $myArray[$i]['title'] = '$keywords' Basically I want the filter to only display results which contain any of the $keywords in the title
  9. Very interesting, I had almost exactly the same function before and changed it as it was messing up my array_multisort(), now I know it was due to lack of re-indexing after the duplicates are removed. Thanks for that
  10. Hi, another simple one which I can't work out: I have a function to remove duplicates from an array, however I need to modify it to remove duplicates by 'title' if ( !function_exists( "arrayUnique" ) ){ function arrayUnique ( $rArray ){ $rReturn = array (); while ( list( $key, $val ) = each ( $rArray ) ){ if ( !in_array( $val, $rArray ) ) array_push( $rReturn, $val ); } return $rReturn; } } Array format: Array ( [0] => Array ( [pic] => 1.jpg [link] => http:// [from] => shop [title] => title1 [cost] => 0.01 [description1] => asd [description2] => fgh [description3] => jkl [category] => LED ) [1] => Array ( [pic] => 1.jpg [link] => http:// [from] => shop [title] => title [cost] => 0.01 [description1] => asd [description2] => fgh [description3] => jkl [category] => LED ) [2] => Array ( [pic] => 1.jpg [link] => http:// [from] => shop [title] => title1 [cost] => 0.01 [description1] => asd [description2] => fgh [description3] => jkl [category] => LED ) So... what the function needs to do is to look at the titles and remove duplicated entries containing the same title. (if this makes sense) From the array above one of the entries containing '[title] => title1' should be removed leaving the following: Array ( [0] => Array ( [pic] => 1.jpg [link] => http:// [from] => shop [title] => title1 [cost] => 0.01 [description1] => asd [description2] => fgh [description3] => jkl [category] => LED ) [1] => Array ( [pic] => 1.jpg [link] => http:// [from] => shop [title] => title [cost] => 0.01 [description1] => asd [description2] => fgh [description3] => jkl [category] => LED ) Order is irrelevant.
  11. Perhaps you are very right sir How embarrassing... For anyone interested in the full solution: $directory = "cache/"; $filecount = count(glob($directory . "*")); //echo $filecount; $allFiles = scandir($directory); $files = array_diff($allFiles, array('.', '..')); foreach($files as $file) { $un[] = unserialize(file_get_contents("cache/".$file."")); } foreach ($un as $num => $entry) { if ($num == sizeof ($un)-1) continue; if (isset ($un[$num]) && isset ($un[$num+1])) { if (isset ($res)) $res = array_merge ($res, $un[$num], $un[$num+1]); else $res = array_merge ($un[$num], $un[$num+1]); } } if ( !function_exists( "arrayUnique" ) ){ function arrayUnique ( $rArray ){ $rReturn = array (); while ( list( $key, $val ) = each ( $rArray ) ){ if ( !in_array( $val, $rReturn ) ) array_push( $rReturn, $val ); } return $rReturn; } } $myArray = arrayUnique ($res); This will get all the serialized data from all files in a folder, merge them in one array, and remove duplicates
  12. Hi, What I am looking at now is to unserialize multiple files while adding them into an array: $directory = "cache/"; $filecount = count(glob($directory . "*")); $allFiles = scandir($directory); $files = array_diff($allFiles, array('.', '..')); $i=0; foreach($files as $file) { $un = unserialize(file_get_contents("cache/".$file."")); $i++; .......???????????????????? echo "<br>".count($all_results)."<br>"; } Any ideas? because I run out of them... file output format: Array ( [0] => Array ( [pic] => 1.jpg [link] => http:// [from] => shop [title] => title [cost] => 0.01 [description1] => asd [description2] => fgh [description3] => jkl [category] => LED )
  13. Ok... I can't believe how simple the solution was... echo "<input type=hidden name=search value=".$_GET['search'].">"; I was trying to send the actual variable in the name field... It was good to be educated on some of the changes done since PHP3 Thank you for the help!
  14. Right, sorry I should have explained better. Looks have nothing to do with my problem. the last time I done php is 10 years ago and see some differences, like the variable carried over in the URL is not always accessible by just calling it $some_variable, now I have to $_GET['some_variable']... not always however. Now, when I have some_variable=something in the URL I can get it no problem with $some_variable, however when I have some_variable%3Dsomething I can't get it. I hope this makes sense.
  15. I mean, is there a way for the browser to show = rather than %3D?? there is too much happening within the script for me to change all of the variables to urlencode()
×
×
  • 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.