Jump to content

NiTx

Members
  • Posts

    31
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    New Zealand
  • Interests
    Web Design
    Film Making
    3D Modeling
    2D Animation
    Motion Graphics
  • Age
    23

NiTx's Achievements

Member

Member (2/5)

0

Reputation

  1. You can't echo operations, You need to use if or else statements. $operation = $_POST['SelectedOperation'] if($operation == 'count') { echo count($array); } elseif ($operation == 'sum') { echo array_sum($array); } You can have as many elseif statements as you require.
  2. Solved the issue. Discovered LEFT JOIN. As with most of my php problems, I just don't know what to search in Google to find the answers to my issue.. For anyone else with the same issue this is how I solved my issue. $sql = "(SELECT devices.id, devices.brand_id, devices.dev_model, devices.dev_version, devices.dev_model_number, devices.dev_release_month, devices.dev_release_year, brands.brand_name FROM devices "; $sql .= "LEFT JOIN brands ON devices.brand_id = brands.id "; $sql .= "WHERE CONCAT(brands.brand_name ,' ', devices.dev_model, ' ', devices.dev_version, ' ', devices.dev_model_number) LIKE '%{$database->escape_values($term)}%' "; $sql .= "ORDER BY devices.dev_release_year DESC, devices.dev_release_month DESC LIMIT 4)";
  3. NiTx

    help

    Sorry to say this but you clearly have no idea what you're doing. You're missing " " around your query. That to any basic php programmer would be obvious. I'd suggest you take the time to learn PHP before asking for help.
  4. It looks like you've been watching Lynda tutorials? Make sure you don't skip any of the videos and try actually MAKE SENSE of what your learning. The error your getting spells it out for you, the fetch_assoc method doesnt exist.. Plain and simple, you need to add it. I will spoon feed you. Add this to your database class. (I've added extras for your convenience) public function fetch_assoc($result_set) { return mysql_fetch_assoc($result_set); } public function num_rows($result_set) { return mysql_num_rows($result_set); } public function fetch_array($result_set) { return mysql_fetch_array($result_set); }
  5. I have two tables, brands and devices. brands table is set up like so: id | brand_name 1 Apple 2 Samsung devices: id | brand_id | dev_model | dev_version 1 1 iPhone 5s 2 2 Galaxy S4 Right now I can search for a phone by its device name, for example: 'iPhone 5s', but I need my users to be able to search for the brand too: 'Apple iPhone 5s'. Is there a practical approach to doing this without having to add the brand names in my device table? This is my current MySQL query: $sql = "(SELECT id, brand_id, dev_model, dev_version FROM devices WHERE "; $sql .= "CONCAT(dev_model, ' ', dev_version) LIKE '%{$database->escape_values($term)}%' "; $sql .= "LIMIT 4)"; Any help would be appreciated, or even a point in the right direction.
  6. Hi, I'm trying to build a search function for my website with a jQuery auto-complete feature implemented. I have three columns I need to search for in my database, dev_model, dev_version and dev_model_number. Right now I'm just focusing on getting the query to work with the first two columns. The auto-complete works, but its far from perfect and gives undesired results at times. I've tried multiple different approaches to building my search query. So far, doing a full text search is working the best but its far from perfect. Here's my MYSQL query: SELECT id, brand_id, dev_model, dev_version, MATCH (dev_model,dev_version) AGAINST ('+" . $database->escape_values($parts[$i]) . "*' IN BOOLEAN MODE) AS SCORE FROM devices WHERE MATCH (dev_model,dev_version) AGAINST ('+" . $database->escape_values($parts[$i]) . "*' IN BOOLEAN MODE) ORDER BY SCORE DESC LIMIT 4 My search page: http://www.fonefox.com/fonefox/public/index1.php If you search for example 'Galaxy S4', as soon as you start typing the 'S4' (dev_version), the autocomplete hides the Galaxy S4 phone from the search. No idea why, but if the 'dev_version' string is greater then 4 characters it WILL work. Another issue is, you could search 'Galaxy S4 Lumia 1020', and it will return results for a Lumia 1020 which has no relevance to "Galaxy" or "S4". I'm guessing that I need to somehow concatenate dev_model and dev_version before comparing my search terms to it. I'm just not sure how to approach this. Any help would be greatly appreciated.
  7. Thanks trq, I see what you mean. I'm trying to get myself familiar with OOP concepts but i'm failing to do so! :S Is pulling in from the global scope a complete no-no? Take my basic find_by_sql function as an example.. Do you not have a database class to make database queries? And if you do, how do you make queries without pulling it in form the global scope? public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } return $object_array; }
  8. All classes that are associated to a table in my database Inherit this class as it contains my Create, Update and Delete functions. So as to save me rewriting that code multiple times in each class. Sorry, I'm still very new to OOP so I wouldn't know why. Seems still viable to me, and to the person who's tutorial I've been watching. I'm all ears though, the tutorials I've been watching are aged and I don't want to start any bad habits early. Your're right. It is only for me but I plan to have admins that could make mistakes. It's really hard to explain what I'm asking you guys without posting a ton of code. I should have spent more time structuring my post as to explain myself better. To put it into perspective.. Lets say you had a database table with 110 columns and a form with 100 fields. You have 60 fields which are required fields, 40 fields that are not required. The remaining 10 variables are generated fields like id, admin_id and date_added etc.. All these different variables have to go through a different process in my code before getting submitted to the database. So have I done the right thing by grouping my variables into arrays so that each group of variables can be processed in the appropriate way?
  9. Hey Guys, I've just started to learn OOP. So far I'm lovin' it, but I want to get some advice. I'm dealing with a form that has around 100 fields and I'm trying to find the most efficient way to work my variables. Here's a small example. class Review extends DatabaseObject { protected static $table_name = "reviews"; public static $required_fields = array( 'security', 'location', 'training', 'comments' ); public static $nonRequired_fields = array( 'pay', 'pay_rate', 'tips' ); public static $generated_fields = array( 'company_id', 'id', 'user_id', 'date_added' ); protected function attributes() { global $company; global $user; $attributes = array(); foreach(self::$required_fields as $field) { if(property_exists($this, $field)) { $attributes[$field] = $this->$field; } } foreach(self::$nonRequired_fields as $field) { if(property_exists($this, $field)) { $attributes[$field] = $this->$field; } } if(isset($_SESSION['user_id'])) { $attributes['user_id'] = $_SESSION['user_id']; } $attributes['company_id'] = $company->company_id; $attributes['total_score'] = $this->total_score; return $attributes; } As you can see I've put these variables into arrays to make form validation easier, but when it comes to instantiating my class, I run into some issues. I know this is most likely a stupid approach. I apologize because I know I haven't really explained what I'm after. I have to be as efficient as possible since I'm dealing with such a large number of form fields and I'm not sure which way is the best approach with OOP. I hope my code is enough for you to get a good enough idea. Please help and thanks
  10. $q = "SELECT * FROM questions WHERE id = '$post'"; should be $q = "SELECT * FROM questions WHERE id = {$post}";
  11. Never used 'continue' before so thanks! Added to my repertoire Again, thank you both!
  12. Thanks requinix, I thought of this, but if my function passes the key ID andits value, I get an error. I could try to alter my function to suit, but it would be a pain in the ass to say the least. Still, thanks for the tip
  13. Hey guys, I'm trying to run a while loop for an array that includes an ID value in each row. I'm trying to temporarily disable that value while I perform a foreach loop, then prepend the value back into the array after the foreach loop is finished. function array_unshift_assoc(&$arr, $key, $val) { $arr = array_reverse($arr, true); $arr[$key] = $val; $arr = array_reverse($arr, true); } So far I've come up with this function (which works), but I feel like there may be an easier way? Rest of my code is below. Thoughts? while($row = mysql_fetch_assoc($get_specs)) { //Set the phones id to a temporary variable. $tempid = $row['id']; //Unset the id so that we can perform the foreach loop without //it interfering with the function. unset($row['id']); foreach($row as $spec => $value) { get_spec_rating($spec, $value); echo $rating . "<br/><br/>"; } //Unshift the id value back into the array array_unshift_assoc($row, "id", $tempid); } Thanks!
  14. Just goes to show you can only learn so much on lynda.com. My coding skills are still at a rudimentary level, so thanks! Will definitely read up some more on the implode. Given all the large arrays I use, I think it will come in handy! Nice to know I was on the right track! Thanks for introducing me to this, I've seen it used before but didn't know what to search in google. I did some reading on it just now, would you say it's mainly used for smaller if else statements like mine and that for a larger argument you would just use an ELSE IF? Again thanks a ton!
×
×
  • 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.