-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
And you will watch your RSS Subscriptions plummet and it become one of your least viewed files if you put ads in it. How many people do you know or even think will willingly subscribe to advertisements?
-
Make sure you are editing the right php.ini file, some all-in-one programs have multiple php.ini files. Also check your mysql config file, maybe it is the mysql execution timing out, not php
-
Okay, this will perform a query that searches the description column for a value that contains the value you pass in description query string param. If the value is more than one word, it will return results for each word. So for example, yoursite.com/yourscript.php?description=foo%20bar will return some foo description some bar description some foo bar description if (isset($_GET['description'])) { $description = explode(" ",urldecode($_GET['description'])); $description = array_map('mysql_real_escape_string',$description); $description = "'%" . implode("%' OR LIKE '%",$description). "%'"; $sql = "SELECT * FROM productdbase WHERE description LIKE $description"; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($res)) { echo $row['description'] . "<br/>"; } }
-
actually wait I take that back, that's a list of exact matches...1s
-
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/>"; } }
-
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; }
-
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"
-
You have got to be shitting me. Why didn't you mention this before?
-
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..
-
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)
-
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!
-
$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?
-
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
-
geez man, you're killin' me. Are there any other surprises or "gotchas" you need to mention?
-
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.
-
echo out your $sql variable and run it directly in your database (like through phpmyadmin). Do you get results?
-
so if you echo $description and $_GET['description'] are those blank?
-
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?
-
$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
-
did you restart apache after you made the change to php.ini?
-
for starters, you assign your description to $ID but use $description in your query. But also, post what the error is.
-
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.
-
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.
-
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'...
-
Can't account for spaces in my database when echoing out data?
.josh replied to mcc_22ri's topic in PHP Coding Help
MAAaaaAAAAaAaaAAaaAGIIIiiiIIIIiiiIIIIiiiiC