bory has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mysql database
by rnahi (Curate) on Dec 12, 2003 at 14:42 UTC | |
You are making the same mistakes that you made in a previous node (selecting from a mysqldatabase). For starting, your SQL is not valid. Moreover, you are making a Cartesian product with your query. It means that if your tables ddts and deliver have 1000 records each, the query will return 1 million records. There are other problems as well. It seems to me that you are doing a lot of cargo cult programming. Read again the answers to your previous post and then ask again what you need. | [reply] |
by eric256 (Parson) on Dec 12, 2003 at 16:22 UTC | |
I don't think your numbers are quite right on the query. He is checking AND delivery.Data=ddts.Data which will limit the data to just records that are 'linked' between the tables by there data field. Of course i don't know how valid that link is, but unless every record in both tables has the same data feild he should be okay. (Ignoring of course the comparison of `User`=\"@user\", i have no idea what thats suppose to do. ___________ Eric Hodges | [reply] [d/l] [select] |
|
Re: mysql database
by jdtoronto (Prior) on Dec 12, 2003 at 15:17 UTC | |
You are making a number of crucial mistakes. Firstly you are directly placing variables into your prepare string. Use placeholders instead then the DBI/DBD will take care of escaping for you. You haven't fully worked out the SQL you need and until you do it is likely you will have some pretty awful problems! First step is to check the tutorials on this site. You are making errors and using a coding style which is well discussed in several tutorials. Either go to www.mysql.com and carefully read the documentation there or go out and buy a good MySQL or SQL book. You also have a similar quoting problem in building the checkboxes. I would suggest using CGI.pm to create them, which will, again, removing the quoting difficulties. And remember - ONE WORD for me please - PLACEHOLDERS | [reply] |
|
Re: mysql database
by Abigail-II (Bishop) on Dec 12, 2003 at 14:37 UTC | |
Also, you aren't checking whether your prepare succeeds; you aren't checking whether your execute succeeds, and you aren't using placeholders. Abigail | [reply] |
|
Re: mysql database
by Sandy (Curate) on Dec 12, 2003 at 16:40 UTC | |
About the actual algorithm...
If i understand your problem correctly, you want to
If this is what you want to do, then... It this is not what you want to do, just forget I mentioned it. PS: If @id is huge, then another algorithm may be more appropriate, which minimizes all the queries to the database.
My $.02 worth: When I was first learning to program, my mentor insisted that I write my algorithm 1st, and then step through it with 'dummy data' while pretending to be the computer (do what I say, not what I mean). This method works well when you are still at the learning phase of programming. | [reply] [d/l] |
by bory (Beadle) on Dec 15, 2003 at 09:22 UTC | |
Thank you very much | [reply] [d/l] |
by Sandy (Curate) on Dec 18, 2003 at 16:59 UTC | |
I will be willing to help you solve this if you want (later this week, not now), but I would need to know a bit more info. Could you give me a sample of the input from the db (not the whole thing please), explain why you are querying based on 'user'=\"@user\", print out the select statement before querying, and print the results (as is) of each row fetched from the database. It's possible that just doing this may help you solve the problem yourself. UPDATE ... ignore above Silly me, over lunch I realized what was wrong (at least I think that this is the problem). When you query the database, you use a while loop. When a row is returned, you print the resulting CHECKED box. So far so good. But, still within the while loop, a new query is performed, and there is no row returned. Now the $identifier is 'undef', and the while loop is exited. So what happens next? The if statement is executed, and $identifier (which is 'undef' because of the last query to the db) is not equal to $id. The condition is true, and the unchecked box is printed.
There are certainly a lot better ways of doing this than what I am about to suggest, (it's a quick and dirty fix) but it should work.
PS: Note that I used a placeholder, which many people have mentioned in the other posts.
| [reply] [d/l] |
|
Re: mysql database
by injunjoel (Priest) on Dec 12, 2003 at 17:35 UTC | |
Aside from needing to fix up your query methodology (adopting the use of placeholders "?" would be a good start) you have no else for your if condition. Since there is no else that might be the reason "It's printing all the elements of @id as checked". try something like this HTH -injunjoel | [reply] [d/l] |