Timeline for prepare select of array
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 29 at 12:30 | comment | added | Ian Young | Tom J Nowell As far as what is working. the query selects only one row. Normally a 'foreach would work, to separate out the $id strings would do the job but not in this case. | |
| Jan 29 at 8:51 | comment | added | Ian Young | Not in Wordpress - sorry folks but that is only true if you use %d or %s. If you use a straightforward select clause inverted commas are required. | |
| Jan 28 at 18:06 | comment | added | Tom J Nowell♦ | Rup is right, '$id' is not a variable, it's a string. E.g. the program $id = 'test'; echo '$id'; prints $id not test. It must be $id without the quotes. Also how are you testing that it does or doesn't work? Can you fix the indenting/formatting? | |
| Jan 28 at 17:41 | review | Close votes | |||
| Feb 12 at 3:07 | |||||
| Jan 28 at 16:16 | comment | added | Ian Young | I did try that in my original query which wasnt a prepare - that didnt work. Have also used a foreach in and out of loop, nothing happens Also - the query shows nothing if the inverted commas are removed I'm sure its a simple fix. Ive been working on it so long that the wood is being hidden by the trees | |
| Jan 28 at 16:01 | comment | added | Rup | Oh OK - on second glance that looks like it's still inside your loop though? To batch you should be collecting an array of IDs and then do a user_id in [] outside the loop, although unhelpfully it looks like wpdb prepare() doesn't really support that. And actually you also don't want the inverted commas around user_id either in the SQL string: if you want to quote a column name in MySQL that's backticks not inverted commas, but you don't need to here. | |
| Jan 28 at 15:54 | comment | added | Ian Young | A batch - I have done it in other queries. In the Wordpress guide they use inverted commas around the query. if not there the query doesnt work at all | |
| Jan 28 at 15:44 | comment | added | Rup | Are you trying to this as a batch, i.e. all $ids at once, or just one? At first glance your problem is you've got the string '$id' when you just want the value $id. I'm also not sure you need the array() around $id but it shouldn't matter. | |
| S Jan 28 at 15:27 | review | First questions | |||
| Feb 11 at 15:30 | |||||
| S Jan 28 at 15:27 | history | asked | Ian Young | CC BY-SA 4.0 |