KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
Not a fan: Purple, black, and silver/gray are the colors of royalty, and, ironically, the porn industry, not of New Hampshire (I'm a resident myself, near the seacoast), nor of antiques (have you traveled down Rt. 4 at all? it's called Antique Alley for a reason). The drop down menu is useless. The whole point of a drop down is to offer hierarchical navigation without needing to scroll. Get rid of the bumpiness of the store menu. It's distracting and out of place. A whole bunch of other stuff - useless home page, unaligned forms, SQL/PHP errors for a bad GET value rather than a 404 error page, etc. I get that it's unfinished, but it's really rough at the moment. As a designer, you can't just bend to the whims of your clients. Small business clients in particular are notorious for having horrendous design sensibilities. Many are just excited to have any web presence at all, while others won't be happy unless their site is more gaudy than Reno. It's your job to reign them in and stress that design is supposed to invoke certain feelings/moods/ideas while enhancing user interaction. An antique store shouldn't have the same color palette as a porno shop. In other words, it's okay to disagree with them. If you consider yourself a professional, you should disagree with them if the design they want will undermine the purpose of the site. You're job isn't just to spew out whatever they want, but to make the best site for them.
-
Brain fart on my end. Use: var homeScore = document.getElementById("homeScore"); homeScore.onclick = function() { var homeScorers = document.forms["myForm"].elements["homeScorers[]"]; var homeLength = homeScorers.length; for(var i = 0; i < homeLength; ++i) { homeScorers[i].style.display = "none"; } var score = this.value; for(var j = 0; j < score; ++j) { homeScorers[j].style.display = "block"; } } Notice that it's arrayelement.style.display = "whatever". Be sure to do the same for the away scorer side as well. My entire test script: <?php $dbc = mysql_connect('localhost', '*******', '*******'); mysql_select_db('test'); function makeSelects($dbResult) { mysql_data_seek($dbResult, 0); while($row = mysql_fetch_assoc($dbResult)) { echo "<option value='{$row['name']}'>{$row['name']}</option>"; } } function homeScorers($dbResult) { echo "<select name='homeScorers[]' class='hidden'>"; makeSelects($dbResult); echo "</select>"; } function awayScorers($dbResult) { echo "<select name='awayScorers[]' class='hidden'>"; makeSelects($dbResult); echo "</select>"; } $query = "SELECT * FROM players"; $result = mysql_query($query); ?> <!DOCTYPE html> <html lang="en-us"> <head> <title>Test</title> <style> .hidden { display: none; } </style> </head> <body> <form name="myForm" action="#" method="post"> <select name="homeScore" id="homeScore"> <?php for($a = 0; $a < 11; ++$a) { echo "<option value='$a'>$a</option>"; } ?> </select> <?php for($i = 0; $i < 10; ++$i) { homeScorers($result); } ?> </form> </body> <script type="text/javascript"> var homeScore = document.getElementById("homeScore"); homeScore.onclick = function() { var homeScorers = document.forms["myForm"].elements["homeScorers[]"]; var homeLength = homeScorers.length; for(var i = 0; i < homeLength; ++i) { homeScorers[i].style.display = "none"; } var score = this.value; for(var j = 0; j < score; ++j) { homeScorers[j].style.display = "block"; } } </script> </html> That should be more than enough for you to finish with. You really only need to copy the home side functionality to the away side, and fiddle with making your HTML and CSS look good. I used an internal stylesheet for the test file, but you should probably use an external one. Separation of concerns, and all that. You still have some logic to figure out, namely how to handle the values in the hidden drop downs. I'll leave that as homework.
-
Okay, the problem is that when you use one of the mysql fetch functions (like mysql_fetch_assoc) in a loop, it moves the internal pointer past the last row in your query result and keeps it there. Thankfully, there's an easy way to move the pointer back to the first row. Change makeSelects to this: function makeSelects($dbResult) { mysql_data_seek($dbResult, 0); while($row = mysql_fetch_assoc($dbResult)) { echo "<option value='{$row['name']}'>{$row['name']}</option>"; } }
-
Need someone who can help me calculate the price of a job.
KevinM1 replied to Jumpy09's topic in Miscellaneous
Not to be harsh, but I wouldn't pay more than $500 for that site. It looks amateurish to me (which, to be fair, it should, given your admitted skill level). The theme is very dark, especially for a business, and the navigation is odd. The drop down menus don't seem to align properly, and they feel cramped. For some reason, there's two pages for 'Contact Us' and 'Contact Form'. They can be consolidated. A lot of it just looks like raw HTML. Bulleted lists everywhere, Times New Roman font.... From a design standpoint, this really should be your first draft, not your final draft. Getting paid as a freelancer is more than just the time you put in. It's ultimately about quality. Without being able to see what you did for the admin area, I just don't see $900 worth of value here. -
Remember to close your <select> tags. You can do it simply by doing: function awayScorers($dbResult) { echo '<select name="awayScorer[]" >'; makeSelects($dbResult); echo '</select>'; } And, obviously, do the same in homeScorers() To show 10 of them, simply make a for-loop in your HTML where ever you want to show them: <?php for($i = 0; $i < 10; ++$i) { homeScorers($homeResult); } ?> And do the same for the away scorers. You'll most likely need to fiddle with the HTML to make it look right. For the CSS, the easiest thing would be to give all the scorer <select>'s a class, and then set that class's display to none.
-
I thought shucking was implied. It's not a corn job without shucking. And a whole lot of chafing.
-
Read up on functions, especially passing arguments to them. The Reader's Digest version is this: When you write a function definition, you specify an abstract version of the parameter(s) you want to pass in. To illustrate, a horribly canned example: function example($arg1, $arg2) { // do stuff with $arg1 and $arg2 } The key here is that this is a function definiton - a blueprint which isn't actually run until specifically invoked. So, when you have code like: $x = 10; $y = "Mila Kunis"; example($x, $y); $arg1 is replaced by $x and $arg2 is replaced by $y in that particular invocation. So, in the real code you have, $dbResult is essentially just a placeholder/delegate name. $homeResult and $awayResult are the real values you're dealing with. When you pass one of them to one of the functions, PHP is smart enough to do the replacement for you. So $dbResult is substituted with one of the others automatically. Really short answer: the $dbResult -> $homeResult/$awayResult is fine, leave as is. --- For makeSelects, get rid of one of the loops in its entirety, then simply echo the options in the other loop as such while($row = mysql_fetch_assoc($dbResult)) { echo "<option value='{$row['playername']}'>{$row['playername']}</option>"; } You only need one line in the loop because you only want one option per row. And, simply echoing them out, rather than returning them as a variable, is a bit easier, even if it's not 100% best practice. Ideally, you'd store each option in an array like so: $options = array(); while($row = mysql_fetch_assoc($dbResult)) { $options[] = "<option value='{$row['playername']}'>{$row['playername']}</option>"; } return $options; But that would require you to loop through those results to echo them to the screen. Easier just to echo them in place.
-
You're way off. Don't try to rush into the code. Stop, and take the time to read it. You have three components all working with one another. Your PHP is writing both your HTML and your JavaScript. homeScorers() and awayScorers() invoke makeSelects(). All you need to do is invoke one of those top level Scorers functions where ever you want a scorer drop down to appear: <?php function makeSelects($dbResult) { while($row = mysql_fetch_assoc($dbResult) { // make select OPTIONS, not the select tag } } function homeScorers($dbResult) { echo '<select name="homeScorer[]" >'; makeSelects($dbResult); } function awayScorers($dbResult) { echo '<select name="awayScorer[]" >'; makeSelects($dbResult); } $homeQuery = "SELECT * FROM players WHERE teamname = '$hometeam'"; $homeResult = mysql_query($homeQuery); $awayQuery = "SELECT * FROM players WHERE teamname = '$awayteam'"; $awayResult = mysql_query($awayQuery); ?> <!DOCTYPE html> <html lang="en-us"> <head> <title>Example</title> </head> <body> <!-- all of your HTML up until your form --> <?php echo homeScorers($homeResult); ?> <?php echo awayScorers($awayResult); ?> </body> <script> // the JavaScript </script> </html> This is how well-formed PHP apps should look, BTW. All PHP processing at the top, then the output last. Notice how, aside from a couple of function calls, there's no PHP mingling with HTML. Similarly, there's no inline JavaScript in the HTML. This layering is what you should strive for when you write your apps. Again, since this is pseudo code (although, almost completely written for real at this point), there will be details that you'll need to fill in. The most important one is actually writing the <option> HTML for the scorer drop downs (not difficult if you're familiar with either echo or return). There's also error handling to take into account. Take your time and really read what the code is doing. It's not that complicated if you take your time.
-
You're making a lot of extra work for yourself. You really don't want to be mixing PHP with JavaScript like you are. Remember what I said before: keep your stuff separate. Okay, that said, here's a rough sketch of how I'd do it (pseudo code): <?php function makeSelects($dbResult) { while($row = mysql_fetch_assoc($dbResult) { // make select OPTIONS, not the select tag } } function homeScorers($dbResult) { echo '<select name="homeScorer[]" >'; makeSelects($dbResult); } function awayScorers($dbResult) { echo '<select name="awayScorer[]" >'; makeSelects($dbResult); } $homeQuery = "SELECT * FROM players WHERE teamname = '$hometeam'"; $homeResult = mysql_query($homeQuery); $awayQuery = "SELECT * FROM players WHERE teamname = '$awayteam'"; $awayResult = mysql_query($awayQuery); // When you want to make your drop downs, it's as simple as writing: homeScorers($homeResult); // or: awayScorers($awayResult); // Obviously, you'll want to invoke them in the right place in your template, so DON'T simply write them one after the other like I did above. // Okay, so now, at the BOTTOM of your HTML: ?> <script> var homeScore = document.getElementById('homeScore'); var awayScore = document.getElementById('awayScore'); homeScore.onchange = function() { var homeScorers = document.forms["myForm"].elements["homeScorer[]"]; var homeLength = homeScorers.length; for(var i = 0; i < homeLength; ++i) { homeScorers[i].display = "none"; } var score = this.value; for(var j = 0; j < score; ++j) { homeScorers[j].display = "block"; } } awayScore.onchange = function() { var awayScorers = document.forms["myForm"].elements["awayScorer[]"]; var awayLength = awayScorers.length; for(var i = 0; i < awayLength; ++i) { awayScorers[i].display = "none"; } var score = this.value; for(var j = 0; j < score; ++j) { awayScorers[j].display = "block"; } } </script> Since this is pseudo code, I didn't put in any error checking (which you should do). It also may not (likely won't) work out of the box. The idea is to show how to approach the problem, not simply write the full script.
-
Rather than dynamically creating these drop downs, you're better off creating as many that would be reasonable (say, 5-10 for each side), and then hiding them with CSS. You could then use JavaScript to unhide them when necessary, based on their value. So, like I suggested before, do something like (pseudo code): var homeScore = document.getElementById('homeScore'); var awayScore = document.getElementById('awayScore'); homeScore.onchange = function() { // get all of the existing child drop downs and HIDE them all // unhide the number of child drop downs equal to this.value } awayScore.onchange = function() { // do the same thing here }
-
It's good to see that I'm not the only one sometimes posting a response in the wrong thread
-
The Others frighten me. All wintery/zombie like, with their glass swords. http://en.wikipedia.org/wiki/Night%27s_Watch#Others
-
You should always sanitize any data that you use in a query, whether that means escaping or doing something else to sanitize the data. Escaping won't help you if you're using user data in an unquoted part of the query (unquoted integer in a limit or order by, table name reference, etc). ...obviously. Since the example/joke is an incoming, unsanitized string, that's what I addressed.
-
No, but it's the most common/simplistic example of why you should always escape any string data that you'll use in a query. Escaping nullifies the ' characters that Philip used in his example, which would result in a bad query and no results for the attacker to poach.
-
Look at the line starting with: $query = ... And try to figure out what's wrong with it.
-
...and what happens if someone turns JavaScript off?
-
Are you getting any errors?
-
Yes, you need to use either "ON" or "USING" when you use the "JOIN" keyword. That's what the link I gave you specified.
-
http://dev.mysql.com/doc/refman/5.0/en/join.html
-
How would i do this? Is it even possible? (Form help)
KevinM1 replied to chrisidas's topic in PHP Coding Help
It wouldn't be too difficult. You'll need to learn some of the basics, but, since JavaScript is already ubiquitous and becoming ever more important in the industry (especially with HTML 5's improvements), it's a core language to learn. No time like the present to get your feet wet. The biggest hurdles are: 1. Making sure the script doesn't execute before the HTML is rendered. JavaScript runs fast and tends to be greedy. One of the most common mistakes newbies make is putting their scripts in the <head></head> element without ensuring that the DOM (Document Object Model - your HTML document, plus a simple API to traverse/manipulate it) is loaded. The easiest way around it? Place your <script></script> tags at the end of your HTML, before the closing </html> tag. 2. Using inline JavaScript. A lot of tutorials show stuff like: <select name="blah" onchange="someFunc(someVal);"> Don't do it like that. Place all your JavaScript code in <script></script> tags, like: <!doctype html> <html> <head> <title>Example</title> </head> <body> <!-- stuff --> </body> <script type="text/javascript"> // JS code </script> </html> Why? It makes it easier to write/test/maintain/debug/edit your code, and it keeps your components separate from one another. Well-formed applications keep their various components (PHP, CSS, HTML, JavaScript, etc.) separate from one another, communicating only through rigid, explicit lines of communication. Mashing them together quickly gets messy. Might as well learn best practice from the start. 3. For your specific case, the hiding/unhiding of the drop downs is the biggest problem. You'll need to obtain the value of the goals, then unhide the right number of goal scorer drop downs. There's a wrinkle here - what if the user changes the score after goal scorer values have been selected? You'll be dealing with arrays, and array offsets here. So, do what you can, and if you have an issue, write a question in our JavaScript sub-forum, with the code you have. I'll be able to give better guidance after seeing what you've come up with. EDIT: Best resource to start from: https://developer.mozilla.org/en-US/learn/javascript -
How would i do this? Is it even possible? (Form help)
KevinM1 replied to chrisidas's topic in PHP Coding Help
To be honest, from a design standpoint, using JavaScript would actually be a lot better. It gives the user a seamless experience, and would be trivial to execute. Easier than doing it just in PHP. For PHP-only, you'll need the form to submit to itself, checking to see which side has a score. Then, you'd need to redisplay the form, with drop down boxes for the right team, depending on the score. With JavaScript, it's easier because you can create the goal scorer drop downs immediately, on the first page load, and simply hide them with CSS. When a goal number drop down's onchange event fires, you can grab its value and unhide the correct number of goal scorer drop downs on the fly. --- Regardless, you'll need to pass in the goal scorer's data as an array of values on each side. So, each goal scorer drop down you create should have a name along the lines of <select name="team1[]" >. -
How would i do this? Is it even possible? (Form help)
KevinM1 replied to chrisidas's topic in PHP Coding Help
Unless you want to have the page refresh, you'll need to use JavaScript. Remember - PHP runs on the server, while JavaScript runs in the browser. By the time your PHP script's output is rendered in the browser, it's done executing. There's no way for it to respond to the user unless another HTTP request is sent, which would invoke the entire script again. -
Can't connect to either one.