Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. There's lots of different ways to attack this problem. Doing a custom session save handler is one. You write the session data into a mysql table rather than the default, and once you commit to doing that, you can modify the routines slightly so they do a couple of extra things: -Include the user id when the user authenticates -Add a bit of code to your custom session read() function that updates a timestamp column in the session row, you can name something like "last_seen". If you read the http://php.net/manual/en/function.session-set-save-handler.php comments there are several that include implementations you can modify slightly to do this. Once done, you have an intrinsic mechanism (the last_seen timestamp) that you can query using the mysql date/time functions to get a list of people who have actually done something on the site within the timeframe you decide indicates that they are actively logged in.
  2. You are in control of the user registration process, so I don't see any issue there. If you're using mysql, then you can use mysql_insert_id() to get the id of a new row you just inserted. The php http://us3.php.net/manual/en/function.mkdir.php is about as simple a routine as they come.
  3. The claim is basically from my own experience working on an irc bot, and the fact that it was never really stable, but you can certainly see plenty of other complaints when you read about the file wrappers and issues that they have. With that said, I know work has been done on the socket routines to make them better. I don't personally think a web server is a good example, due to the request/response nature of php, but I have always thought nanoweb is a cool project, and I'm sure a lot could be learned from looking at its code.
  4. Does your server configured with open basedir or safe mode?
  5. Just change your onclick to use the ternary operator, to toggle the state from one style to another.
  6. Is this something you're doing just to clean up the data one time, or something you plan to use on an ongoing basis?
  7. It's a value. You can save it to a variable and output that variable anyway you want. If you want to store it in a session variable you can do that too.
  8. Well, the longer I work with Mysql the less it surprises me when they cook up some crazy non-standard syntax. The error you're having is definately a path or permissions issue. Does the path: /center/resources/books/ actually exist? This can't be a relative path, it has to be a real path on the server. It will not make directories for you either -- they have to exist or the move_uploaded_file fails. And as already suggested by codingPhoenix, the directory has to have rwx perms that apply to the apache process as well.
  9. I'm not sure I understand the question. Stylesheets do not support procedural code. They style and format. onClick is a specific event that fires when you "click". The event that matches "hovering" is the "onMouseOver" event, so you can run javascript code when you mouseover an object in the same way that you can run code when you click on an object.
  10. It helps if you actually state what error you're getting. With that said, this is obviously wrong: $sql = "insert into books set name='$name', url='$url'"; An insert statement format that might actually work: $sql = "insert into books (name, url) values ('$name', '$url')";
  11. Here's me in my setup. Total immersion baby.
  12. I would really question what it is that you are going to be doing most of the time. Python can be bent to do Web development, although it is not as well suited to that as PHP. It's used a lot in academia and by scientists. I'm not sure exactly why that is, but I suspect that some of the things I don't like about Python are the very reason people who aren't primarily programmers like it. For example, in Python, indentation of code is important. In fact, you really have to configure your editor so that it uses spaces instead of tabs, and things like that. It's logical, and I guess you could argue that it's terse and efficient not to have to have block delimiters, but I'd rather not have a program not work because I typed an extra space somewhere. As for php, the biggest issue I've seen with it is in people trying to do socket servers and things of that nature. The routines in the language are flakey enough that people regularly avoid them and use curl to for example, connect to a web service or server, even those capabilities are baked right into the file handling routines. PHP doesn't for example, seem to make a great platform for the development of an irc bot, whereas, python does. With that said, you can probably get by with making either language your general purpose language, but I'd certainly consider which task I believe I'll be doing more of and make my decision based on that, rather than which one is more of a swiss army knife. Sure a swiss army knife could be used to dig a ditch, but if you're mostly digging ditches I'm sure you'd rather have a shovel.
  13. It depends on the task, but in general, PHP is mainly a web development language.
  14. I don't think it's a problem to be new and use a framework. In a lot of ways it's a great idea because you'll learn a lot of the best practices from working within the framework, and emulating the structure and design they use. The question of exceptions, like many things is a judgement call, but in my experience you use a try ... catch block because you are doing something that has a flow, and you expect that in most cases it will complete successfully, but there are a variety of unexpected conditions usually embedded within routines called in the flow, that could go wrong, and you want to be able to deal with those "exceptions" gracefully. In my opinion, you're processing a login form, and that's a basic expectation of the task -- that logins fail, and a failed login should in no way require the equivalent of an application interrupt, that drops you out of the application flow and into the exception handling flow.
  15. I'm unconvinced by your explanation. Ajax has nothing to do with what version of these fetch routines you use. I also think that most experienced developers know the various versions of the routines and even if they don't, there's php.net for that. At the end of the day, what you used and what I suggested you use are exactly the same function. Mine is simply an alias that passes the parameter.
  16. FWIW, part of your problem is that you were using double quotes. When you use double quotes for a string, you're telling PHP to interpolate (do variable replacement" of any php variables. To not make that happen, you would have to use single quotes.
  17. Hey, since you bring it up, my boys on the Flyers just spanked you guys the other night. Well it was a pretty tough game actually. Kinda feel bad for Modano though. In a way the Modano situation is similar to what we went through with Simon Gagne this year. He's probably the closest philly had to a Modano - type veteran franchise player. It's painful to see the team turn its back on a guy who is practically the face of the franchise, but in the salary cap era, there's just no room for sentimentality anymore. As it ended up, it's kinda sad to see Modano get injured, and lose what chance he might have had at another playoffs.
  18. I commend you for trying to attack the most efficient solution. Yes, when you join 2 tables together you get a row everytime the two columns can join on the join condition, so you would get a row for every answer of every question. So long as you ORDER BY this select by Question_ID, AnswerID you'll have a result set you can work with, and you can then save the initial question id, output your question markup, then output your answer markup for each answer, until you see that the question_id changed. You don't have to fetch all the rows and foreach through them if you don't want to, you could accomplish this in a single while ($row = mysql_fetch...) loop. Structurally, this is where functions shine, because you write a function that takes a row param and outputs your question markup, and another that takes a row and outputs your answer markup, and you will be left with a tiny easy to understand loop that makes a couple of function calls. It's also a step towards the best practice of decoupling your logic from your presentation code, in that you would move all that presentation code into a function, which could easily include a simple template file that had just the basic markup and variable replacement you need.
  19. People typically use either the gd extension or the imagemagick one. I've only used gd, and find it's the most commonly installed extension. It's really very simple function based code you need: http://www.php.net/manual/en/function.imagecopyresampled.php You simply add that after you've moved the file, and have it save out as your thumbnail, exactly as illustrated in the manual.
  20. Doing a really blown out and sophisticated form, with data cleansing, validation rule checking, error message integration and a mix of complicated form elements, some of which might be connected, is one of the more interesting challenges in basic web development. These frameworks each recognize that and provide form classes and child objects that give you a way of doing forms efficiently with a high degree of sophistication and usability. You could put a toolkit together that would have a lot of these same capabilities yourself, but there's a good deal to it. Here's 2 manual pages to browse. You'll probably notice that there are a lot of similarities and use of design pattern jargon to describe what they are doing (filter, decorator, validator) etc. http://www.symfony-project.org/gentle-introduction/1_4/en/10-Forms http://framework.zend.com/manual/en/zend.form.forms.html In particular, they offer things like validation chaining. So you might have a basic rule that validates the length of a textbox in characters, but then it also might only be valid if it has some text, and even a minimum number of characters, and it also might require that the input have the name of at least one fruit in it. When you start writing this code yourself, big function that is also going to have to associate an errror message with each individual problem, not to mention that it would be better if the form showed all the errors for that column as well as any other columns that they needed to change, rather than only displaying one error. That's the tip of the iceberg in terms of talking about why people use frameworks and in this particular case, form classes. These classes can also be based on the actual database strucure, so that the form knows in advance how to pull data out of the model layer (from the database) and to enforce basic schema level validations without you having to know anything. Symfony really makes this easy because it will generate base form classes from the schema file, and you can derive from those classes. The big win is that you have a built-in form->save() method that already knows how to take a form with some changes, and save it back to the original table, even when that table has a number of related tables. ZF has hooks to do the same things, but again it requires you set a lot of this up yourself via configuration. I should probably say for the record that the current phpfreaks main site, was written using ZF, with the data being pulled from mysql using doctrine integration.
  21. Great. FWIW, all mysql_fetch_assoc is, is a wrapper around mysql_fetch_array($result, MYSQL_ASSOC). Under the circumstances I can see no reason for you to want the numeric key version, since it's a duplication of the same data you get from the associative key version.
  22. You may have left out a key detail. The form must use method="post"! If you neglected to include that, it could explain your results. This page has every thing you need to know to get your file upload working. http://us3.php.net/manual/en/features.file-upload.php
  23. So the obvious thing that jumps out is that you have a problem in your SET columname for the update query. Again this would jump out if ($result) is false and you check the mysql_error(). Do a describe on the table (or use phpMyAdmin) to check the table structure.
  24. AFAIK that shouldn't cause any problems. Hmm, yeah that is something that probably was an issue a long time ago, but mysql doesn't seem to care about that anymore, although it would certainly not work if you were to omit the quotes around a character column comparison.
  25. First on the mysql_select_db() you only need to do that once, and only need to call it again if you're going to change the selected database. Both these tables are in the same db, so just make the connection, select your db, and you're good for any number of queries. The most efficient answer is to join the tables together and get one result set. That is complicated and would require a lot of changes to your code, so I won't suggest you do that. The simpler answer is: Query for questions. Then start fetching and inside your loop do a nested query for the related answers. while ($row = mysql_fetch_assoc($result) { //output your question markup $query = "SELECT Answer_ID, Value FROM Answers WHERE Question_ID = $row['Question_ID']"; $result2 = mysql_query($query); if ($result) { while ($row2 = mysql_fetch_assoc($result2) { //output your answer markup } }
×
×
  • 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.