KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
Try something like: <script type="text/javascript"> window.onload = function() { var submit = document.getElementById('submit'); var spin = document.getElementById('spin'); submit.onclick = function() { spin.innerHTML = '<img src="images/wheel.gif" />Search Database...'; } } </script> . . . <div id="spin"></div> . . . <input type="image" src="images/search_button.png" class="submit" id="submit" /> You may need to rename the submit variable within the script...I'm not sure if that's a JavaScript keyword or not.
-
Show some example code of the problems you're encountering. I'm betting your issues stem from JavaScript's unique sense of scope and/or closures.
-
[SOLVED] If html tables are "bad" how to output data ?
KevinM1 replied to lonewolf217's topic in CSS Help
This is an odd conversation... Anyhoo, I don't think I've ever seen a site use <dt> in the context of layout. An unordered list and individual list items for navigation (<ul> and <li> respectively for any newbs following along)? Yes. But this stems from those elements making the most sense semantically in that situation (lists of hyperlinks). Unfortunately, HTML doesn't have elements describing navigation structure, so that's the best we can do for now. Hell, you could use a host of <span> elements for top-of-the-page horizontal navigation, or a bunch of small <p> or <div> elements for vertical navigation. No one's stopping you. But, logically, a paragraph really isn't the place for navigation, unless you need an inline textual reference to something else. To get back to the topic of the thread, <div> elements are the cornerstone of CSS-controlled layouts. They make sense semantically (they are divisions of your document), and are themselves pretty simple (just big blocks). Like others have said, the key in forming the layout is in correctly using the tools CSS gives you. To master these tools, you need to know three things: 1. HTML document flow (i.e., how do the elements naturally fit around each other) 2. How CSS positioning options affect document flow 3. The Box Model (how block elements are structured -- in other words, how their margins, borders, padding, and overall size are formed) Make sure you don't neglect the Box Model. I struggled for months with CSS positioning when I first started because I didn't know the Box Model existed. Once I stumbled upon a site describing it, everything else clicked into place. -
RegisterClientScriptBlock Equivalent for PHP?
KevinM1 replied to jungleGuru's topic in Javascript Help
From what little I know of .NET (currently enrolled in an ASP.NET 3.5/C# class), I'm somewhat familiar with what you're asking. No, there's no built-in function to register your JavaScript with PHP, at least, none that I know of. You can simply put it all in an external library file, or within a static header file that's included with each page. Or, if you need to write the JavaScript dynamically, you'll have to roll up your sleeves and write it directly using echo, print, or a HEREDOC. There's no real clean way to doing it that way, I'm afraid. Hey, mind telling me in a private message why registering client-side scripts with the server would be a good thing? My book describes how to do it by using one of the three Register methods, but not why I'd want to. It doesn't even mention what registering a script does! -
At least I know I'm not going crazy (well, with this, anyway).
-
There we go...had to do the same with the session registry, too. I could've sworn it was working before, though. I wonder if the upgrade to 5.2.6 a couple months ago caused it to break (or, looking at it now, behave properly)? In any event, thanks.
-
I decided to download Google Chrome to see how it handled some light AJAX stuff. I decided to navigate to a small test script I wrote a while ago. It was working fine, and I haven't touched its source code in months. It's basically a test of the Front Controller in Zandstra's book with a tidbit of AJAX on top. Nothing particularly useful outside of a learning exercise for myself. In any event, I'm now getting the following error: The line in question is pretty innocent looking (for those who read through the coding style thread in the Polls section, this is my old coding style, which should illustrate how old this is): <?php class MP_base_RequestRegistry extends MP_base_Registry{ private static $instance; private $requests = array(); static function getInstance(){ if(!self::$instance){ self::$instance = new self(); // <-- line in question } return self::$instance; } protected function get($key){ return self::$instance->requests[$key]; } protected function set($key, $value){ self::$instance->requests[$key] = $value; } static function getRequest(){ return self::$instance->get('request'); } static function setRequest(MP_controller_Request $request){ self::$instance->set('request', $request); } } ?> And the base class, for poops and giggles: <?php abstract class MP_base_Registry{ private function __construct(){} abstract protected function get($key); abstract protected function set($key, $value); } ?> Looking over the news items my hosting company has sent out, it doesn't look like they changed anything on the backend that should effect this, and I never attempt to directly call the abstract registry class at all anywhere in these, or other, files. I'm a bit stumped.
-
Well, I think your VB.NET coder friend was thinking of the solution as some sort of Strategy pattern implementation (http://en.wikipedia.org/wiki/Strategy_Pattern). That's the only reason why I can see them suggesting storing the base functionality as an attribute. In general, though, inheritance isn't bad per se, but when building program structures, composition is much more flexable. Looking at your example, without any other context to base my opinion on, I don't think your idea is bad at all.
-
First, give your submit input a name, so you can reference it directly within your PHP code. Then, in bank.php, do something along the lines of: <?php if(isset($_POST['submit'])) //this assumes you named your submit input 'submit' { if(isset($_POST['money'])) { //execute money code } else if(isset($_POST['crystal'])) { //execute crystal code } else if(isset($_POST['ruby'])) { //execute ruby code } else { //any error reporting you need to do?? } } ?>
-
Not only that, but a lot of the issues that come up in this forum are directly related to application design. I mean, how many threads have been started that are basically "Help, I can't get my JavaScript and PHP to behave properly?" I believe that stressing good application design, in conjunction with helping them with their immediate coding problem, is a better solution than just giving them the code to fix it. That's one of the reasons why I cringe whenever I see people give code like: <body onload="someInitFunction();"> . . . <?php while($row = mysql_fetch_assoc($result)) { echo "<a href=\"{$row['url']}\">{$row['linkName']}</a>"; } ?> . . . <input type="submit" name="submit" value="Submit" onclick="alert('You clicked me!'); return false;" /> This is NOT GOOD DESIGN!!!!! It's hard to edit, hard to debug, and necessitates copy-&-paste coding, which is bad. Separating the code into logical segments produces much better results: <?php . . . $output = ""; while($row = mysql_fetch_assoc($result)) { $output .= "<a href=\"{$row['url']}\">{$row['linkName']}</a>"; } . . . ?> <html> <head> <script type="text/javascript"> function someInitFunction() { var submit = document.getElementById('submit'); function showAlert() { alert('You clicked me!'); return false; } submit.onclick = showAlert; } window.onload = someInitFunction; </script> </head> <body> . . . <?php echo $output; ?> . . . <input type="submit" name="submit" id="submit" value="Submit" /> </body> </html> Yes, the JavaScript code is longer than what you'd get if you embedded it, but it's all in one centralized location, meaning it can be extracted into an external file you can use in multiple pages. Not only that, but the JavaScript is completely separate from both the static markup and the markup generated by PHP, so it's easier to follow what the script is doing. Now, obviously, in a contrived, just-off-the-top-of-my-head example like this, the benefits to this approach may not be very evident. But there's a reason why the professionals stress developing in terms of tiers, and in using unobtrusive methods to render output. Now, regarding the OP, it could be, as Skittalz said, that they need immediate results. Fine. But other forces will tug at the seams of the OP's application. Good design application future-proofs projects from these forces. So, maybe the band-aid will work here. But as issues come up, and band-aids become harder and harder to integrate into the core application, they'll probably wish they took the time to properly design their site. So, in the end, they'll be hit twice - once for all of the little tweaks and fixes that they employ, and once for finally biting the bullet and designing their app the right way, which they should've done at the beginning. I don't mean to rant, but shrugging off the importance of application design when helping people who obviously need to rethink the direction of their project is the exact opposite of how we should help them. If it's a matter of them being under a deadline...well, maybe they shouldn't have accepted a project from a paying client that's beyond their current skill level. Just my $0.02.
-
Your code doesn't make sense. First, you set arr to an array of <div> elements. Then, in your second for-loop, you set elem to equal that entire array, which is wrong. You also attempt to use innerHTML on the entire array, which is also wrong. You need to remember to use the array index you're using in the loop. So, instead, you should have: . . . for(var elem = arr[i]; elem != null; elem = elem.offsetParent) { //stuff } . . . data['result[]'].push(arr[i].innerHTML); That should produce...something. At the very least, you should get some sort of output.
-
Then better application design is needed, not a JavaScript workaround that dosen't address the cause of the potential 'headers already sent' problem. A well designed application processes requests first, then renders output, thus avoiding the problem entirely.
-
Here's an easy way to do it. First, give your table an id attribute, then do the following: <script type="text/javascript"> window.onload = function() { var myTable = document.getElementById('tableId'); //get a reference to the table var tableCells = myTable.getElementsByTagName('td'); //get all of its cells for(var i = 0; i < tableCells.length; i++) //loop through all the cells, adding an onclick style toggle to each one { tableCells[i].onclick = function() { if(this.style.backgroundColor == 'white') { this.style.backgroundColor = 'red'; } else { this.style.backgroundColor = 'white'; } } } } </script> This assumes you're using color names rather than hex values. You should be able to adapt this idea to your script.
-
Sweet, another NH resident. I'm an UNH alum, so I'm pretty familiar with Durham. Let's see... Unfortunately, I think the site needs a lot of work. I'll list my issues with it from the top-down. 1. The header images don't blend well. You have the wagon in sunset separated from the rest of the header image. It stands out, and not in a good way. 2. You can probably reduce the redundancy in the header image. Official Website for the Town of Durham, NH would suffice. 3. The text in the header image looks a bit pixelated. Not good. 4. The main header image hides the white border separating the entire header from the navigation. Is this intentional? 5. The horizontal navigation text looks blurry. 6. You should label the left-hand navigation. It's a bit confusing as you have the mailing list button in the same block as the rest of that navigation. 7. In the left-hand navigation, you should separate the text links from the image links. At the very least, put a black (or white) border between the two groups. 8. The main content area is a bit haphazard. I suggest having three blocks - one for News, one for Events, and one for Features - all the same size, lined up next to one another. Limit the entries of each to 5 or so, with a link at the bottom of each block pointing to older entries. That way, the user won't have to scroll as far to read pertinent info. 9. In the right-hand navigation, the 'i want to...' text is blurry. 10. Is there any point for the 'i' image? It looks like it should be clickable. 11. The 'Town Council' and 'Administrator' blocks look out of place. 12. It's a bad idea to remove a link's underline during a mouseover. You should do it the other way around - no underline until the user mouses over the link. Note: all of these items are from me using IE, which is what most of your users will use when visiting your site. All in all, I think that the majority of the criticism I have is based on how the site's info is organized. Having three areas of navigation seems like overkill to me. I think you'd be well served by re-examining how your site info is chunked and how that info relates with other parts of the site. I think having a drop-down menu system would work wonders. You could have something like: government v Town Council >> Council Members Meeting Minutes Next Meeting Agenda Group items that belong to the same category together, and give the user as much navigational freedom as possible, so they don't have to click through several layers of information hierarchy just to get to what they want.
-
Good points. I think my first message came across as a little snarky (I am NOT a morning person ), so I apologize. Let me rephrase: Like the others, and myself, have more or less said, a mentor/apprentice relationship - especially if it's a long distance, online relationship - just isn't conductive to you (the original poster) learning the language. It's inefficient at best, and it's also not fair to us, as the reality is we all have other responsibilities to address during the day. As far as I know, we're all volunteers who stop by when we have a free moment to chat about PHP and help each other with our problems and ideas. Looking for anything more than that from here is just a waste. Now, this isn't to say we won't help with any issues you may have. But we're not going to focus on making you a PHP master. Instead, this community will do what its always done: address the specific problems anyone may have regarding PHP, MySQL, and related technologies. Like I said before, if you really want to learn the language, a good PHP 5 resource is a must. I learned most of my procedural-style PHP and MySQL kung fu from one of Larry Ullman's Visual Quickstart Guide books. I think something like that would be a good place for you to start. And, like ardyandkari and hopelessX suggested, you'd be well served by supplementing whatever you learn on your own by posting questions here and visiting php.net's function reference (http://www.php.net/quickref.php). And if that's not enough, like I said before, you should look at what local colleges offer. Of course, if someone does take you up on your offer, then this is all moot.
-
I doubt anyone here is going to directly mentor you. Your best bet is to find a decent resource on PHP 5 and MySQL, some hosting that has those two items (even free hosting services, for example, Awardspace, often has both of them), and start coding yourself. If you really need to be taken by the hand and shown what to do, you should look for PHP classes at your local community and/or technical college(s).
-
Let me get this straight: You wrote a blog, filled with grammatical errors, ranting and raving about other peoples' blogs having grammatical and spelling errors? To steal a joke from Family Guy, that's like being a dwarf among midgets.
-
Throw in a return false; Statement at the end of your callSlideOut() function. That should disable the default action of the browser following the link.
-
Are you sure your variables contain values? Because there's no syntax error, other than 'process form' not being commented out.
-
Sorting the array i.e., fetched from mysql a/c to position
KevinM1 replied to sreekanth's topic in PHP Coding Help
Ah, good point. -
Sorting the array i.e., fetched from mysql a/c to position
KevinM1 replied to sreekanth's topic in PHP Coding Help
Sure you can: SELECT * FROM tablename ORDER BY total DESC, rank1 DESC, rank2 DESC ... The above query first orders by the total, then by each column in order. -
Sorting the array i.e., fetched from mysql a/c to position
KevinM1 replied to sreekanth's topic in PHP Coding Help
Wouldn't it be easier to just do the ordering in the query itself? $query = "SELECT * FROM tablename ORDER BY total DESC"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo "{$row['rank1']} {$row['rank2']} ... {$row['total']}"; //everything's ordered by the 'total' column } You can most likely add the other ordering conditions right in the SQL query. Far easier to let the DB do the heavy lifting than to do hack through it in the script. -
I don't believe you can nest classes in PHP.
-
If this is for output, like you stated in the JavaScript board, then don't worry about overwriting your PHP code with & Judging by your request, and the obvious difficulty you're having executing such a simple task, it leads me to believe your overall application design is lacking. Like all programming ventures, logical flow and clarity is key. A well-formed PHP application will look like this: PHP: Handle user requests. Scrub/verify/secure incoming data. [1] Query the DB to save/retrieve results. Form and format the output. Store dynamic output (including any JavaScript that's dependant on PHP logic) in variables. Include() static output (like a <div> that acts like a footer on each page). [2] | | | V HTML: Display page structure in a logical manner. Avoid including PHP code within the page structure. Avoid inline JavaScript. So, in your case, you should run htmlEntities() at either point [1], if the output you're concerned about is actually written by a user, or [2] if, for some reason, you decide to keep the '&' characters inside the database but want to transform them before outputting them. In all honesty, your problem shouldn't be more difficult to solve than: if(isset($_POST['submit'])) { if(isset($_POST['description'])) { $desc = mysql_real_escape_string(addslashes(htmlentities(striptags($_POST['description'])))); /* this strips HTML tags from the input, then converts all questionable characters into their HTML entity counterparts, then adds slashes in case magic quotes is turned on (may be redundant because of htmlentities), then, finally, it escapes the input making it ready for storage in the DB */ } }
-
EDIT: got it to work in Firefox: <html> <head> <script type="text/javascript"> window.onload = function() { e = document.getElementsByTagName("body")[0]; e.innerHTML = e.innerHTML.replace(/&/g, "&"); } </script> </head> <body> & & & </body> </html>