Jump to content

littlea5h

Members
  • Posts

    13
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

littlea5h's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. With this code... Computer Systems in URL: Array ( [0] => [1] => systems[2] => computer-systems [3] => ) 1 Commun/networking in URL: Array ( [0] => [1] =>systems [2] => commun-networking [3] => ) 1
  2. Does not work as search and replace works backwards for some reason :s
  3. Thanks a bunch! I tested it for the '/' and it worked like a charm but i needed it for the space aswell, so after fiddling around,i put it inside an array again and I changed it to this: $char = array("/"," "); $name = str_replace("-", $char, $request[2]); $id = $category->find_id_by_name($name); However it doesnt work either, displays that error i stated above so i used the index to get the forward slash and it worked: e.g $name = str_replace("-", $char[0], $request[2]);<-- works for forward slash but not space $name = str_replace("-", $char[1], $request[2]);<-- works for space but not forward slash I just can't seem to get them to work together!! And from your example you have shown me, $request[2] is not shown but this is needed as this is where the data is, it would really help me out much if my code above was used
  4. So i am trying to replace spaces and forward slashes in a url with a hyphen. Say we have a website named: www.example.com/car/bmw/porsche where bmw/porsche is one value I can seem to get it to work for a space but having trouble with the forward slash. This is what i have for the space (yes i know the search and replace are at opposite ends but it seems to work and doesn't work if i swap them round) $name = str_replace("-", " ", $request[2]); $id = $category->find_id_by_name($name); I tried a number of ways to make it work but it still doesn't seem to want to listen.. these are the ways i have tried but neither work: 1. $name = str_replace("-", array(" ", "/"), $request[2]); $id = $category->find_id_by_name($name); 2. $chars = array(" ", "/"); $name = str_replace("-", $chars, $request[2]); $id = $category->find_id_by_name($name); Both which produce the error:- Notice: Array to string conversion 3. $name = str_replace(array("-","//"), " ", $request[2]); $id = $category->find_id_by_name($name); In the above code, space works but not the forward slash. Tried changing the forward slash to a single one, single quotes with both one and two slashes but still nothing. I have spent a good couple of hours fiddling around with it but nothing seems to work
  5. So i have a car database storing parts for cars and i am in the process of creating a page which will store unique data for each car part chosen from another page(not yet created), at the moment i am just testing via the URL. This may be clear to me in the form of flat PHP but i am creating it with an MVC framework which makes it all the more complicated, i am still a noob in this area. Well the page which stores the unique data has two drop down menus for that particular part, such as the vehicle model and vehicle brand. I have created the view page, but it is the controller i am having the problems for. The other problem now is that there is way too much code for this to post here and they all connect together but im thinking if ur a PHP pro, you may have some general idea of how to go about this without looking at all the code?This is what i have for my controller so far: class CarController extends Zend_Controller_Action { public function indexAction(){ $category = new Application_Model_CarMapper(); $gcat = $this->getRequest()->getPathInfo(); //get id $id = $category->find_id_by_name($gcat); $this->view->title = $category->get_sub_cat_select($id); } } And it comes from the following query: public function find_id_by_name($name){ $select = $this->getDbTable()->query("SELECT * FROM car_category WHERE category_name = '{$name}'"); $result = $select->fetchAll(); if(!$result) { return; } return $result[0]["ID"]; } It is the controller class i am looking to change rather than the query itself. I am testing it out by the title but it just doesnt seem to display at all. I would like it to display the drop down menus for the specific category, e.g car-live.local/cars/Volvo ---> "Welcome to the Volvo Car Finder" car-live.local/cars/BMW ---> "Welcome to the BMW Car Finder" I know it is not working as i have to split down the URL even more, as right now it is finding the id via the URL, but i am unsure how to do this :s Any light you can shed on this would be extremely grateful.. Thanks.
  6. I have tried to alter the code to a fulltext search. As i stated previously, the code i posted earlier was not fulltext as i have not come across the method. I changed the code to this however it still doesnt seem to be working. It just displays the message that shows up to the user that they can not find the keyword. $statement_front = "SELECT * FROM p2_parts p INNER JOIN p2_parts_category c ON p.partNumber = c.partNumber WHERE"; $sql = $statement_front." MATCH (p.manufacturer,p.description) AGAINST ('+{$description} IN BOOLEAN MODE') AND p.description LIKE '%{$description}%' OR c.category LIKE '%{$description}%' LIMIT 200"; $select = $db->query($sql); $results = $select->fetchAll(); Instead of the user wanting to type in the full keyword, i would like it so that they would only enter part of a keyword so it shows something similar. E.g 'key' would display 'keyboard' or 'board' would display 'motherboard, 'keyboard' etc
  7. Hey guys, i am trying to implement this piece of code around a full text search but i havent worked with them before. I want that the user doesnt have to enter all of the keyword entered, so they can type half the keyword and it will still display the result. This is what i have so far! public function fetchAllByDescription($description){ $db = Zend_Db_Table::getDefaultAdapter(); $statement_front = "SELECT * FROM p2_parts p INNER JOIN p2_parts_category c ON p.partNumber = c.partNumber WHERE"; $sql = $statement_front." p.description LIKE '%{$description}%' OR c.category LIKE '%{$description}%' LIMIT 200"; $select = $db->query($sql); $results = $select->fetchAll(); if (0 == count($results)) { return; } $products = array(); foreach($results as $r) { if(isset($r['ID'])){ $products[] = $this->find($r['ID']); } } return $products; } Any help would be appreciated. Thanks!
×
×
  • 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.