in reply to Re^4: CGI Action call
in thread CGI Action call
Yes, as is documented in DBI.
Also, your SQL seems faulty to me as the "previous record" seems to skip users:
create table users ( user_id integer not null primary key, name varcha +r(16) ); insert into users values (1,'Fred'); insert into users values (2,'Barney'); insert into users values (3,'Wilma'); insert into users values (4,'Betty'); insert into users values (5,'Pebbles'); SELECT * FROM users WHERE user_id < (SELECT MAX(user_id) FROM users WHERE user_id < 4) ORDER BY user_id DESC LIMIT 1
This suggests that the "previous" entry for "Betty" (user id 4) is "Barney" (user id 2), and not user id 3 as I would expect.
The same, but inverse holds for the other SQL.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: CGI Action call
by tultalk (Monk) on Mar 27, 2018 at 17:00 UTC | |
I have a form with a navigator control I made. Works fine except when I want to scroll with a different order in place. The 4 SQL statements work fine in PHPAdmin. I issue an "alter table users order by lastname asc and the table is so ordered. Shows as such in browse. I execute the various SQL statements below and the returned records are as expected. next, next, previous, beginning and end. The ORDER remains in place. On the form I search for last name and set the alter table based on the search selected. This all works as intended per my logging. When I try to scroll the records with the navigator it is returning records based on the user_id order. I tried correcting this by reasserting the alter table again with each scroll but to no avail. Don't understand why the process works in PHP MyAdmin but not with my code.
More code
And yet more code
| [reply] [d/l] [select] |
by poj (Abbot) on Mar 27, 2018 at 20:31 UTC | |
Why use sub selects here
instead of the simpler poj | [reply] [d/l] [select] |
by Corion (Patriarch) on Mar 27, 2018 at 17:05 UTC | |
I don't think that this is how SQL works. In fact, I'm surprised that such a statement parses at all and doesn't raise an error. In SQL, tables don't have any kind of order that you can change. SELECT statements have an order clause and if you want to have a specific order, you need to specify that in every SELECT statement. | [reply] [d/l] |
by tultalk (Monk) on Mar 27, 2018 at 18:06 UTC | |
The alter table MyTable order by MyField works in PHP Admin and is in the MySQL docs as well as testing and explanation in Work Log Wl#3681 Report BUG#24562 MySQL Docs: ALTER TABLE tbl_name [alter_specification ORDER BY col_name , col_name ... My question remains: Why it works in PHP MyAdmin and not in my program????? Best regards | [reply] |
by Corion (Patriarch) on Mar 27, 2018 at 18:30 UTC | |
by tultalk (Monk) on Mar 28, 2018 at 00:10 UTC | |
| |
by tultalk (Monk) on Mar 27, 2018 at 21:13 UTC | |
| |
|
Re^6: CGI Action call
by tultalk (Monk) on Mar 12, 2018 at 22:08 UTC | |
That may be. I threw it together and locked it to return related to fixed row number for testing other parts. Another to-do | [reply] |
|
Re^6: CGI Action call
by tultalk (Monk) on Mar 15, 2018 at 12:05 UTC | |
Need some insight. Have been staring at this since last night. Placeholder issue
placeholder substitution
This works fine with hard coded vaues instead of placeholders and also testing MySQL directly. count = 1 When running with the placeholders, count = 0 Result with hard code JSON output below
| [reply] [d/l] [select] |
by Corion (Patriarch) on Mar 15, 2018 at 12:22 UTC | |
What is the value of $searchfield? You don't show it to us so we have to guess. This makes it much harder to provide you concise help. Please adjust your debugging process and tell us what you see/output instead of making us guess. My guess is that $searchfield contains the string id or some other string that you want to be interpreted as column name. Did you read the section about placeholders in DBI? Most likely, you skipped over the part where it tells you where placeholders can be used: Placeholders, also called parameter markers, are used to indicate values in a database statement that will be supplied later, ... Naturally, you can't supply the name of a column as a placeholder because the database can't validate your statement before seeing the column name. What happens instead is that your database treats all placeholders as values and never compares the columns but just values of the placeholders. | [reply] [d/l] [select] |
by tultalk (Monk) on Mar 20, 2018 at 00:24 UTC | |
My guess is that $searchfield contains the string id or some other string that you want to be interpreted as column name. You are correct, however: Regarding placeholdrs: You stated and the perl docs state that placeholders cannot be used for elements of the SQL statement such as field names. The code below demonstates use of a placeholder for a field name (lastname) and this works. I am asking because I have a much more complicated statement with 6 placeholders (4 field names and 2 values) which fails.It works fine with hard coded field names. I am trying to use one statement for 3 different queries each using different sets of fields/values I am trying to understand why the one below works
warn log
| [reply] [d/l] [select] |
by poj (Abbot) on Mar 20, 2018 at 09:31 UTC | |
by Corion (Patriarch) on Mar 20, 2018 at 08:07 UTC | |
by tultalk (Monk) on Mar 20, 2018 at 09:30 UTC | |
| |