Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. I agree, a Virtual Private Server (VPS) is a good compromise between shared vs. dedicated for starting out.
  2. is id in your temp table set to be unique/auto-increment? also do this, does it output any errors? $r = mysql_query($q) or die(mysql_error());
  3. so is the correct ID showing up in the URL when the page is loaded?
  4. $_POST != $_GET. Query string parameters are put into $_GET. Sidenote: You should validate or sanitize the value before putting it into your query. At a minimum, do this: $id = (int) $_GET['id'];
  5. Okay so you're saying the target page $row[1] is the next page. So then it's easy enough to append the id to it. Just do this: $target = $row[1]; $target .= (substr($target,-1) == '?') ? '&' : '?'; $target .= 'id='.$row[0]; print "<td><a href=".$target.">$row[2]</a></td>"; So that will pass the id to the target page. Then on the target page, grab that id and select surname where id=$_GET['id']
  6. Okay, so what are you saying then.. that you want to click on the name and it go to a details page, but the name ($row[2]) is already a link pointing to somewhere else? Well what is it pointing to? Is it pointing to the same page $row[1] that you want the details to show up on, or a different page? If it's the former, then it's easy to append the id to it. If it's the latter, well then yeah, that's a problem. You can't have a link that points to 2 places. You'll have to apply the concept to some other piece of text or make a new button altogether.
  7. So one thing I see wrong is you have this: var ptotal; // stuff myItems[x] = document.getElementById('totalPrice' + x).innerHTML; ptotal+=myItems[x]; Okay so first you declare ptotal but don't assign anything to it, so even though it's declared, it's undefined. then you attempt to add add myItems[x] to it, which is a string type value, because .innerHTML is a string type value. So javascript stringifies the typeof ptotal (which is 'undefined') and uses the + operator in the context of string concatenation to concatenate the string value of what's in that element's innerHTML. To fix this, you need to initialize ptotal as a number type, by assigning a value to it: var ptotal=0; Then, you need to convert the value of myItems[x] to a number type, before adding it to ptotal: myItems[x] = document.getElementById('totalPrice' + x).innerHTML; ptotal+=Number(myItems[x]); Beyond that, since you are saying you are only getting an alert of "undefined20.00", to me that means that you have a mis-alignment of your html element id names vs. array index vs. that howMany value. Which means basically your loop isn't looping through all of your html elements. I can't really confirm this without seeing more code, like your actual html elements and what value howMany actually is, etc..
  8. when you are looping through and outputting the values, wrap the name in a link that has the id (primary key) appended to the details page (you will need to add it to your select statement if you don't already have it in there) pseudo-code: while ( $row = fetch row ) { echo "<a href='details.php?id={$row['id']}'>{$row['username']}</a><br/>"; } So then it will output for example: <a href='details.php?id=1'>John</a> <a href='details.php?id=2'>Jane</a> <a href='details.php?id=3'>Jim</a> etc.. Then on your details.php page, grab $_GET['id'] and use that in db query to select the info where id equal that id.
  9. ..yeaahhhhhh.. except that totally doesn't sound like what he meant. But maybe he's not in America and maybe whatever country he's in doesn't have laws like that.
  10. Not to be pedantic, but the point of a donation is that it's not compulsory. If you require someone to give you money in exchange for something (be it product, service, access or anything else) then it's no longer a donation, but a fee. I only mention this because that's how the tax people are going to look at it, and they will be expecting a cut, or else proof of exemption.
  11. Okay, well read up on functions. If you have a specific question, then by all means post.
  12. $line = strtolower(trim(preg_replace('/[^a-z]/i', '', $line)));
  13. perhaps a matter of case-sensitivity, need to strtolower $line ? If that doesn't work, then post some example lines from your file. replace with '' instead of ' ' so that all non-alpha chars are stripped.
  14. well, technically it's working as intended. <div class="hello world"> $elems = $html->find('.hello'); This will return that div because "hello world" is not one class. It's 2 separate classes, "hello" and "world". So perhaps you meant to ask for it to return elements that only contain one class ("hello")? If that is the case, I think what you want to do is (untested) $elems = $html->find('*[class=hello]'); Edit: Just noticed that you rezzed an old thread, prueba. So I added what should work for you, since it's unlikely the OP will be responding.
  15. oobradersoo I applaud your effort to wanting to learn it the "long" way without built-in functions. It is better that way because then you will better understand the concepts and principles of programming. You will better understand what stuff like str_repeat is doing internally, etc. You acknowledge that you're a nub, and I commend you for that as well. Which is why you need to step back and start on square 1 with the basics. As it has already been shown in your previous threads, there is no benefit to just handing you the code. You aren't learning anything from that, because you don't understand the basic syntax. There are a ton of php tutorials out there, not to mention php.net's excellent manual. Start with the proverbial "hello world!" tutorial and go from there. You need to learn to crawl before you walk.
  16. parse_url just parses the (url) string you give it. There are no php functions or methods to get the referring URL if it's a masked 301 redirect, or otherwise get it if the user agent simply doesn't provide it or lie about it. For example, say you are in your browser and have an addon like tamper data. When the request is made, you can set Tamper Data to strip whatever headers, or alter the values. So the overall message here is that you can't rely on that data as 100%. You have to treat it like you do any other user input, like from a form. Bottom line is there is no reliable method of getting the true value. What you already have is as reliable as it can get. There's nothing you can do with regex (or other means) that parse_url can't already do*, because the problem is getting an accurate string to work with in the first place. *actually parse_url doesn't account for several edge-case url formats, so if you're looking for a more thorough version of it, ctrl+f the user comments in the manual entry for "j_parse_url". But the previous statements still stand: the core issue is not a limitation of parse_url, but in the server itself reliably receiving a value that isn't tampered with or omitted.
  17. If you don't want to use str_repeat (why?), then you need to use a loop that counts to whatever the number is.
  18. also note to make sure to do a strict comparison when using strpos. $foo = "bar"; if (strpos("bar",$foo)) { // found? } else { // not found? } In this example, the condition should be true, but strpos returns the position of the found needle. Since it is at the beginning, it will return 0. Since 0 is a falsey type, the condition will evaluate false, even though it was found. So you need to do something like this: $foo = "bar"; if (strpos("bar",$foo)!==false) { // <-- !== not != for strict comparison // found! } else { // not found! }
  19. No, [^g] will not match the same thing as [a-fh-z]. [^g] will match any character that is not a "g". So it will match whitespace, numbers, non-alphanumeric chars, etc. But in general, a carat at the beginning signifies a negative character class. It means to match the opposite of what's listed. So for example [a-z] will match any one lower case letter whereas [^a-z] will match any one character that is not a lower case letter. Outside of the character class, ^ does mean "beginning of line" as you said. Well it actually means "beginning of string". If you use the "m" (multi-line mode) modifier then it becomes "beginning of line or string".
  20. i'm not sure I 100% understand you, but I have a small suspicion perhaps your issue isn't the prefix, but perhaps the suffix. For example, this: \bv?ojet.?\bal What is the purpose of the .?? The second \b may cause it to not match, depending on what that dot actually matches. If that dot matches a "word" character, then that second \b will cause the pattern to fail. For example, "vojet-al" will match "oject-al" will match "ojectal" will fail "ojectfal" will fail \b is a lookaround assertion. It looks at the character before and the character after it. It will only match if there's a non-word char followed by a word char, or visa versa. Well you have \bv?ojet.?\bal, so the "a" after the \b is a word char, so that dot will have to match a non-word char in order for the \b to match.
  21. ignace .. well in America there is no such law that makes you get to work for set amount of time. So unless you explicitly negotiate something in a contract when you get hired.. the "default" legal setting is immediate termination without or without reason (unless it's for something like firing because of sex, race, etc..). Though, depending on circumstances, it's possible to collect unemployment while looking for a job. But it's fairly difficult to get and maintain it. I can see what you're saying as far as it being in everybody's best interests to try to resolve shit and keep the person around, and the same can be said here, as well. It is a drain on morale for the other employees. And it will take time and effort to find a replacement and get them up to speed. So unless your insubordination causes the company to lose like millions of dollars or some shit.. you may likely "get away" with it in the sense that it wouldn't immediately get you fired. But it as you noted yourself, it will set things in motion with them to do something about it. Refuse to do the job? Okay, re-task you. Refuse to do that job too? How long do you think they will wash-rinse-repeat before they decide you aren't worth keeping around, before they decide it'd be less of a loss to just let you go? So in principle, the core of what I said in previous post still stands: At the end of the day, it's about doing what you're told.
  22. ignace that's cool and I'm glad it worked out for you, but when you say this to your boss: "You either let me do my job or fire me. I don't do half-work," more often than not he will choose the latter. Or else choose the former because it's better than nothing at the time - and then start focusing on replacing you. IOW I would not recommend this approach for most people in most situations. If you're going to stand up to your boss like that, make damn sure you really are irreplaceable or else you don't really need the job. I won't sacrifice my morals for a buck. For example, you will never catch me willingly code for a porn site. But the whole "shitty code for shitty timelines" thing.. that's not really morals, that's pride. And while I certainly strive to be proud of the work I do, I am just as certain to swallow my pride to keep my job if it's not violating my morals. I do the best I can do with what I'm given. I make sure it's abundantly clear that someone understands what they are asking for and what they are getting and how shitty it is. If the say they want it anyway, why should I continue to protest? Refusing to do the job unless I can do the best I can in optimal settings is, IMO, usually a foolish thing to strive for, and something very few people can afford to get away with. It's a balancing act, for sure. There's always going to be a certain level of mutual exclusion between "Doing it right" and "Doing what you are told." Just remember, at the end of the day, your boss is the one in charge making the decisions. He can't do his job if you are insubordinate. He may very well be a dumbass making a wrong decision, but it's his decision to make. He's not paying you to make the decisions; he's paying you to do what he tells you to do. If that weren't the case, then he wouldn't be your boss. If he's that much of a failure, go over his head and appeal to his boss. Because I guarantee you that 99% of the time you will get fired over insubordination no matter how right you are. And saying "Well then they aren't worth working for" looks really pretty on paper, but just doesn't work out in reality for most people. Truth is, "We'll consider your input when making a decision, but when we decide and give you instructions, you will do it or we'll kick you to the curb" is pretty damn universal. So unless you're financially secure and only doing work for the hell of it out of boredom and can afford to pick and choose, then you would do well to ditch that unrealistic mentality. And if you think about it, that's not really a bad thing. Put yourself in the boss's shoes. Let's say you are a project or department manager, responsible for making sure lots of people get shit done. You're dealing with people higher up than you, clients and other outside forces, etc.. you have all this shit to consider and deadlines to meet, etc. You know that the situation sucks but you pick the least of the evils and go with it. So you give your minion his marching orders.. and then he tells you "No, I won't do this cuz I refuse to do shitty work." Your may try to be patient and explain to him you understand, but that's not an option. If your minion still refuses, you might have "a talk" with him about misguided principles. Or maybe you're not very patient and flip your shit over his insubordination right from the get-go. Either way the end result is the same: the only way you can "accept" his terms (even if you agree with his principle/arguments) is by you yourself becoming insubordinate to your superiors, or else going back on promises to client, etc. "Oh well maybe if the boss didn't make promises he couldn't keep, or had asked me before the project started, etc.." Yeah that's fine and dandy but it's also extremely short-sighted and ignorant. Your boss receives marching orders the same way you receive them from him. He's the proverbial messenger and you're trying to shoot him, as if it's his fault. Obviously everybody's situation is different. But the core essence of it is universal: bottom line is someone is paying you to do work for them. It doesn't matter how stupid or pointless or inefficient. That's not the point. The point is they want something, are willing to pay for it, and either they will pay you, or they will pay someone else. This is a universal concept. Even with freelancing. Even with buying anything in general. From the "customer's" (client, your boss) point of view, you aren't standing up for your principles. You're telling them that you refuse to provide product/service as if you know what's good or bad for them. Even if you do, it's not your right to do that. It's like if a shopkeeper were to refuse to sell junkfood to fat people because they shouldn't be eating it. Well you may be right in that they shouldn't be eating it, but it's not your right to make that decision for them. It's not really even socially acceptable to advise against it, though this analogy is getting into pretty gray territory now. In reality your boss should be asking you for your PoV. And ideally, he should be trying to incorporate that in what decisions he can make, or else faithfully pass it on up the chain of command. But at the end of the day, "Do what you're told to do" almost always 99.999% of the time will trump all, so be prepared for warnings, suspensions, terminations, etc.. over it. No matter how "right" you are. Which is why I will stick by it if it violates my morals, but I absolutely will happily turn in shitty code to keep my job, as long as I make sure it is understood it's shitty. People seem to always start out relationships with clients or new projects etc. with pie in the sky fantasies like it's going to be some vacation. Plan the vacation out and everything goes smoothly. But things always go wrong. Plane crashes on a desert island, don't refuse to make a fire just cuz you don't have matches. Don't refuse to hunt because you don't have a gun or a fishing pole. Don't refuse to cook because you don't have a 5 star kitchen and 5 star ingredients to work with.
  23. You do it by establishing word boundaries and quantifying whatever you are matching for. For example, to match a word that does not contain a "g", you do use \b[a-fh-z]+\b The \b is a word boundary assertion. Wherever the regex pointer is in the string, it looks at the character behind it and the character in front of it. If there is a switch from a "word" character to "non-word" character or visa versa, the word boundary will match. Then you have the original character class that matches any 1 character except "g", and then + is a quantifier, meaning match 1 or more of the preceding character (or character class or group). Here is the same principle using the negative lookahead: \b((?!g)[a-z])+\b Sidenote: I see that you found \w. Note that this is not the same as [a-z]. \w is shorthand and is the equivalent of [a-zA-Z0-9_] which matches any letter (case-insensitive), number and underscore. [a-z] only matches lowercase a through z (unless you were to add a case-insensitive modifier somewhere else), no numbers or underscores. For the purpose of this example it will match a "word" that does not contain a "g", but just note that \w would consider "abc_123_EFG" a "word". Also note that the \b boundary logic works the same way as \w's "word" logic. For example, using this regex: \b[a-z]+\b on "123foobar456" would fail, because the only thing [a-z]+ will match is "foobar", but since \b considers digits to be a "word" character, there is no switch from "word" to "non-word" between "3f" and "r4".
  24. Yes. It's called an array, which is what I was trying to get you to adopt in your previous thread, except you favored your less-efficient coding practices.
  25. Basically you need to do this, which will match no matter what comes before it: $str = preg_replace('~/issue/(\d+)\b~i', '<a href="/issue/$1">/issue/$1</a>', $str); Or this, which uses a negative lookbehind as a workaround for what kicken posted. (it will only match if it's preceded by a non-word char): $str = preg_replace('~(?<=\W)/issue/(\d+)\b~i', '<a href="/issue/$1">/issue/$1</a>', $str); I also threw in a case-insensitive modifier so it will match if someone does /ISSUE/123
×
×
  • 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.