Jump to content

nick1

Members
  • Posts

    41
  • Joined

  • Last visited

    Never

Everything posted by nick1

  1. I am also interested in knowing how PHP can connect to an OPC server. Our PHP is running on unix with an Apache webserver. The OPC server is on Windows. Both systems are on the same network. Thanks!
  2. Hi, I am working on a basic blog-style website with articles and comments. I'm aware that similar software already exists (drupal, joomla) but I prefer to roll my own in this case, and besides, it's how I learn. :-) Here are the basic table details: Table Name: users Purpose: Information about people with access to the system. Column Names: id name hashed_password email website last_login_date last_login_ip permissions Table Name: articles Purpose: Articles published by people in users table. Column Names: id title users_id date content Table Name: comments Purpose: Comments on an article published by the public and users. Column Names: id articles_id comments_authors_id date comment Table Name: comments_authors Purpose: Information about people who commented on an article. Column Names: id name email website Work flow: 1.) A user, from the users table, publishes an article. 2.) The article is written to the articles table. 3.) John Doe, not a user, comments on the article. 4.) John's personal info is written to comments_authors. 5.) John's comment is written to the comments table. Sounds good so far. Now consider this… 1.) A user, from the users table, comments on an article. 2.) The user's personal info is written to comments_authors. 3.) The user's comment is written to the comments table. The Problem: Now we have duplicate information about the user. :-( The user's name, email address, and website url are stored in the users table and the comments_authors table. Is this such an incorrect design? Is there a correct way instead? A system with only a few users, maybe not worrying about. A system with hundreds of users, well, that's a lot of duplicate data. I really appreciate your help. Thanks!
  3. Thank you for your help! You showed me how to approach the problem from a different view - that's exactly the kind of help I needed. :-) Nick
  4. Preferably using PHP, I'd like to create X number of colors based on X number of items and using a predefined color range. For example: ITEM VALUE 1 1,234,567,890 2 234,567,890 3 34,567,890 4 4,567,890 5 567,890 Color Range red = largest value green = medium value blue = smallest value Example Item 1 gets color red Item 2 gets whatever color naturally comes between red and green Item 3 gets color green Item 4 gets whatever color naturally comes between green and blue Item 5 gets color blue Requirements The code should be able to handle any number of items. 5 items was just an easy example. Some Thoughts - Number of items = number of colors - How to divide a color range into number of items? - Colors can be represented in decimal format: red=255,000,000 blue=000,000,255 - Can a formula be created, based on the color decimal format, to solve this problem? I think it's the math portion of the problem that I'm stuck on right now. Thanks for your help, Nick
  5. Greetings, The following code hides some DIV elements which can later be displayed depending on user action. The problem is, the DIV elements are displayed on the web page for a brief moment and then hidden. This is NOT the effect I want. The DIV elements should be hidden, not displayed for a brief moment and then hidden. window.onload approach: /*window.onload = function() { hideElementsOnLoad(); } function hideElementsOnLoad () { // When the page loads, hide the form type help list and each form type. var formTypeHelpList = document.getElementById("formtypehelp"); var uniGroupForm = document.getElementById("unigroupform"); var uniAffilForm = document.getElementById("uniaffilform"); formTypeHelpList.style.display="none"; uniGroupForm.style.display="none"; uniAffilForm.style.display="none"; } So, I looked into using Prototype.js to solve the issue of the DIV elements being displayed for a brief moment then hidden. Using Prototype.js, the code above can be replaced with this. The benefit being, the elements are hidden right after the DOM loads but before images are loaded. document.observe("dom:loaded", function() { // When the page loads, hide the form type help list and each form type. $('formtypehelp', 'unigroupform', 'uniaffilform').invoke('hide'); }); Unfortunately, Prototype's way still results in the elements being displayed on the page for a brief moment and then hidden. It's the same result the window.onload approach produced. :-( Another approach would be to hide the DIV elements by default, by using CSS (display:none;). The DIV elements could then be displayed by using JavaScript (display:block;). But I would prefer not to use this approach since the DIV elements would not be visible to a JavaScript disabled device. Perhaps it is possible to hide the DIV elements as the DOM is loading? I am seeking suggestions on how to solve this problem. Thank you in advance.
  6. EDIT: Nevermind, I figured out what the problem was. I'm embarrassed, haha. I decided to replace setInterval with setTimeout, since setTimeout executes displayTime once and then stops. Whereas setInterval continuously executes a piece of code. So, after 10 minutes, 11 intervals would be scheduled - not what I wanted.
  7. When I first set out to learn JavaScript, I had two books with me: 1.) Learning JavaScript by Shelley Powers 2.) DOM Scripting: Web Design with JavaScript and the Document Object Model by Jeremy Keith I found Learning JavaScript too dense so I put it down for awhile and picked up DOM Scripting, and I'm glad I did. I thought DOM Scripting was very understandable and it also explains JavaScript best practices, such as unobtrusive JavaScript and graceful degradation. Later on, I went back to Learning JavaScript which helped me understand some of the more advanced uses of JavaScript, such as AJAX. So, I would recommend starting with DOM Scripting and then moving onto Learning JavaScript. Nick
  8. Greetings, The following JavaScript code displays a clock in a <p id="time"></p> element on a web page and updates the clock once per minute. When letting this code run for ~10 minutes under FireFox 2.0.0.16 on Ubuntu 6.10 and Mac OS X, Firefox eventually becomes unresponsive. A CPU check shows Firefox consuming +100% of the CPU. Am I losing my mind or did I code something incorrect? I'd appreciate your thoughts. Thanks. window.onload = function() { /* * Execute the following functions in the order they appear after the webpage loads. * The reason being, the DOM needs to finish loading in order for these functions to * manipulate certain elements. */ displayTime(); } function displayTime() { var date = new Date(); var hour = date.getHours(); // Returns 0-23. var minutes = date.getMinutes(); // Returns 0-59. // Is it AM or PM? if (hour >= 12) { var ampm = "PM"; } else { ampm = "AM"; } // Convert hours format from 24 hour to 12 hour format. if (hour > 12) { hour = hour - 12; } // Convert hour 0 to 12. if (hour == 0) { hour = 12; } // Convert minutes format to mm for 0-9. if (minutes < 10) { minutes = "0" + minutes; } // Put everything together to form the current time. var time = hour + ":" + minutes + " " + ampm; // Display the time on the webpage. var paraTime = document.getElementById("time"); if (paraTime.childNodes.length > 0) { // Meaning it has childNodes. hasChildNodes doesn't work. paraTime.removeChild(paraTime.firstChild); } paraTime.appendChild(document.createTextNode(time)); // Update the clock every one minute. setInterval(displayTime, 60000); }
  9. Greetings, I'm in the process of learning how JavaScript can be used to work with the DOM. I have a specific problem I'm trying to solve but unfortunately my skills aren't advanced enough at this point to know how to quickly solve the problem at hand. Here is an excerpt of the XML file I am working with: <item> <title>Recipe of the Week: 5-Minute Ginger Pineapple</title> <link>http://whfoods.org/genpage.php?tname=recipe&dbid=236</link> <description>Recipe of the Week: 5-Minute Ginger Pineapple</description> <pubDate>Mon, 11 Feb 2008 08:14:45 -0600</pubDate> <guid isPermaLink="false">tag:whfoods.org,2008-02-11:whfoods.tname=recipe&dbid=236</guid> </item> In this XML file are an infinite number of <item> nodes, each containing different information. First, I want to search the XML file for the string "Recipe of the Week", which will be located in a <title> node. Second, I then want to grab the <title> node's parent node, which is <item>, and all of its children and their information. All of this information will then be stored in a variable so that I can then access the information I need. For example, I could then locate and do what I want with the <title>, <link>, <description>, etc. nodes. Unfortunately, I have found little information on how to search an XML file for a specific string. I'm familiar with regular expressions, but I have a feeling there are more efficient ways of searching an XML file in this case. I would appreciate your thoughts and recommendations on the correct way to solve this problem. Also, I would greatly appreciate recommendations on some quality JavaScript/DOM materials, including book recommendations. Thank you for your time, *Nick*
  10. Thank you for your help. I decided to go with this solution: <script type="text/javascript"> //Purpose: Hides or shows the menu div. //<![CDATA[ var hide = false; function HideShowMenu() { hide = !hide; if(hide) { document.getElementById('menu').style.display = 'none'; } else { document.getElementById('menu').style.display = 'block'; } } //]]> </script> Along with your help, I also found Learning JavaScript by Shelley Powers (O'Reilly) page 263 very helpful. Thanks, Nick
  11. Greetings, On the left side of my website I have a navigation menu built from a table. I would like to give visitors the option of hiding this table. I would like the table to behave like this: 1.) When the website is visited, the table is visible. 2.) Somewhere near the table there is an option to hide the table. This could be a small "<" image, for example. 3.) When that option is clicked, the table is "pushed" to the far left, off the screen. This is the hiding concept. 4.) After the table is hidden, there would exist an option to display the table again. This could be a small ">" image, for example. What is the most correct way to design this feature? Compatibility across multiple web browsers is very important here. I know some CSS and have only seen JavaScript but would appreciate code snippets and technical explanations. Thank you for your time, Nick
  12. http://www.guelphdad.wefixtech.co.uk/sqlhelp/numericdata.shtml answers my first two questions. Any thoughts on my third question? Thanks, *Nick*
  13. Greetings, In short, the MySQL LENGTH parameter is driving me a little crazy. For example, lets say we have a table named TEST with just one column called NUMBER. The datatype for NUMBER is set as SMALLINT(3). "(3)" is the LENGTH parameter. At first glance I would think that its purpose is to limit the number of digits allowed in the column called NUMBER. Maybe this really is its purpose and I'm just not understanding. According to http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html : " Another extension is supported by MySQL for optionally specifying the display width of integer data types in parentheses following the base keyword for the type (for example, INT(4)). This optional display width is used to display integer values having a width less than the width specified for the column by left-padding them with spaces. The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters. " I decided to test this out using the TEST table mentioned above: Table Name: TEST Table Info: Field____Type_________Null____Key____Default____Extra NUMBER___smallint(3)__YES_____blank__NULL_______blank Inserting 12345678 into NUMBER results in 32767 being inserted instead. This partially makes sense since SMALLINT has a range of -32768 to 32767. My questions are: 1.) What's the point of declaring SMALLINT(3) then? 2.) The way the MySQL documentation makes it sound is that specifying the LENGTH parameter allows the range to be expanded by LENGTH. For example, SMALLINT(3) would mean -32768xxx to 32767xxx. Therefore, 12345678 should've been inserted. 3.) I was really hoping MySQL would've returned an error when trying to insert 12345678 into NUMBER, but it didn't. It inserted 32767 instead, appearing as though the command completed without error. Is there a way to make MySQL say "hey, the number you're trying to insert into this column is longer then 3 digits - access denied."? I hope this makes sense. Thank you for your time, *Nick*
  14. Greetings, I'm hoping someone who's been down this road many times can tell me if I have my story straight. I would like to use apache and mysql to authenticate users to an "administrator only" portion of my website. I would also like the communications over that portion of the website to be encrypted. This is all on a LAMP installation of the newest version of Ubuntu server. I've done some research and it looks like I need the following: 1.) Apache/MySQL authentication : mod_auth_mysql 2.) Secure Communications : SSL Is this correct? I've read of something called mod_myauth for apache2. What is the difference between mod_auth_mysql and mod_myauth ? I was a little surprised of the lack of documentation on setting up mod_auth_mysql. Can you recommend some thorough tutorials on these subjects? Any other advice from the battlefield would be greatly appreciated. Thank you for your time, *Nick*
  15. Greetings, Please see the attached image for this post, it serves as an example for my question. What I'm Trying To Do: Create two auto-populated drop-down boxes based on the contents of the CATEGORY and COOKINGMETHOD fields. These drop-down boxes will appear on a data entry webpage which submits its contents to the database. 3 Ways To Achieve This (that I can think of): 1.) Break out CATEGORY and COOKINGMETHOD into their own tables then place their foreign key into RECIPE. This would allow the contents of each drop-down box to have the most accurate list of categories. It would also narrow down the possibility of a user misspelling a CATEGORY or COOKINGMETHOD, since an administrator would be in charge of adding a new CATEGORY or COOKINGMETHOD to the database. In the current design (see attached image), if a recipe is deleted, its CATEGORY and COOKINGMETHOD are also deleted. Therefore, if Grilled Eggplant was the only desert in our recipe database, then when a user tries to enter a new desert recipe on the data entry webpage, the drop-down box will not have a desert option listed since it was deleted when Grilled Eggplant was deleted. Database performance should be considered if going this route. Is it worth breaking these two fields out into their own tables just to satisfy the layout of the data entry page? What if there were more auto-populated drop-down boxes we wanted to place on the data entry webpage that were based on the contents of other fields? This could result in many small tables. 2.) Use the current design and auto-populate the drop-down boxes based on the values in CATEGORY and COOKINGMETHOD. Although the easiest method, it can lead to the same problem discussed in the later part of #1 (see above). This method would require an input box (so that users could create a new category if one is not listed in the drop-down box) and a drop-down box (so users could select a category if it is already listed in the drop-down box) on the data entry webpage. The chances of misspelling increase, two boxes are required instead of one, and the drop-down boxes might not always contain a category or cookingmethod for the recipe the user wants to enter. 3.) Auto-populate the drop-down boxes based on hard-coded values in the code. This would mean having to edit the code each time a new CATEGORY or COOKINGMETHOD is needed (or other value in a different field). This option makes me nervous. I'm sure my question is pretty basic and has been answered millions of times over by more experienced developers. I would appreciate your advice. Thank you for your time, *Nick* [attachment deleted by admin]
  16. Greetings, I am considering earning some type of web development certification and was wondering if anyone could recommend a particular program, such as the Certified Web Professional Program or World Organization of Web Masters program. I'm looking for a quality program that is widely known and whose graduates are sought after in industry. Thanks, Nick
  17. Greetings, Consider this post more of a therapy session. I have this anti-javascript attitude that I've been carrying around with me for awhile and I really don't know why. It's not that I don't understand javascript or don't think it's useful. Maybe my fear of it is based on other peoples opinions about it. As I write this, I'm recalling people I've encountered who have used phrases such as "evil javascript" or "eww, javascript" or "insecure javascript" when discussing web development. Or maybe I avoid using javascript because of accessibility issues, meaning that a user can disable javascript in their browser if they choose. In doing so, part of my application is now useless to that user. For whatever reasons I have been avoiding using javascript, I would like your thoughts on it. Do you avoid it too? If so, why? Or are you of the opposite frame of mind - you love to use javascript in your web development? Or maybe you use it only when necessary. Either way, I'd appreciate your thoughts. Thanks, *Nick*
  18. thorpe and Snooble, thank you for your thoughts and suggestions, I appreciate them. I too have considered using a more "robust?" language to accomplish this task. PHP is probably my most comfortable language at the moment, but this project could be a good excuse for me to learn another language, such as Perl or perhaps C? I was wondering if you can recommend any specific books on programming that are really excellent learning tools and not just another programming book? Walking into the programming section of a book store can be like walking into the amazon without a guide... except the books cost more. Thanks for your input, *Nick*
  19. Fellow friends in PHP, I turn to you in great frustration regarding my search for a general-purpose log file analyzer. You're probably saying "why are you posting about log analysis here, idiot." Well, because since it appears that I cannot find a log analysis product that fits my needs, I'm tempted to write a PHP script that does fit my log analysis needs and I want your feed back on if there is a better way to go about this madness. Here's what my ideal log analyzer would do: -Apache: report all information about who is accessing my web server (IP, time, browser, OS, etc). Also report on any errors. For this information I can look to AWstats, Webalizer, etc. But there's a lot more information I want reported. Keep reading. -MySQL: report who is accessing the database, time of access, queries used, any errors, etc. -PHP: report any errors that might have occurred. -SSH: report who is accessing the SSH server, time of access, IP the server was accessed from, etc. -IPtables: report on successful and denied requests, scans, attacks, etc. -System logs: report on any operating system errors, etc. It would be ideal if such a program could generate one master report, each section of the report containing information about a different log file. I'm developing an administrator webpage for my website where I can edit my database and *hopefully* setup my theoretical log analyzer to generate a master report on the criteria above, at the click of a button. That's where the PHP script comes into play - it IS the log analyzer Please tell me such a product exists. If not, what magnitude of a project are we talking here? Again, if there's a better way to go about all of this, please, do tell. All feedback is welcomed. Thanks, Nick
  20. Greetings, While working on some CSS tonight, I had one of those "what the heck, why not" moments. I applied an ID and a CLASS to a DIV to see if the DIV would take on both rule sets. I didn't expect this to work since I never tried it before. But to my surprise, it worked: <div class="component" id="operatingsystem" > blah blah blah blah blah </div> I apologize if I'm showing my "newbieness" to CSS. Now my question: is this considered 100% valid markup? It definitely reduced a whole bunch of redundant markup for me. I'm just hoping my technique is considered valid. Thanks, *Nick*
  21. Greetings, I would like to know what your thoughts are on using multi-purpose PHP pages. I've been reading a little bit about them but am still deciding if I feel comfortable with the idea and if multi-purpose pages just make coding more confusing and if they are a hindrance on server performance. An example I have in mind is this: page1.php contains the following: click here to show all authors in the d.b. page2.php contains the following: displays all authors as requested in page1.php first author name is displayed here now click here to delete the author from the d.b. page3.php contains the following: a php script that deletes the selected author So, that's a total of 3 php scripts. I suppose another option would be to populate a drop-down box with all of the authors in the d.b. Then, when an author is selected from the drop-down box, a delete button can be clicked and a script on page2.php would be executed which deletes the author from the d.b. So, we've eliminated an additional script. Anyway, I hope this makes sense. I'm a little fried right now from coding most of the day. I'd appreciate your feedback. Thanks, *Nick*
  22. Greetings, It's been awhile since I've actually had to design a database schema. Lets say you're an I.T. person at your organization and you want to development some type of inventory system that keeps track of all your servers, switches, routers, environmental monitoring units, KVM's, etc.  This inventory system will use a MySQL database to organize things.  Your core question is "How do I uniquely identify each one of my devices?" That's my question too. I was thinking this over and came up with several criteria by which a device could be uniquely identified.  A device could be uniquely identified by: -serial number -name -IP address -MAC address -some database-generated number Then I thought about the pro's and con's of each of these items: -Serial number: Pro's: Each device has a unique serial number. Con's: However each serial number can have several devices.  For example, virtual hosts(think VMware).  One virtual host can have many virtual servers inside of it.  As a result, many devices can have the same serial number. -Name: Pro's: Each device has a unique name.  No two devices can have the same name. Con's: ? -IP Address: Pro's: Each device has a unique IP address.  No two devices can have the same IP address. Con's: One device can have several IP addresses (some funky NIC setup).  A virtual host that uses NAT for its virtual servers (this is probably rare though).  A network device that performs NAT and has computers behind it(again, probably rare at our organization). -MAC Address: Pro's: Each device has a unique MAC address but do ALL devices have a MAC address?  No two devices can have the same MAC address. Con's: ? -Some database-generated number: Pro's: Each device would have its own unique # that would be generated by MySQL.  No two devices can have the same #. Con's: none. So my question is:  what's a solid "key" to use which can uniquely identify each device?  Maybe the best option is using two keys? Or maybe there's a better key to use besides that which I've mentioned here? All suggestions are greatly appreciated. Thank you for your time, *Nick*
  23. Greetings, Lets say we have a MySQL table called Warranty.  The table could look something like this: +---------+---------------+-------------+-----------+ | serial# |  description  |  startdate  |  enddate  | +---------+---------------+-------------+-----------+ | 1234    |  blahblahblah |  2000.1.1  | 2000.12.30| +---------+---------------+-------------+-----------+ | 1234    |  uh huh yeah  |  2001.1.1  | 2001.12.30| +---------+---------------+-------------+-----------+ | 5678    |  something    |  2006.1.1  | 2006.12.30| +---------+---------------+-------------+-----------+ | 5678    |  some more    |  2007.1.1  | 2007.12.30| +---------+---------------+-------------+-----------+ As the table shows, it is possible for one serial# to have multiple warranties, this is fine. Now lets say we want to display all of the information in the warranty table to the web browser. Doing so is quite easy via the standard methods.  However, to make things easier on the users eyes, it would be helpful if each group of identical serial#'s were colored-coated with the same background color. For example, all serial#'s which are "1234" would have a background color of gray.  The next group of serial#'s would have a background color of white.  The next group of serial#'s would have a background color of gray.  And so on and so forth, alternating between gray and white backgrounds. It is easy to make every other row gray, but I am having a difficult time figuring out how to make the background color of identical serial#'s the same.  Any input would be greatly appreciated. Thank you for your time, *Nick*
  24. The following command executes successfully at a command line: [code]smbclient //192.168.206.1/d$ -U me mypasswd -c 'get test.txt' /home/me/test.txt[/code] However the following PHP code fails and returns error "Error opening local file test.txt": [code] <?php //Connect to a Windows share and download a file. $results = shell_exec("smbclient //192.168.206.1/d$ -U me mypasswd -c 'get test.txt' /home/me/test.txt"); print_r($results); echo "<div>$results</div>"; ?> [/code] Any suggestions? Thanks, *Nick*
  25. Some updates: The following PHP script appears to not fully execute... [code]<?php //Connect to a Windows share and download a file. $results = shell_exec("smbclient //192.168.206.1/d$ -U me mypasswd ; get test.txt /home/me/test.txt ; quit"); print_r($results); echo "<div>$results</div>"; ?>[/code] ...I checked the Windows logs and the script is connecting then immediately disconnecting and not transferring text.txt.  I think "; get test.txt /home/me/test.txt ; quit" is not being executed.  Why? I can however issue the smbclient commands manually at the command line, one command at a time, and successfully transfer test.txt. So next I figured I'd try writing a shell script then executing the shell script in PHP... Contents of shell script: [code]#!/bin/bash #Test script smbclient //192.168.206.1/d$ -U me mypasswd && get test.txt /home/me/test.txt && quit[/code] Contents of php script: [code]<?php //Connect to a Windows share and download a file. $results = shell_exec("sh shell"); print_r($results); echo "<div>$results</div>"; ?>[/code] ...I checked the Windows logs and the script is connecting then immediately disconnecting and not transferring text.txt.  Again, I think "&& get test.txt /home/me/test.txt && quit" is not being executed.  Why? Thanks, *Nick*
×
×
  • 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.