DavidAM
Staff Alumni-
Posts
1,984 -
Joined
-
Days Won
10
Everything posted by DavidAM
-
"order" is a reserved word in mySql. If you really must use it as a column name, you will have to surround it with backticks: UPDATE someTable SET `order`=100 ... I recommend NOT using reserved words for column names (or table names for that matter).
-
These errors are messages generated by your code. Search through your source and find where they are assigned and then figure out why. Does not allow the last name to be more than 10 characters: "testingagai" is 11 Checks for an MX record for the email's domain: "[email protected]" is probably not a valid email domain. @Drummin: You can assign a value to a the $_SESSION super-global array at any time after the call to session_start(), even if something has already been sent to the browser. It is the session_start() call that must occur before anything is sent to the browser.
-
Just for the record: There are were two magic-quotes settings. The one everybody always talks about --- magic_quotes_gpc --- and the other one magic_quotes_runtime. From the manual on Core Directives: magic_quotes_runtime (emphasis added) I have never come across a system where this was on, but if it is, then data from the database might need stripslashes.
-
When you have problems with this type of script, take the value you are providing in the SRC attribute of the IMG tag and type it in the address bar of your browser (with the host name, etc). If it works, you will see the image, if it does not work, you should see the error messages. If you don't get any error messages, add those two lines from xyph's signature to turn on error reporting. This could be a BOM issue.
-
I wrote this query last night, but my grandson flipped off the power strip and it was lost. I think it went something like this: SELECT FLOOR(DATE_DIFF(RainDate, '2011-01-01') / 10) AS RainSet, SUM(RainQty) AS TotalRain FROM dayRain WHERE RainDate BETWEEN '2011-01-01' AND '2011-01-31' GROUP BY 1 DATE_DIFF(RainDate, '2011-01-01') calculates the number of days between the date in the table and the starting date of your range. For the first date in your range, this is zero FLOOR( <DATE_DIFF> / 10) - Divides that number of days by 10 and returns an integer result. So the first ten days will have a RainSet value of zero, the next 10 days will have a RainSet value of 1, etc. GROUP BY 1 - groups by the first expression in the select list (this is a shortcut so I don't have to type the whole FLOOR(DATE_DIFF ...) expression again The Date in the DATE_DIFF expression needs to be the start date of your range. Your range is also specified in the WHERE clause --- remember BETWEEN is inclusive. This will return a result set like: RainSet TotalRain ------- ------- 0 20 1 5 2 15 The beauty of relational databases and SQL, is that you almost never "need" to make a new table for calculated data. Unless you have a compelling reason to create the table, you should use queries to summarize your data.
-
Getting the clicked element in an onclick handler
DavidAM replied to jhsachs's topic in Javascript Help
<a onclick="SetLoad(this);" href="..."> Here, when the user clicks the line (the A tag), we call a function. The function's name is "SetLoad" and we are passing it a single argument. The argument we are passing is "this" which is the JavaScript object that is calling this function. function SetLoad(theTag) { } Here, we define the function that we are calling from the onClick event above. The function name has to be the same: "SetLoad". But we can name the parameter anything we want to here. So inside the function, you use "theTag" as if it was the "this" variable that you were expecting in your original post. In this scope (inside the function) the "this" object will still reference the document. So we had to pass in "this" at a point where it referenced the Anchor so the code in the function can know who called. -
Doesn't post it in the database :( (HELP PLEASE) ):
DavidAM replied to buzzern96's topic in PHP Coding Help
That query looks fine to me. When you say "Still doesn't work." -- what exactly do you mean. Is it not putting the data in the database (did you check), or is it not redirecting you? Since you are serving out HTML above this code, the header redirect is NOT going to work. For debugging purposes only: add the following lines to the very beginning of that file (above the DOCTYPE and everything): <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> Then add the "die" line below if ( mysql_query($sql, $con) ){ mysql_close($con); header('http://localhost/takk.php'); }else{ ## Add this line for DEBUGGING PURPOSES ONLY die(mysql_error() . '<BR>' . $sql); mysql_close($con); header('http://localhost/error.php'); } Those redirects are never going to work in the middle of the file like that. However, if you move ALL of the PHP above the DOCTYPE, and add exit(); after each header() call you should be very close to what you want. -
In JavaScript, the ID attribute must be unique across the entire document (web page). When you need to refer to a group of elements (like your "delete" buttons) you can use the CLASS attribute.
-
Getting the clicked element in an onclick handler
DavidAM replied to jhsachs's topic in Javascript Help
Have you tried: <a onclick="return SetLoad(this);" href="..."> and then reference the parameter in your function function SetLoad(theTag) { } -
The database structure should match your real-world setup as much as possible. In Texas, USA, Sales Tax is based on the TOTAL price of all Taxable items on the order (some items may not be taxable). Also, in Texas, all taxable items on the order are subject to the same Sales Tax (and therefore the same rates) -- although certain sales are subject to other taxes (such as cars, hotel rooms, car rentals, etc). And finally (not that there is ever a final word when talking about taxes) some Customers are exempt from Sales Tax. In this scenario, I would have a Order Header table with the order specific data, and a Order Lines table with an entry for each line on the order. I would not store the order total or line total or tax total or any other calculated field; these can all be calculated on the fly. OrderHeader: ID, Customer, IsTaxable, TaxRate -- TaxGroupID (see below) OrderLines: ID, OrderID, Item, Quantity, UnitPrice, IsTaxable and possibly OrderPayments: ID, OrderID, AmountPaid In most applications I have worked on, instead of the TaxRate in the header (or in addition to it), there is a TaxGroupID which is a foreign key reference to a table indicating what tax rates are applied. That table (usually) has a child table listing the individual jurisdictions and their rates. (In this case, I would probably store the aggregate tax rate: TaxGroups: ID, Description, TotalRate TaxGroupJurisdictions: ID, TaxGroupID, TaxJurisdictionID TaxJurisdictions: ID, Description, TaxRate One final note: Since tax rates are subject to change, I would (likely) store the rate used for a particular order in the order header AND I would make sure to store the date of the order so I could prove that I charged the rate that was in effect on the date the order was taken. Note: The above database structure is overly simplified to answer the specific question at hand, there will be many other fields, and (most likely) foreign key references to other data in the final structure.
-
isset returns true or false indicating if the variable is set. Since it is set (in the code above that), it is returning true. When you compare true to any integer (1 or 2) the IF is returning true. So, both IF statements, as written, are true. if ( (isset($_SESSION['result'])) and ($_SESSION['result'] == 1) ) should produce the results you are expecting.
-
The data there already satisfies your requirement (well, except for the "random" part). If you call the PHP strtotime function against the "Time" value, all of the rows with the same Timestamp will return the same integer value. At first I thought you wanted something like a sequence, but then I re-read the OP and you say you want a "random" number. Maybe if you explain a little about why you need it and/or how it will be used, we can offer a better answer.
-
Since you said the main JavaScript will be in a separate file, you can have PHP output JS variables in your page and then have your LINKed in JS file reference them. So, the output HTML would look something like this: <SCRIPT> var addrStreet = "123 Main Street"; var addrCity = "Hometown"; var addrState = "TX"; var addrZip = "98765"; </SCRIPT> <SCRIPT src="/js/mapper.js" type="text/javascript"></SCRIPT>
-
Which way would be best? Depends on how you are doing things ... break ... If your page has a single location and you want to include the map, you can set the JS variables when PHP outputs the page. Just set them before your JS LINK if it refers to them directly. If your page will need to change the address based on the user's interaction, you probably want to use AJAX to run a PHP script to query the database and return the address.
-
Your question is too general (IMO) to actually get the answer you want. Do you mean: How do I put the data into the database? Use the INSERT statement How do I maintain the data? Write an Admin page to add, edit, delete these items How do I structure the data -- do I use another table? We would need to see your database structure How do I make the add-on work? [soapbox]Personally, these add-ons annoy the h@#% out of me, so I'm not even going to address it. If I wanted fried bull testicles with my pizza, I would have clicked on it before I clicked "Checkout"[/soapbox] Sorry ... we would need to know more details on how you want it to work - always show all add-ons, show only one "randomly" selected add-on, show something that actually goes with what they have already ordered, show something they have ordered in the past and maybe forgot to order this time, ...
-
25 hours ... is that a record? Wow! I completely missed it last night when I logged in. Of course I wasn't able to stay long because of pressing issues at home. I am honored to have been selected to join this elite group. I shall always wear my badge and ring with dignity and ... hey! ... wait a minute ... why's my finger turning green?!? All seriousness aside ... Party at my place tomorrow night!
-
Debbie, I really think you have a grasp on the possibilities, it's just that there are many different ways to do this, and most of them are perfectly valid, so you question whether you are doing it "right" or not. The most critical part of any programming project is design. It is also the most neglected. Think ahead about what you want to do with the profile, and where you will be placing links to it. Then consider what structure/format makes the most sense for most cases, and do it that way. It sounds like a logical choice. Keep in mind, however, that if you are using mod_rewrite, the "directory" does not have to exist; and there does not even have to be a physical relationship between the URL "directory" and the web-root directory. This is advanced stuff, but you can rewrite a url, such as, http: //www.mydomain.com/account/userprofile/about-me/DavidAM so that it actually runs a script in <webroot>/profile.php with a query string of ?user=DavidAM&tab=about-me; or it could run a script in <webroot>/profile/index.php; or whatever. I try to avoid creating a subdirectory that will have a single file in it. I would rather rewrite the request. With mod-rewrite, the user will (usually) not see the actual script filename so we could rewrite to lessImportantStuff.php if we want. I won't say it is wrong to do it, I just personally avoid it (mostly for maintenance reasons). But it really depends on your preference, and how the rest of your site is designed --- above all, be consistent, so you know where to look for the profile script if you need to modify it. If you do create a directory, you are correct in suggesting that there be an index.php file in that directory. Otherwise, a request to the directory without parameters, could show the directory list, which leaks some information about your platform to potential blackhats (and isn't very user friendly, either). We could swap the two parameters around, so the tab-name comes first in the url and the user-name comes last. We still have to handle the case where one or both are missing (show current user's about-me tab, or send the not-logged-in visitor to the registration page). Again, it is a matter of your preference. Since the rewrite rules will be sending the data as "named" parameters (i.e. $_GET['user']), it does not really matter what the url looks like. I would look at which "parameter" is most likely to be provided most often, and put it first -- in other words, look at which parameter is most likely to be omitted and put it last. Since on my my-friends page, I'm guessing you will list my friends as links to their profile, I figured the username will almost always be present and you would want the link to go to the about-me tab, so that could be omitted. On the other hand, you could be consistent and always provide both. I would recommend providing both on any "public" pages (pages that do not require a logged in user). Since these might be indexed by Google, you don't want to have two different links pointing to the same content. For the links to the current logged-in user's profile, this is not an issue, since Google is not going to have a login. I hope I haven't confused you more than I've helped. It's been a long day and I'm not feeling very logical right now. - David
-
Right. Hopefully, each user has a "name" that can be displayed to other users; and this "DisplayName" is unique. Since it is unique, you can use it as a "Slug". So the URL would be different for each user. Yeah, it would be some string that your script can use to decide which tab to display You could use an index.php file in a "profiles" subdirectory. It would (most likely) not present a list of users, though. You would check $_GET for the "user" and the "tab". Not really ... if (! isset($_GET['user'])) $user = $_SESSION['userDisplayName']; // Or however you are tracking the logged in user else $user = $_GET['user']; $validTabs = array('AboutMe', 'MyFriends', 'MyThoughts'); if (! isset($_GET['tab'])) $tab = 'AboutMe'; else $tab = $_GET['tab']; if (! in_array($tab, $validTabs)) $tab = 'AboutMe'; // Just in case they typed it wrong I would. Then my page -- profile/DavidAM/about-me -- would be indexed in Google with my name right there (ain't that exciting!?) Yes Actually, since you are using restrictive character classes, the sequence may not matter. I usually do it the lazy way: RewriteRule profile/(.*)/?$ profile.php?user=$1 RewriteRule profile/(.*)/(.*)/?$ profile.php?user=$1&tab=$2 In which case, I have the rules backwards here. The second rule would never fire, because everything would match the first one. If you are going to use it as a "Slug" then it needs to be restricted to valid URL characters. So you would need to exclude slash (/), colon ( : ), asterisk (*) and question mark (?) at the very least. I would allow at least: A-Za-z0-9 and some special characters. For mine, I allow space ( ), underscore (_) and dash (-). I DIS-allow `~!@#$%^&*()+{}|:"<>?`=[]\\;',/ mostly because they would have to be urlencoded, and then it would not look as pretty; actually, it's more complicated. The path part of the url should be rawurlencoded, but the query strings should be urlencoded, so what happens when you move a path portion to a query string in mod_rewrite? Is the urldecoding handled properly? I wasn't sure, and so I just restricted everything that has to be encoded. --- I just noticed I have the backtick in there twice, now I have to go fix the script I copied that out of ... dang, I did it in all three of my "bad characters" constants ... thanks for helping me find a "bug" in my code ... (a programmer's work is never done) You tend to ask very intelligent questions, and always seem to grasp the responses fairly well (yeah, I've noticed you around ). It's really very close to the Articles code, just with the addition of a "tab" selection. Did I miss anything?
-
What about using profile/DisplayName/showTab You use the DisplayName just like the Article slug. * If showTab is not provided, you default to the "AboutMe" tab * If showTab is provided, but is invalid, you default to the "AboutMe" tab * If DisplayName is not provided (and neither is the showTab) you default to the current user's "AboutMe" tab. I'm not an expert with mod_rewrite, so I end up with a couple of rules to cover these. Pretty much the same as your Articles rule RewriteRule profile/([a-zA-Z0-9_-]+)/?$ profile.php?user=$1 RewriteRule profile/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ profile.php?user=$1&tab=$2 The sequence of those two rules is important. Make sure the character class includes everything that is valid for a user's Display Name. Also, I usually include the optional trailing slash, just in case someone tries typing the URL manually and puts it on there. This should cover: profile/DavidAM profile/DavidAM/ profile/DavidAM/AboutMe profile/DavidAM/MyFriends (a very short list, indeed) profile/DavidAM/MyFriends/
-
Don't blame it on the "older generation"!!! My kids still holler at me: (When I say "child" I'm talking about my teenagers -- in fact my 21-year old daughter did this the other day) They just click OK and move on. I really think it is Bill Gates's fault, for making the computer do soo much for the user, without giving the user a choice, that kids today expect the computer to do exactly what they want without having to tell it. And if the computer does something they didn't expect, then they believe that that was actually want they wanted it to do, they just didn't know it.
-
Loop through Three Variables but Make them Always = 1
DavidAM replied to unemployment's topic in PHP Coding Help
Maybe you should look at this problem in a different way. Why? Because the number of possible combinations increases exponentially with each added stock. The number of permutations is roughly equal to 100 raised to the power of (the number of stocks minus 1) -- roughly, because you excluded zero and therefore 100 from the possibilities. So: Stocks Formula Result 1 100^0 1 2 100^1 100 3 100^2 10,000 4 100^3 1,000,000 Who is going to sit around and wait for your webpage to calculate one million permutations and then wait for you to multiply all those percentages by their available funds; and then wait for you to loop through the results and determine the "proper asset allocation"? This page will take forever. Not to mention the memory exhaustion problem that rythemton pointed out. If you could define what "proper asset allocation" means in terms of a formula, you could do it with far fewer calculations. For instance; let's say that Current Highest Price gets 2 points, Biggest Price Jump in Past 6 Months gets 4 points, Biggest Price Jump in Past 12 Months gets 2 points, Current Highest PE Ratio gets 3 points. Then you calculate the "points" for each stock (warning the following numbers are coming straight out of my @#$%&!) Highest Price: Yahoo Biggest 6-Month Jump: Google Biggest 12-Month Jump: Apple Highest P/E: Yahoo Points: Yahoo => 2 + 3 = 5 Google => 4 Apple => 2 TOTAL = 11 Allocation: Yahoo => (5 / 11) = 45.45% ==>> $AvailableFunds * .4545 Google => (4 / 11) = 36.36% ==>> $AvailableFunds * .3636 Apple => (2 / 11) = 18.18% ==>> $AvailableFunds * .1818 Of course, you have to handle rounding issues and so forth. But this cuts the number of calculations you have to do down to a linear number, uses far fewer resources, and will return the results in a reasonable amount of time. -
Display data from database !Confused!HELP Please
DavidAM replied to ckerr27's topic in PHP Coding Help
"Code tags" in a post are like HTML markup, but with square-brackets. So for bold instead of <B></B> (as you would do in HTML), you type [ b]something[ /b] (I had to put a space after the open brackets there so it would display, take the space out) which comes out like something. For code, you use code tags: [ code]code here[ /code] (again, remove the spaces). I mentioned the "#" because, above the edit box are some buttons for formatting posts; the "#" is the picture on the button that puts code tags into the edit area. Also, there is a Preview button below the edit area (next to the Post button) that will let you see your post before you send it, so you can see if the markup is correct. Anyway, on to the problem I see some HTML markup problems in that code. I'm not sure if these could be causing you problem or not. But you should fix these problems and then see what happens: <head> <link rel="stylesheet" type ="text/css" href="anything2.css" </head> That LINK tag is not closed, so the closing HEAD tag is ignored and it's closing bracket closes the LINK. <div id="container"> ... <div id="body"> There are no closing tags for these two DIVs Other than the fact that the HEAD tag is left open, I don't think these could be causing the problem. Did you look at the HTML source in your browser? That may give us a hint as to what is happening. -
1) You've got a mis-placed double-quote in there 2) You're missing a concatenation operator 3) Having the same "value" for all of them will not be very helpful echo "<option value ='" . $row['id'] . "'>" . $row['name'] . "</option>";
-
Either your newsfeed.php file is saved as utf-8 WITH BOM or there is a space or new-line before the opening "<?php" tags. Your adauth.php is script is trying to start a session but you already started one -- most likely the one you started there in newsfeed.php. If this is one of your scripts, you either need to take the session_start() out of adauth.php, or have adauth.php check to see if there is already a session before issuing the session_start(). If this is a third-party script, umm, hmm, move your session_start() to after the include and check to see if one has already been started -- of course this will be a problem if config.php needs a session. This one (the third one) is probably coming from your header() call that your original post was all about. You can't send the header because something else has already been sent to the browser (including these error messages). So fix the first two problems above and this one will go away. Edit: The moral of this story is: Always develop with FULL error reporting on.
-
Display data from database !Confused!HELP Please
DavidAM replied to ckerr27's topic in PHP Coding Help
Well, we'd like to help more, but I don't know what you are saying. Did you change the code as I suggested? Or was it already that way? Is that your actual code, because the code you showed should produce a syntax error, not the output you showed. Can you cut and paste your code, exactly as is, using the code tags (it's the button with the hash-mark -- octothorpe? -- just above the smileys with the blinking eyes)? Can you also cut and paste the HTML (from "View Source") of the browser (again, using code tags) so we can see what is happening?