Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. actually wait I take that back, that's a list of exact matches...1s
  2. here is a more complete example: if (isset($_GET['description'])) { $description = explode(" ",urldecode($_GET['description'])); $description = array_map('mysql_real_escape_string',$description); $description = "'".implode("','",$description)."'"; $sql = "SELECT * FROM productdbase WHERE description IN ($description)"; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($res)) { echo $row['description'] . "<br/>"; } }
  3. if (isset($_GET['description'])) { $description = explode(" ",urldecode($_GET['description'])); $description = array_map('mysql_real_escape_string',$description); $description = "'".implode("','",$description)."'"; $sql = "SELECT * FROM productdbase WHERE description IN ($description)"; echo $sql; }
  4. No offense, but neglecting to mention what you are trying to do, what values you are testing is not a coding issue, it's a common sense issue. You told me you were testing with "test"! You are not helping me help you! = is an exact match operator in SQL . % only works with regex or 'contains' type operators, for example SELECT * FROM productdbase WHERE description LIKE '%lukas%' What exactly are you wanting to do here, return results for any of the words, like "foo bar" will return "some foo description" "some bar description" or does it have to contain both words, but can occur anywhere, like "some foo description bar"
  5. You have got to be shitting me. Why didn't you mention this before?
  6. okay, well "search" is arbitrary, what code is behind this action? Compare your search code to this new code. Is it using the same database connection info? same database? same table? etc..
  7. I really wish you'd stop with the "..but it works with ID!" it's starting to get pretty annoying... the code is similar but different in many ways, it is NOT the same code. And on that note, you need to focus here and catch on to the whole debugging process. Line by line, compare the differences between the two scripts, setup points to test at each difference. Test by echoing out the relevant variables, etc.. So you have queried your database directly and got 0 results. As spiderwell mentioned, are you querying the right table? do you see a value of 'lukas' in your description column in your table (example, SELECT description FROM productdbase to get a dump of all description values with no where clause)
  8. Okay you got me phil, that one-liner is way more complicated from a readability perspective. But to be fair, I was speaking from a "more steps than necessary" perspective. But anyways.. don't be jealous!
  9. $sql = "SELECT * FROM productdbase WHERE description = '$description'"; echo $sql; // <--- add this line here Now copy and paste what it is output. Login to your mysql database, like through phpmyadmin. Go to the database and productdbase table and click on the SQL button and paste that query in and run the query. Do you get results returned?
  10. good job Jay, but IMO you unnecessarily complicated it. No need to group that additional ([^\d]*) and use extra matched index. Also that would technically match non-alphanumeric chars. Probably not a concern but may as well be more efficient and explicit since it is assumed that the prefix are alpha only. Also, because I was exceedingly bored, I one-lined it: $string = "CX1,CX2-6,CX7,CX9-CX11"; $string = preg_replace_callback('~([a-z]+)(\d+)(?:-[a-z]*(\d+))?~i',create_function('$m','return (isset($m[3]))?($m[1].implode(\',\'.$m[1],range($m[2],$m[3]))):$m[0];'),$string); echo $string; output: CX1,CX2,CX3,CX4,CX5,CX6,CX7,CX9,CX10,CX11
  11. geez man, you're killin' me. Are there any other surprises or "gotchas" you need to mention?
  12. if you are referring to the code I posted, look at the edit. I noticed afterwards that the letter prefix could be more than 1 char so i adjusted the regex.
  13. echo out your $sql variable and run it directly in your database (like through phpmyadmin). Do you get results?
  14. so if you echo $description and $_GET['description'] are those blank?
  15. please clarify what you mean by "it doesn't do anything". did you echo $row or $num_rows out to see if you have something from the query?
  16. $string = "C1,C2-6,C7,C14,C15-43"; $string = explode(",",$string); $list = array(); foreach ($string as $val) { preg_match('~([a-z]+)(\d+)(?:-(\d+))?~i',$val,$parts); if ( isset($parts[3]) ) { for ($c=$parts[2]; $c<=$parts[3]; $c++) { $list[] = $parts[1] . $c; } } else { $list[] = $val; } } $string = implode(',',$list); edit: modified regex to match 1 or more letter prefix
  17. did you restart apache after you made the change to php.ini?
  18. for starters, you assign your description to $ID but use $description in your query. But also, post what the error is.
  19. Really? Because that's exactly what you have been doing. You have been quite explicitly stating that OOP is "perfection" and anybody who does not use OOP is an amateur. And even still, you are still being presumptuous. You say that a programmer can be a good programmer if he uses Procedural, as long as he understands OOP. Do you not see the flaw in that statement? Either Procedural has a place or it doesn't, and that is independent of whether or not the coder knows an alternative method. So if a coder works solely in an environment where Procedural is acceptable, then there is no reason he needs to know OOP, and he is still a good coder. This is the equivalent of saying a doctor can never be a good doctor unless he knows how to do the job of all doctors, from heart surgeon to dermatologist. A doctor can specialize in skin (dermatologist) and know nothing about the heart. Does that make him a bad doctor? No! He has his knowledge and tools most relevant to his specialty. He can be a really good doctor and know nothing about hearts. Or how about an analogy that hits closer to home. You are obviously a coder. So the chances are very high you have your own circle of people who automatically think that just because you touch a computer, you are an expert on everything having to with computers. That's why your grandpa calls you up asking you to fix his shit when he's clicked on too many links from nigerian princes promising riches and 10 hour erections. And what do you say to that? "Sorry grandpa, I do web development, I don't know how to clean old-man splooge from a usb port". Does that make you a bad programmer? No! It just makes you bad at cleaning up your grandpa's taint (And I'm not judging, I too have trouble cleaning up my grandpa's taint, no worries bro). Anyways, I am by no means knocking OOP. But I love it or hate it, depending on what environment I am working in and what I am doing in that environment. As I have mentioned before, it seems that you've just gotten into it and it's really shiny and all, but you don't seem to have enough real-world experience under your belt to realize that it is not the end-all-be-all perfection that you think it is.
  20. HoF IMO the main reason php code is written procedural style is because it is mainly used for http protocol (making websites). OOP in a stateless environment don't really mix all that well. Obviously it can be done, but it more often than not comes out as overkill.
  21. Rule 1) $system would likely be implicit (in the same way window is implicit in javascript) and not necessary (built into the interpreter, no include or instantiation necessary) Rule 2) output can just be an alias of echo (maybe there is a nuance but nothing we care about in this scenario). Rule 3) Objects are implicit, you don't necessarily need to use the new operator to instantiate a new object. For instance, if I can pass new String("Hello World") as an argument, I can equally just pass "Hello Word" as a string object literal (same principle in js as being able to do this: console.log("THIS IS A TEST".toLowerCase()); Given these 3 "rules", echo "hello world"; would already be perfectly reasonable syntax for a fully OOP language. Just sayin'...
  22. MAAaaaAAAAaAaaAAaaAGIIIiiiIIIIiiiIIIIiiiiC
  23. The way I understand it, you have in your database "las vegas" and you want to be able to put into the address bar ../las-vegas and treat the city as "las vegas" right? Assuming your mod rewrite is working correctly and it is putting it into that u url param...this will allow you to do ../las-vegas or ../las%20vegas <?php include('init.php'); // connection to database // if city exists... if (isset($_GET['u'])) { // decode and replace hyphen with space $city = str_replace('-',' ',urldecode($_GET['u'])); // if value contains only letters, numbers or spaces... if ( preg_match('~^[a-z0-9 ]+$~i',$city) ) { // select data from database... $data = mysql_query("SELECT State, City FROM cars WHERE City='$city'" ); if (mysql_num_rows($data) > 0) { while ($row = mysql_fetch_assoc($data)) { echo $row["City"]; } } } } ?>
  24. if ( is_file("img/albumOne/".$_POST['fileToDelete']) ) { unlink("img/albumOne/".$_POST['fileToDelete']); }
  25. looking at the syntax helps, but is not good enough. So you spelled it right...so what? Do you actually have a database on your server, did you check that? Do you have error reporting turned on? Are you checking the results of your query? You can't just eyeball!
×
×
  • 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.