The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
db where var1=x AND var2=y AND var3=q - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.4 (https://userspice.com/forums/forumdisplay.php?fid=27)
+--- Thread: db where var1=x AND var2=y AND var3=q (/showthread.php?tid=1293)



db where var1=x AND var2=y AND var3=q - Ruud - 01-05-2019

I can't figure out how to solve a right query, what do I wrong?

sql query: 
DELETE FROM `tbl_resource` WHERE (`ID_resource`=".$var1."  AND `ID_veld`=".$var2." AND `type_resource`='P') LIMIT 1;

first try:
$db->delete("tbl_resource",
[ "AND", 
["ID_resource","=",$db->result()[0]->ID_papo], 
["ID_veld", "=", $lesblokId ],
["type_resource", "=", "P"]
]);

second try:
$db->delete("tbl_resource",
[ "AND", 
[ "AND",[
["ID_resource","=",$db->result()[0]->ID_papo], 
["ID_veld", "=", $lesblokId ]
], 
["type_resource", "=", "P"]
]
]);


RE: db where var1=x AND var2=y AND var3=q - Ruud - 01-05-2019

fallback scenario below used, but please let me know what's the best way to work ;-)

$db->query("DELETE FROM `tbl_resource` WHERE (`ID_resource`= ? AND `ID_veld`= ? AND `type_resource`='P') LIMIT 1;",[$papoId, $lesblokId]);


RE: db where var1=x AND var2=y AND var3=q - mudmin - 01-06-2019

What happens if you do
$db->query("DELETE FROM tbl_resource WHERE ID_resource = ? AND ID_veld= ? AND type_resource=? LIMIT 1",[$papoId, $lesblokId,'P']);


RE: db where var1=x AND var2=y AND var3=q - mudmin - 01-06-2019

And btw, table name is really tbl_resource not resource and the columns are ID_veld not veld right?


RE: db where var1=x AND var2=y AND var3=q - Ruud - 01-06-2019

(01-06-2019, 01:19 AM)mudmin Wrote: And btw, table name is really tbl_resource not resource and the columns are ID_veld not veld right?

the normal query works (my second post-entry), but was wondering why it should not work like my try in a first manner.

but I understand it only works for two variables or isn't it so?


RE: db where var1=x AND var2=y AND var3=q - mudmin - 01-07-2019

Hi. Sorry. Pretty much all the devs have been away this weekend. Sorry for the slow response.

As far as the first vs second, I'll take another look. the way I wrote the query is shorter. In general if you can avoid the paranthesis and ` vs ' there are fewer chances for a mistake.

Ready for something that will change your life and I went 2 years without knowing? ...
After your query that doesn't work, you can just type
dump($db->errorInfo()); and you will get PDO's best guess as to what's wrong with your query. If you get some array with just 012, that means it worked as far as PDO/MySQL is concerned.

You can bind as many variables as you want with the ? thing if that's what you're talking about. And you really don't have to bind that P, like I moved from the query to the bound parameters, but I always do it in case I want to sub it out with a variable later.

I think the $db->delete only works with one parameter. I usually only use that with an ID. I like to write out my delete queries, personally.