Wikipedia:Reference desk/Archives/Computing/2016 April 30
Computing desk | ||
---|---|---|
< April 29 | << Mar | April | May >> | May 1 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
April 30
editnull value in MySQL table
editI'm trying to insert a null value into a MySQL table but I keep getting all zeros for the date, i.e. 0000-00-00. I've tried single quotes around the Null, I've tried lower case null... What am I doing wrong?
if (isset($_POST['add_animal'])) { // /user hit submit
// check the NOT NULL columns to be sure they have a value.
// the next 5 post vars are NOT NULL so they should have a value
$name=$_POST['name'];
$species=$_POST['species'];
$birthdate = $_POST['birthdate'];
$color = $_POST['color'];
$breed = $_POST['breed'];
// For values that allow a NULL
$fixed_date = !empty($_POST['fixed_date']) ? $_POST['fixed_date'] : "NULL";
$query =
"INSERT INTO animal (name,species,birthdate,color,breed,fixed_date) VALUES
('$name','$species','$birthdate','$color','$breed','$fixed_date')";
// print $query;
$result = mysqli_query ($db, $query);
if (!$result)
print "ERROR: Add New Animal Failed on INSERT " . mysqli_error($db);
else {
print "<br />New Animal Added <br />";
print "<form>";
print "<button type='button' onclick=\"window.location='add_animal.php';\">Add Another Animal</button>";
print "<button type='button' onclick=\"window.location='animals.php';\">Display Animals</button><br>";
print "</form>";
}
}
Thanks, Dismas|(talk) 02:01, 30 April 2016 (UTC)
- One point - don't use the raw $POST variables to generate the SQL. See SQL injection. Tevildo (talk) 07:29, 30 April 2016 (UTC)
- I don't use either MySQL or PHP, but one obvious problem is that you seem to be using the string
'NULL'
in yourINSERT
statement, which MySQL may be converting to 0000-00-00. As Tevildo says, this way of constructing dynamic SQL statements is not best practice, especially without sanitising the inputs, but if you're going to do it then you would need to set$fixed_date
to either (the string) NULL or (e.g.) '2016-05-01' (including the quotes) and not use the quotes in the$query = ...
statement. AndrewWTaylor (talk) 10:15, 30 April 2016 (UTC)
Thank you both. I got it figured out by using the following:
$fixed_date = !empty($_POST['fixed_date']) ? $_POST['fixed_date'] : 'null';
if (empty($_POST['fixed_date']))
$query =
"INSERT INTO animal (name,species,birthdate,color,breed) VALUES
('$name','$species','$birthdate','$color','$breed')";
else
$query =
"INSERT INTO animal (name,species,birthdate,color,breed,fixed_date) VALUES
('$name','$species','$birthdate','$color','$breed','$fixed_date')";
It's a bit lengthy but works. I'm not too worried about SQL injection as this is only a class project and not meant for a live environment. Also, it's a course on databases and not web dev, even though our final project is to slap a front end on the database. Thanks for responding though! Dismas|(talk) 11:56, 30 April 2016 (UTC)
- This is the way into the abyss. --Stephan Schulz (talk) 12:42, 30 April 2016 (UTC)
Queue reservation system
editI have a thought experiment that doesn't quite make sense to me, so I'm hoping to clarify it here:
- First consider an ordinary queue system: To make it easier to visualize, let's make it a real world situation, like a queue ("line" in US English) at a grocery store. Each person joins the queue when they are ready to be checked out, then waits for their turn.
- Now consider my queue reservation system: Back in the grocery store, we assume each customer has a kid with them, and asks the kid to wait in line as soon as they enter the store, while the parent goes shopping. So, while the parent shops, the kid moves higher and higher in the queue order. If they get to the front before the parent is done shipping, they let one, and only one, customer past them, until that customer is checked out, then they let the next customer past them, etc. Let's assume that the shopping time is sufficiently long compared with the queue length so that the kid is always at the front by the time the parent finishes shopping. So then, when the parent returns there should only be 0 or 1 customers in front in the queue.
So, the second scenario is a gain for the customer (and kid) who uses it, at the cost of those customers who would have been in front of them, but are now behind them, having to wait longer. (Let's not discuss the ethics of this, I'm just interested in the facts.)
My trouble comes in when I consider what happens if everyone uses the same queue reservation system. It seems like there should be no gain for anybody then, on average. However, I have difficulty conceptualizing how this works out to be the case. For example, if there would have been 10 customers in front with full baskets, if nobody used the queue reservation system, and now instead there are 10 kids holding places, when Mom is ready to check out, doesn't she still go right to the front of the queue ? I suppose there is some chance that other customers with earlier queue reservations will finish shopping right at the same time, so our customer will have to wait for them, too, but it seems implausible that all 10 would finish at once. So, would we end up with more place holders than we would have customers, without the queue reservation system ? I can see this when the business first opens, but a business that is open 24 hours a day doesn't seem like it would have this issue.
Any thoughts ? (This is posted on the Computer Desk because of the possible application to computer queues.) StuRat (talk) 17:00, 30 April 2016 (UTC)
- There are two issues you need to detail. Assume all the kids are in line and nobody ever finishes shopping. Do the two kids in the front of the line keep swapping places? Now, one person who is not in the front finishes. What happens? You said one and only one may pass. If the two in front aren't done shopping, they can, at most, just swap places over and over. They won't let the person finished shopping move up in line. So, how does that person get to the front of the line? 47.49.128.58 (talk) 17:47, 30 April 2016 (UTC)
- When a customer checks out, the next real customer moves to the front, past all place-holders. A place-holder never lets another place-holder move past. If the queue consists of place-holders only, then nobody moves. StuRat (talk) 18:49, 30 April 2016 (UTC)
- Isn't this just the same as having priority customers who automatically go to the front of the queue past normal customers? In the case of the computer implementation, you just interrupt the normal processing to give priority (no placeholders needed). Dbfirs 19:02, 30 April 2016 (UTC)
- No, it's like giving all customers high priority, which doesn't seem like it should change anything, but when we talk about the specifics, it somehow seems like it does. This is what I don't quite understand. StuRat (talk) 22:08, 30 April 2016 (UTC)
- I don't really understand why you think it will change anything, unless behaviour changes. Queing is complicated but if we assume there is no change in behaviour (which is unlikely but beside the point), then your high priority isn't going to work if everyone is using it. I haven't read the complicated discussion but what will happen will either be that the ques are exactly the same with a bunch of kids pointless standing somewhere in the que, or the que will be different because some people who happen to be lucky will get to skip the que because their kid happens to be at the right place when they come to join the que. Either way the average waiting time will be the same. Nil Einne (talk) 17:58, 1 May 2016 (UTC)
- I should have been more careful in my phrasing. As 209 pointed out below (I think some other people did elsewhere but as said, I didn't pay that much attention), another possibility is that the first to arrive in the supermarket will be pushed to the front of the que. So it's not random or "luck" based but is different from the normal order (first to arrive in the que after finishing). The main point still stands though, the average wait time isn't going to significantly change but the order in the que may or may not change. Significantly is another clarification here. For large numbers, the averages will likely not change much. For small numbers, the averages may change. Even by random chance, those who take longer may end up more in front or at the back. It may not even be random. Depending on precisely how it works there may be a built in bias. (If it's first in to supermarket ends up in front of the que, these could take longer on average.) Nil Einne (talk) 18:07, 2 May 2016 (UTC)
- I don't really understand why you think it will change anything, unless behaviour changes. Queing is complicated but if we assume there is no change in behaviour (which is unlikely but beside the point), then your high priority isn't going to work if everyone is using it. I haven't read the complicated discussion but what will happen will either be that the ques are exactly the same with a bunch of kids pointless standing somewhere in the que, or the que will be different because some people who happen to be lucky will get to skip the que because their kid happens to be at the right place when they come to join the que. Either way the average waiting time will be the same. Nil Einne (talk) 17:58, 1 May 2016 (UTC)
- No, it's like giving all customers high priority, which doesn't seem like it should change anything, but when we talk about the specifics, it somehow seems like it does. This is what I don't quite understand. StuRat (talk) 22:08, 30 April 2016 (UTC)
- I've already stated that it shouldn't make any difference, on average. What I'm asking about is the exact mechanism by which those with a queue reservation are delayed as much as they would have been without one. By analogy, we know that perpetual motion machines are impossible, but if we see something that keeps moving seemingly forever, we then need to figure out how (such as hidden source of energy, like sunlight). Or, for a math example, the "always double your bet until you win" gambling strategy seems to guarantee you can never lose, but we know that isn't possible. The answer there is that there is a very low, but significant, possibility you will lose your entire bankroll, which makes it so you won't win on average. StuRat (talk) 16:25, 3 May 2016 (UTC)
- FILO (first In – last Out) = stack (abstract data type) or FIFO (first in – first out), which is a queue or circular buffer, when input and output are syncronized, in a basic circuit, called a shift register, also used in CPUs to divide by two when shifting right or multiply by two when left left. Analog shift registers are used for sustain of sampled audio or reverberation. Did You mean basics of computer multitasking on depending tasks like parallel computing (Parallel processor)? --Hans Haase (有问题吗) 19:11, 30 April 2016 (UTC)
- The question asked, "What happens if everyone uses the queue reservation system." That means there are no actual customers in the queue, ever. There is simply an unending number of mothers who enter the store and send their child to the back of the queue. Now, in that case, no child would move until a mother showed up with her groceries at her child's position. At that time, the most logical thing to happen would be for that mother to advance to the head of the queue, pay at the checkout, and leave with her child, with every other child retaining his/her position in the queue. There is no logical justification for the children ahead of hers to drop back. Why should they lose their priority? Akld guy (talk) 21:26, 30 April 2016 (UTC)
- When that mother shows up with groceries and moves to the front, that pushes every child which was in front of her child back one spot, while children who were behind hers are in the same position in the queue, although now one of those in front of them is a mother with groceries which was formerly just a place-holder. However, I disagree with your statement that that "...means there are no actual customers in the queue, ever". If it were that simple then my queue reservation system would have somehow eliminated all waiting at the checkout counter, and we know that can't be right. Here's where the question comes in. Why isn't it that simple ? One reason is that additional mothers can show up with groceries before that last one has finished checking out, but still, that doesn't seem like enough to make the universal queue reservation system just as bad as if nobody was using it. StuRat (talk) 22:03, 30 April 2016 (UTC)
- However, I disagree with your statement that that "...means there are no actual customers in the queue, ever". Really? But your own question said, My trouble comes in when I consider what happens if everyone uses the same queue reservation system. When you've figured out what you're trying to say, get back to us. Till then you're just wasting everyone's time. Akld guy (talk) 22:29, 30 April 2016 (UTC)
- By 'customers', I meant mothers. You surely didn't think I meant there would be no queue at all, did you? Akld guy (talk) 22:46, 30 April 2016 (UTC)
- No, I took "customers" to mean mothers with full baskets, but I don't understand why you think there will never be any in the queue. StuRat (talk) 23:01, 30 April 2016 (UTC)
- I am unable to understand what part of the description is unclear to you. Perhaps you are thinking of "reservation" as meaning a specific time ? That's not the case here, all that is reserved is an earlier spot in the queue. Thus, if some other mom with an earlier reserved spot shows up first, she will still get in front of later moms, and then we have more than one mom in the queue with a full basket. StuRat (talk) 22:46, 30 April 2016 (UTC)
- I see now what you mean. Initially (when the doors open) a queue of children forms at the checkout as customers come in, but within a short time mothers with carts join the queue at random times, so yes, the children at the head of the queue would drop back to the tail of the queue, allowing each mother/child to move up to the back of the mother/child queue. Akld guy (talk) 23:35, 30 April 2016 (UTC)
- Not quite. The children at the head of the queue don't drop back to the tail. Rather each mother joins her child at that child's spot in the queue. The only case where a child drops back is when they are at the front of the queue and then they only drop back one spot, as the next mother/child pair moves up to the front. The remaining mother/child pairs remain where they are in the queue. StuRat (talk) 23:58, 30 April 2016 (UTC)
- OK, child or empty position=0, mother+child=1. In 8-bit, the queue would initially be 00000000. A mother with cart joins her child at bit2, which would be 00000100. They go to bit7 (checkout) and displace the child there. Bit7,6,5,4,3 children drop back 1, so bit2 is again occupied and it's now 10000000. While they're paying, another mother joins her child at bit4 (10010000). This mother and child advance to bit6 to wait for the checkout to become available and the children at 6 and 5 drop back to 5 and 4 respectively, so it's now 11000000. In each case when a mother joins her child and advances to the back of the mother+child tail, the child there and the ones that were ahead of her child drop back 1. Is that it? I could write that as a right shift operation in Assembler in a few lines. It's fairly trivial. Akld guy (talk) 01:20, 1 May 2016 (UTC)
- Almost right. The second mother/child pair wouldn't advance until the first pair had checked out completely. Also, I'm not sure if we should equate an empty slot with one reserved by a child. If I were to model it, I would use lowercase letters for the child only, uppercase for the child/mother pair, and a 0 for empty. So, your scenario might go like this, with the addition of another pair:
00000000 <- store opens abcdefgh <- kids fill the queue while their mothers shop abcdeFgh <- mother of child f joins him in the queue Fabcdegh <- pair F is promoted to front of queue FabCdegh <- mother of child c joins him in the queue FaBCdegh <- mother of child b joins him in the queue aBCdegh0 <- pair F checks out and leaves queue BaCdegh0 <- pair B is promoted to the front of the queue
- This is the same as the "give each customer a number as they enter" system, with the proviso that places are reserved if a customer is not ready when their turn arrives. Dbfirs 09:15, 2 May 2016 (UTC)
- I'm still don't think this has been described well enough. Assume there are only two customers, A and B. A comes in first. B comes in second. B finishes shopping first, so B checks out first. Then, A checks out when done. There was no point in the kids standing in line. It is just the first to check out will check out first. Now, assume that A finishes shopping first. A checks out first, then B. So, again, there was no point in the kids being there. Assume B is checking out when A finishes. A has to wait for B to check out. Assume A is checking out when B finishes. B has to wait for A to check out. With two customers, having kids makes no difference. Now, add customer C. They arrive in order A, B, and C. Whomever finishes shopping first is promoted to the front of the line and checks out. Then, the next person to finish shopping is promoted to the front of the line and checks out. Then, the last to finish shopping checks out. There was no point in the kids standing in line. The only way the kids can make a difference is if someone finishes shopping while someone else is checking out. With A, B, and C, if one is checking out when another finishes, then one waits in line and then checks out. In the case that only one customer waits in line for a checkout, the kids don't matter. The checkout order is the same. Now, the problem... Assume that A is checking out. Then, C finishes and gets promoted to the front of the line behind A. Then, B finishes. Does B get promoted in front of C? If not, then it is a first-to-finish-shopping is first-to-checkout system. If C does get in front of B, then it is a priority system. The line is always sorted in alphabetical order for customers A, B, C, D... The kids don't matter either way. It is either a FIFO system or a priority system. So, what makes this so different? 209.149.115.199 (talk) 12:31, 2 May 2016 (UTC)
- 209.149, I agree with your analysis up to here: "Now, the problem... Assume that A is checking out. Then, C finishes and gets promoted to the front of the line behind A. Then, B finishes. Does B get promoted in front of C?" Answer, yes, that is the whole point of the kids holding the places in strict A,B,C... priority as they entered the store, as declared by the OP. It is a priority system. Akld guy (talk) 20:02, 2 May 2016 (UTC)
- The logic box posted above by OP makes that clear. Pair B is promoted to checkout ahead of pair C who were actually ready to pay and leave before pair B. Akld guy (talk) 22:14, 2 May 2016 (UTC)
- Yes, that's why I added that part. Customer B, who finished shopping after customer C, still checks out earlier, because they arrived at the store earlier, and their kid had a higher place in the queue. The only way a later arriving customer should check out earlier, is if they are done shopping first and also there is nobody checking out at some time between when they finish shopping and when the earlier arriving customer finishes shopping. StuRat (talk) 16:19, 3 May 2016 (UTC)
- It's a shortest job first scheduling with everyone starting at time=0. In the 'thought experiment' scenario, there's no difference whether all the boys line up at time 0 or they stagger in.
- Using that notation:
abcd <- original queue Cabd <- C is done shopping at TimeC, so it starts checking out CaBd <- B is done shopping at TimeB, nothing happens yet CABd <- A is done shopping at TimeA, which is the same time as TimeB effectively (difference is in granularity of checkout time) ABd <- C is finally done ABde <- E joins in BdE <- A is done, B starts checking out, and E gets done Ed <- B is done, E starts checkout, cause TimeE is shorter than TimeD
- E joining the queue just proves that joining the queue after the start doesn't matter. It could have started with abcde with the same result. The shortest order will be TimeC, TimeA == TimeB, TimeE, TimeD. --Wirbelwind(ヴィルヴェルヴィント) 06:43, 4 May 2016 (UTC)
Dezoom
editOnce again online dezoomify has failed here. Firefox suggests they are separate unstitched images at full size, but I'm not sure. What software is good for extracting full-sized images from that Digital Scrolling Paintings Project? Thanks. Brandmeistertalk 19:22, 30 April 2016 (UTC)
- I don't know why dezoomify failed, but I downloaded and stitched the 1,911 tiles with my own script. Should I upload it over File:Court Ladies Preparing Newly Woven Silk.jpg or somewhere else? -- BenRG (talk) 09:37, 1 May 2016 (UTC)
- @BenRG: Yep, feel free to overwrite. For some reason I still can't run dezoomify.py properly on Win 7. After launching Dezoomify.py and opening the command line, I copy-paste, for instance, python dezoomify.py -i http://www.bl.uk/onlinegallery/onlineex/evancoll/a/zoomify72459.html -q 90 -o c:\output.jpg to the command line, but after pressing "enter" get "the name python is unrecognizable". Same is happening with other URLs. That said, when I start dezoomify.py, it looks like it's opened but I can't see it running anywhere, although Python 3.4 is installed. Maybe there's a more simple script out there. Brandmeistertalk 11:59, 1 May 2016 (UTC)
- I uploaded it. Instead of "python" try "py". It's a launcher that will find the right python executable (probably). -- BenRG (talk) 23:08, 1 May 2016 (UTC)
- @BenRG: Yep, feel free to overwrite. For some reason I still can't run dezoomify.py properly on Win 7. After launching Dezoomify.py and opening the command line, I copy-paste, for instance, python dezoomify.py -i http://www.bl.uk/onlinegallery/onlineex/evancoll/a/zoomify72459.html -q 90 -o c:\output.jpg to the command line, but after pressing "enter" get "the name python is unrecognizable". Same is happening with other URLs. That said, when I start dezoomify.py, it looks like it's opened but I can't see it running anywhere, although Python 3.4 is installed. Maybe there's a more simple script out there. Brandmeistertalk 11:59, 1 May 2016 (UTC)
- Your error message means the shell can't find Python. Did you put the Python installation directory in your PATH? See the official Python help. (If you have a different Python version, you can get to its help files from the top navigation bar.) --71.110.8.102 (talk) 02:45, 2 May 2016 (UTC)
- As of whenever PEP 397 was adopted, the Python installation directory doesn't need to be in your PATH; py.exe can find it in the registry (and py.exe is in \Windows, which is always in the path). That help page is years out of date, despite being from the latest 2.x release. The 3.x page is more current. -- BenRG (talk) 08:16, 2 May 2016 (UTC)
- Ok, I've now reconfigured. At scrolls.uchicago.edu zoomify object syntax failed, it seems, so I tried base URL per commons:Help:Zoomable_images/dezoomify.py#Examples. When trying for instance http://scrolls.uchicago.edu/scroll/night-revels-han-xizai I get this in the command line:
- ERROR: Could not open ImageProperties.xml <HTTP Error 404: Not Found>. URL: http://scrolls.uchicago.edu/scroll/night-revels-han-xizai/ImageProperties.xml.
- Any ideas? Is Dezoomify ever workable with http://scrolls.uchicago.edu? Brandmeistertalk 08:24, 2 May 2016 (UTC)
- Ok, I've now reconfigured. At scrolls.uchicago.edu zoomify object syntax failed, it seems, so I tried base URL per commons:Help:Zoomable_images/dezoomify.py#Examples. When trying for instance http://scrolls.uchicago.edu/scroll/night-revels-han-xizai I get this in the command line:
- As of whenever PEP 397 was adopted, the Python installation directory doesn't need to be in your PATH; py.exe can find it in the registry (and py.exe is in \Windows, which is always in the path). That help page is years out of date, despite being from the latest 2.x release. The 3.x page is more current. -- BenRG (talk) 08:16, 2 May 2016 (UTC)
- Your error message means the shell can't find Python. Did you put the Python installation directory in your PATH? See the official Python help. (If you have a different Python version, you can get to its help files from the top navigation bar.) --71.110.8.102 (talk) 02:45, 2 May 2016 (UTC)
Desktop problem
editWhy does my CPU restarts automatically with the monitor turning black and showing no notification and sometimes with the freezing of the desktop as if it is paused and mouse keyboard or anything doesn't run at that time of freezing? I have Intel's 2.67 GHz processor with 2 GB RAM and 500 GB harddisk. — Preceding unsigned comment added by Sahil shrestha (talk • contribs) 05:00, 30 April 2016 (UTC)
- This problem is not described specific enough and too less precise. If the machine reboots without Your order. Malware or hardware problems can cause this effect. The machines' configuration seems to be 4 years or older. Such hardware may have some problems today, usually caused by mainboard, power supply or graphic card. --Hans Haase (有问题吗) 19:26, 30 April 2016 (UTC)
- Overheating is another potential problem. Smart systems will detect overheating and warn you first, but dumb ones keep going on happily until they freeze up. You can remove the case and point a fan at it to test this theory. If that stops it, then overheating was the problem. If so, you can look for a more elegant solution (perhaps clean or upgrade the main or CPU fan or improve the attachment to the heat sink). If the problem happens more often when the room is hot, that's another sign of overheating. StuRat (talk) 22:13, 30 April 2016 (UTC)
- A loose power cord is another possibility, but there I would always expect a black screen or a "no signal" message. StuRat (talk) 22:15, 30 April 2016 (UTC)
- Yes, there I can see a "no signal" as you said and my CPU gets overheated very soon as well. Is there any method to reduce CPU's overheating. sahil shrestha (talk) 02:08, 1 May 2016 (UTC)
- As I said, the quick fix is to open up the case and point a big fan at the innards and turn it on full. I also described some long term fixes you might try above. And if you have a way to keep the room cool, that will help, too. StuRat (talk) 04:04, 1 May 2016 (UTC)
- The above procedures should not be attempted unless you know what you are doing. The inside of a computer is sensitive to static electricity and hence one must ground themselves (e.g. by touching the bare metal of the case itself for a few minutes) regularly while looking at it. With that said, however, cleaning can only help for overheating problems. @Sahil shrestha: In the worst case, the CPU is permanently damaged from overheating and needs replacement, but I am not sure that the problem is your CPU in particular. Make sure that your RAM is also in working order and that all cooling devices (i.e. fans) are functioning properly.--Jasper Deng (talk) 06:27, 1 May 2016 (UTC)
- As I said, the quick fix is to open up the case and point a big fan at the innards and turn it on full. I also described some long term fixes you might try above. And if you have a way to keep the room cool, that will help, too. StuRat (talk) 04:04, 1 May 2016 (UTC)
- I think you meant "seconds", not "minutes". All you have to do is touch metal on the case briefly to equalize your voltage with the case's. I've been tinkering with computers for decades and have never had anything damaged by static. --71.110.8.102 (talk) 02:36, 2 May 2016 (UTC)
- Thanks. I was never sure exactly how long I needed to do it, so I always did at least one minute to be safe.--Jasper Deng (talk) 07:29, 2 May 2016 (UTC)
- Couple of milliseconds should be fine. The Quixotic Potato (talk) 02:04, 5 May 2016 (UTC)
- Thanks. I was never sure exactly how long I needed to do it, so I always did at least one minute to be safe.--Jasper Deng (talk) 07:29, 2 May 2016 (UTC)
- I think you meant "seconds", not "minutes". All you have to do is touch metal on the case briefly to equalize your voltage with the case's. I've been tinkering with computers for decades and have never had anything damaged by static. --71.110.8.102 (talk) 02:36, 2 May 2016 (UTC)
- Sahil shrestha, I suggest You to upload a picture of your computer with open computer case. What motherboard type is it? --Hans Haase (有问题吗) 22:00, 5 May 2016 (UTC)