Jump to content

svivian

Members
  • Posts

    86
  • Joined

  • Last visited

Everything posted by svivian

  1. If you don't want someone to take your content or code then don't put it on the internet! That's the simple truth. As others said, your code has to be read and interpreted by browsers in order to display it to the user, that's how the internet works.
  2. In a nutshell, XHTML is the same as HTML but with a few differences that make it more "robust": All tag names must be lowercase - i.e. <html> instead of <HTML>) All elements must have corresponding closing tags - i.e. <p>paragraph</p> instead of <p>paragraph Elements without closing tags should use /> - i.e. <br /> and <img src="..." /> instead of <br> and <img src="..."> All attributes must be in quotes - i.e. <span class="test">something</span> instead of <span class=test>something</span> All attributes that are used must have values - i.e. <option selected="selected"> instead of <option selected>
  3. Yes, this is exactly what I was looking for, thanks! Don't know how I missed it in the PHP docs...
  4. I have a function that takes an object as a parameter. In the function I'm doing things like $obj->var - but of course this throws an error if the parameter doesn't exist. I know I can use is_object to check if the parameter is an object, but that doesn't guarantee that the variables I'm looking for exist. So how would I check the type of an object?
  5. ^ You don't need two parameters for each URL, you should do something like: show.php?page=1 show.php?page=2 ...etc Then, with a bit of maths, calculate which records you need for each page on that. Something like: $perpage = 10; $page = $_GET['page']; $min = ($page-1)*10; $max = $min + $perpage; That will give you min=0, max=10 for page 1; min=10, max=20 for page 2. Then simply use those numbers in your MySQL query, in the "limit" clause. Something like: $sql = "SELECT * FROM mytable LIMIT $min, $max";
  6. I know this is a huge bump, but thought I'd post a new solution for this problem that I just came up with while working on something else. Basically, you do a straightforward select all rows query, ordered by your 'grouping' field (season in my case), then by any secondary fields. Then, loop through the MySQL result and store the data in a multi-dimensional array. The first dimension is the grouping field, and the second is your order. The code is below. Hope this helps someone! $result = mysql_query( "SELECT pcode, name, season, sindex FROM episode ORDER BY season, sindex" ); $episodes = array(); while ( ($e=mysql_fetch_assoc($result)) !== false ) { $s = $e['season']; $i = $e['sindex']; $episodes[$s][$i] = array( 'pcode' => $e['pcode'], 'name' => $e['name'] ); } You can then use a foreach to loop seasons, and another inside that to loop episodes.
  7. PHP will close mysql connections when the page has finished executing, so there is no need to do it manually. The only reason you might want to close it, is if there is a lot of processing after you have done all the database stuff, in which case the connection would be open for a lot longer than necessary. Not sure what you mean about the update statement. To check that inserts/updates ran ok, just check the output of mysql_query (it return false on error). See http://uk.php.net/manual/en/function.mysql-query.php If it doesn't return false, then the data has been saved successfully.
  8. I've been working on a contact form for a client that should email them when someone submits it. However, they are not receiving the emails. I've had it sending to my work address, gmail account and other addresses and we always receive it fine. Apparently some ISPs reject email with a bad "Return-Path" header. I have tried setting this in my script in various ways but nothing has worked thus far - the return path is always wrong. Here's the basic code: $emailTo = 'CLIENT ADDRESS'; $emailSub = 'Rooms in Worcester enquiry'; $emailHead = "From: $name <$email>\r\n" . "Reply-To: $name <$email>\r\n"; $emailBody = '...'; if ( mail( $emailTo, $emailSub, $emailBody, $emailHead ) ) { ... } I've tried: - using the "Return-Path" header, with just the email - using the "Return-Path" header, with "name <email>" - adding "-f$email" in the additional parameters Does anyone know any other things I can try? Thanks in advance!
  9. Thanks! That's working a treat. BTW I changed the CASE statements in order to shorten the query and make it easier to read. This brings back NULL instead of 0 for "false" which is fine for me. So instead of... CASE p1.param WHEN 'param1' THEN 1 ELSE 0 END as param1 I have... p1.param='param1' AS param1
  10. I have a table of the form: p_id / param where 'p_id' is a foreign key to an id in another table, and 'param' specifies a parameter applied to that object in the other table. So I might have some data like: 1 / param1 1 / param3 2 / param2 2 / param3 Only the parameters that are "true" are set in the table. What I want to do is get a table like this: p_id / param1 / param2 / param3 1 / 1 / 0 / 1 2 / 0 / 1 / 1 So a set of parameters (that I choose) are used as the fields, and I have a boolean for whether the parameter is on that object or not. Hopefully that makes sense! How would I do this? I've tried a few join queries and such but can't get my head round how to select values from different rows. Grouping doesn't seem to work (though I could probably just get a comma-separated list using the GROUP_CONCAT function).
  11. OK so if I have a class like this: class User { private $db; private $id; private $username; function User( $db, $id ) { $this->db = $db; $this->id = $id; $this->db->query("SELECT ..."); } } Will that pass in and store the $db variable as a reference? Design question: an alternative design would be to keep all SQL queries in the database class, for example a "getUserById" function. The database class would save the result to a User object and return it. Is that a better design? It's a toss-up between keeping the DB functionality all together, or keeping each class's functionality together.
  12. I am using PHP 5, but I've never gotten round to reading up on how to do classes properly, I'm just using the simpler methods that I learned a while back. So you're saying that I don't need the ampersands at all if I'm using PHP 5? P.S. By "access modifiers" do you mean the public/private keywords like in other languages? I had no idea you could do that in PHP! :-\
  13. I have an object that I wish to pass into several classes. Since it is a database class (with query execution functions, etc) I ought to be passing the object by reference. Just wondering, is this the right way to do it? class abc { var $db function abc( &$_db ) { $this->db &= $_db; } } If I've passed the $_db reference in, do I need to use the $= reference as well? Or perhaps it would just be easier to make it a global variable?
  14. If you used the strict doctype IE would display it properly as Firefox does. It's because floats are ignored by their parent element. Solution: add an element after the two floats that "clears" the floating. I think this should work: CSS: .clear { clear: both; height: 0; } HTML: <div class="clear"></div>
  15. Easiest solution is to put line-height:44px; in the #navbar rules. (Using inline-block and vertical-align for the list items is probably the best solution, but some browsers do not support it properly yet). Also, your second set of rules (#recruitTeacher, #postResume...) can be abbreviated to #navbar li if you want it to apply to all the list items inside the ul. Then you don't need the id attributes (unless you're using them for something else, eg a drop down menu).
  16. Don't be so rude, that's not how to get questions answered... I'm not sure exactly what you want. Your three boxes all have the same height so they will be aligned vertically...
  17. If a similar .htaccess works on a different site, it quite possible there is some problem with Apache configuration, for example you may not be able to use the rewriterule or change the options.
  18. I don't know if this is your problem but rFile.php ought to have a slash on the front. If you're in a subfolder it may be looking for the file in the wrong place. Second, does it work if you replace it with two lines, one matching php and one matching js? In other words, splitting the (php|js) part. Also, not a cause of the problem, but why do you rewrite a .js file as a .php file? If it has PHP code in then you could force the JS file to act as PHP (and optionally adding a content-type header to the end of the file to set it back to javascript again).
  19. I'm trying to rewrite URLs like /page to /content/page.php So I've got: RewriteRule ^([^/]+)$ /content/$1.php But I want to ignore certain URLs and folders eg /images. Is it possible to select everything except a specified list of folders?
  20. ^that wouldn't work. You're implying that you can run PHP code when calling a JS function, which you can't do. When the page loads initially, all PHP code is converted to text/html output, so it would try and write something to the database when the page loads, not when the JS function is called. One possibility is to use AJAX, ie call an external PHP script from the JS. You should do any counting from the page that is opened, ie "http://www.??.co.uk/player/player.asp" - it's possible to link through to a MySQL database with ASP.
  21. svivian

    Usemap

    The 'usemap' attribute goes on an image tag, it can't just go on any tag. So instead of using a background image for a page, put the image inline with something like: <img src="..." alt="..." usemap="Map"> Uh, yes it is. It's perfectly valid, who told you it isn't?
  22. If these users will always have accounts then you may as well use the database. And if you want other users to see his customisations then it's the only method. If not, then you'd have to store the IP in the database in order to recognise him when he comes back - but users can change IP pretty regularly (e.g. if their connection goes down) so the cookie approach is probably better in that case.
  23. You've done that round the wrong way, he wants the .html to be rewritten as the PHP file. Should be: RewriteRule ^shop/([0-9]+)\.html$ shop/?id=$1
  24. I keep hearing about SQL injection attacks where someone submits '; DROP TABLE x; in a form where the variable will be used as part of a WHERE clause. But the mysql_query() function clearly states that it must have only one query - "multiple queries are not supported". So does this mean SQL injection attacks are not possible, even with unescaped data?
  25. ^But that's kinda my point. Wrapping the functions in a class has no use, aside from giving them a pseudo-namespace (which can be done with a function prefix, eg "dbQuery", "dbRow"). It would make sense if you're storing something within the class...
×
×
  • 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.