Jump to content
Larry Ullman's Book Forums

chop

Members
  • Content Count

    192
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by chop

  1. Correction the the above post. To clarify, if I want to order the output by the town in which a particular pet was lost (column= town_lost) AND at the same time not get duplicate data returned (because there may be many returns in the "town_lost" column that are not unique) I have to include the unique column "pet_id" which is my primary key. The correct way to do this is: $order_by = 'town_lost ASC, pet_id'; with the primary key being the second sort and with no ASC or DESC In other words, Larry had it correct... sorry Larry!
  2. Yes, exactly! This worked perfectly: $order_by = 'pet_id DESC, town_lost DESC'; First, order by the primary key "pet_id", then the town names (it's really towns I use not states) follow in the same order. No duplication, no missed data. I never knew I could nest one ORDER BY inside another. thanks!
  3. I have run into a bit of a problem where I get repeated row results on separate pages within a paginated SELECT query. It works okay if I sort on, say, the unique "pet_id" column. But if I SELECT and sort by a column that can have similar items in the column (such as sort by state), it's very possible that results for row 15 (which comes up on page 4), for example, also shows up on page 7. This is a problem not just because things are repeated within the same query, but also, because I am using "LIMIT $start, $display", and if one $result row gets on the page twice, that means tha
  4. On page 516 script 16.9: Line 20: setcookie (session .... //DESTROYS COOKIE This line destroys a cookie set earlier (that was set in login.php? or in the Header?) However I cannot find the corresponding cookie that was set. The value, i see, is PHPSESSID thank you Also, is it always necessary to set a cookie when using a Session?
  5. My book is PHP 6 and MySQL 5, though it doesn't have an edition printed on it (copyright 2008). I might be in the wrong forum but the 3rd edition forum for this book doesn't seem to be active. That said, I am in chapter 16, looking at the code for login.php. I can't find any code for setting cookies in it though the logout.php has the code for destroying the cookies. Unless my eyes have gone buggy, I just can't find it. It seems like the login relies just on sessions. Also, login.php page does print the text "Your browser must allow cookies in order to log in" What am I missing?
  6. Thanks, Larry - I'm glad to hear you say it's tricky. I felt like I was asking another dumb question because it seemed like it should be easy. Too bad I just can't set NULL as a default for the whole column. That would make it easy, then write over it with the md5() when it should be validated. Anyway, I'll probably keep the code as 2 queries written under two conditionals. If I've learned nothing else about programming, it's that code should be easy to understand at first glance after not seeing it for a few months. It might come at the cost of a few extra lines of code but, if I am
  7. Is is possible to Insert a NULL value into a table by assigning it to a variable. For a low level user I want the activated column to have the following inserted: $a = md5( uniqid( rand(), true ) ); // put 32 char code into column "activated" for email verification But for a higher level user, I don't want them to have to verify their email address. So I thought I could set $a = "NULL" or $a= NULL I only end up with the word NULL instead a real null . I also thought there might be away of setting the column to default to NULL. Then the md5 () would write over it and that wo
  8. Okay, I found it.. a <?php ?> in the line above. I think you probably meant I "could" be printing something instead of "should". thanks
  9. I should mention that there is an index.html it should go to. Also, I have tried it with a specific page.php as part of the location.
  10. Sorry, I copied it incorrectly. The code is as follows. Also, I don't know what you mean when you say "print". Do you mean a php print statemet? What is the purpose of that? $url = 'index.php'; // Define the URL. echo "Hello, I should be redirecting now..."; header('Location: https://tenthousandeyes.org'); exit(); // Quit the script.
  11. I've used header() a hundred times. For some reason this just gives me a blank screen. The url exists and the script gets into the conditional and exits. This is a modification of Larry's script in chapter 16 that I get get to work because of this. thanks very much if (!isset($_SESSION['first_name']) || $_SESSION['user_level'] == 0 ) { echo "Hello, I should be redirecting now..."; header('Location: https://tenthousandeyes.org/.php'); exit(); // Quit the script. }
  12. I'm getting old... It's not the code that's at fault, it's the non-code. That is the lack of code in line number 1, which is blank. A blank space outside of any <?php ?> tags is also known as "whitespace". I swore I'd never fall victim to whitespace again after the first 3 times. header() cannot follow any whitespace, ever. header() cannot follow any whitespace, ever. header() cannot follow ANY whitespace, ever. Officially, the php documentation: "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file,
  13. Here is a snippet of code right out of this book. I have been using it for years and it has always worked. Now, it just seems to die on me. It is supposed to take me from login.php to logged in.php. Instead, it goes to the line right after the header(), prints it and stops via exit(). The url in the browser still shows I am at login.php. There are no errors generated. After I log in with login.php (and it stops without going to loggedin.php), I will type the url for loggedin.php directly into the browser and it will get me to loggedin.php with the session already running. I.E., the privil
  14. Hi Larry- I just noticed that you have PHP for the Web 5th edition available last month. I have a couple of questions: 1. An Amazon preview of the book is avail. for Kindle but not paperback. Is there much difference in content between the two? Much rather have the physical book. 2. I own PHP 6 and MySQL 5. Though mySQL is not in the title of PHP for the Web 5th edition, it has chapters on it. So, what is the main difference between the two? From what I understand, you are due to come out with the next edition of PHP (without the 6) and MySQL 5 this fall. In light of the fact that I al
  15. Peter- I don't know the answer to your first question but, as for the second (and I assume you are talking about using it for PHP code), no, don't use Word. Use a plain text editor. such as notepad. Better yet, get a free code editor that will give you the functions you need most like code highlighting and line numbering etc. Do a search for "Best free php code editors" or maybe someone here can suggest something for Windows, if that's what you are using.
  16. (I tried to edit above once more but ran out of time so... last words) My own way of thinking is that "it" would have known that the first 'image_id' meant 'art.image_id' because it is followed by the phrase 'FROM art' which, should be the default table for any column to its left that is NOT prefaced by 'table_name.' . Make sense? Anyway, I'm not going to write anyone a letter explaining the world according to Chop. I have what I need, working code Thanks for hanging in there, Larry.
  17. Wow! Works Perfectly now. Who'd a thunk it? For the record, this is the working code; SELECT image_title, art.image_id, COUNT(other_sales.image_id) FROM art JOIN other_sales ON (art.image_id=other_sales.image_id) GROUP BY (other_sales.image_id) I changed : "SELECT image_title, image_id" to "SELECT image_title, art.image_id" Just one last thought about ambiguity: Why, then, doesn't it think that within "SELECT image_title, art.image_id," that 'image_title' is also ambiguous and should be 'art.image_title' ? Could it be that 'image_id' is used more that once and is being reference
  18. I tried that first thing: SELECT image_title, image_id, COUNT(other_sales.image_id) FROM art JOIN other_sales ON (art.id=other_sales.image_id) GROUP BY (other_sales.image_id) Now I get: #1052 - Column 'image_id' in field list is ambiguous I don't know why it is ambiguous. COUNT(other_sales.image_id) is the column where I wan to count how many times the number (image_id) is listed. I couldn't find any examples like this on a Google search.
  19. I ran your suggested query in phpMyAdmin. Here are the results: SELECT image_title, image_id, COUNT(other_sales.*) FROM art JOIN other_sales ON (art.id=other_sales.image_id) GROUP BY (other_sales.image_id) LIMIT 0, 30 MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) FROM art JOIN other_sales ON (art.id=other_sales.image_id) GROUP BY (other_s' at line 1 Open new phpMyAdmin window I've been trying other variations and have downloaded the MySQL Manual (1000 pages) to
  20. Don't know why I didn't think about that. Probably because all the queries I've ever needed have been simple enough to just write them out and they'd work. If I remember correctly, PHP admin will also give me the php code for queries I run. Queries with joins (of different sorts) have always been a weakness of mine. So perhaps messing around in this way will be good exercise. Thanks for the suggestion, I will post the result if I get something that works.
  21. thank you for that work.. I assume you meant art.image_id in "ON (art.id=other_sales.image_id)" I tried the following and it works: 1. THIS WORKS: $q = "SELECT image_id, image_title FROM art ORDER BY $order_by"; 2. THIS DOES NOT WORK: $q = "SELECT image_id, image_title, COUNT(other_sales.*) FROM art JOIN other_sales ON (art.image_id=other_sales.image_id) GROUP BY (other_sales.image_id)" 3. THIS DOES NOT WORK: $q = "SELECT image_id, image_title, COUNT(other_sales.*) FROM art" I did number 3 just to test if the error might be in the JOIN part of number 2 In each case I get: mysql
  22. I have 2 tables for which I want to write a select query containing an inner join: Table 1 is "art" Table 2 is "other_sales" the (simplified) query so far looks like this (without the JOIN) : $q = "SELECT image_id, image_title FROM art ORDER BY $order_by"; The" image_id" here is a primary key which is also used as a foreign key in the table "other_sales". Let's say that the image_id in "art" = 7. The number 7 may appear any amount of times in the table "other_sales" under the foreign key "image_id" I am trying to write a query that creates a report something like this"
  23. Well, okay, not quite onto other things... just one more complication here. I need to add an anchor to the code below: header( 'Location: http://localhost:8888/sites_in_progress/PNE_development/edit_image.php?id='.$image_id ) ; so that it redirects to a specified location on the page (id="this_location") on the page. I can do it without the variable added on to the header() but not with it there.
  24. Okay, I think I have it: header( 'Location: http://localhost:8888/sites_in_progress/PNE_development/edit_image.php?id='.$image_id ) ; As a final end to this post, the redirect actually does work and I am not having any more problem with the browser refreshing and re-posting duplicate values. The main problem was that the redirect needed to be accompanied with a value that I needed carried over to the next page, which i finally did (above). I also discovered that a "headers have already been sent" error will be caused by things that can easily be overlooked, such as html that has been co
×
×
  • Create New...