n00dles / DM_Matrix

The Matrix is an XML file based Database system for GetSimple 3.1
8 stars 7 forks source link

having trouble with 'WHERE' in SQL #42

Closed outflux3 closed 12 years ago

outflux3 commented 12 years ago

I can't seem to get a WHERE clause to work...trying to filter some table results; any suggestions?

$actors=getSchemaTable('artists',"SELECT id,artist_name,bio_teaser,bio_full,artist_link,artist_image,artist_type,slug FROM returnArray WHERE artist_type='actor' ORDER BY artist_name ASC LIMIT 14");

cheers!

n00dles commented 12 years ago

the queries are a bit particular with spaces. make sure you have a space eitehr side of the '=' when doing a WHERE

outflux3 commented 12 years ago

i haven't been able to get the where to work, even with the space outside of the = sign; for now i'm using an array filter to get this done...but would be interested to know what's causing my WHERE to not work, could it be something to do with the field name?

n00dles commented 12 years ago

Shawn wrote a new function for doing queries.. try it first without the limit and order by just to make sure it is the WHERE thats causing it...

$myquery = "SELECT id,artist_name,bio_teaser,bio_full,artist_link,artist_image,artist_type,slug FROM artists WHERE artist_type = 'actor' ORDER BY artist_name ASC LIMIT 14";  
$result=DM_query($myquery,DM_MULTI);
echo '<pre>'.print_r($result,true).'</pre>';
n00dles commented 12 years ago

ok, just confirmed it is the "_" in the field name thats causing the problem.

outflux3 commented 12 years ago

ok, for now my array filter is working, so i'll leave that as is, but for some other sites/projects, i should wait until the _ doesn't mess things up, or just switch to camel case for the field names.

n00dles commented 12 years ago

not too hot on regex so might see if the expert (shawn) can take a look at it.

Looks like its treating the underscore as a special character which it should be doing in a WHERE / LIKE

Either that or we limit the field name to alphanumeric only.

outflux3 commented 12 years ago

on the other site i'm working on, i think i'm going to take out all of the underscores from the field names and see how it goes...

n00dles commented 12 years ago

works fine everywhere except for when doing a WHERE on a field name with underscores...

Have some nice new updates coming in the next day or 2, off work for a couple of weeks so I'll have plenty of time to concentrate on this and shortcodes and get them on to extend.

tablatronix commented 12 years ago

I have an issue open on this, ill take a look at it today, sorry been working on my own plugins and lots of core updates for getsimple lately.

outflux3 commented 12 years ago

great - matrix is really working well; i think that a case study might be most helpful for people who want to try it out; i could use 1 or 2 of the sites i just completed with it, and present all of the code, within the functions and then the template used to output the records as pages; here's an example: andylaster.com/discography/ one thing i did yesterday was to add a link on the gs pages view directly to the table, like this:

load.php?id=DM_Matrix&action=matrix_manager&view=discography

maybe it would be cool to have a feature within matrix to add a link like this to the pages sidebar, so that clients can avoid going to Matrix then to the table.. maybe a preference within the table options...

n00dles commented 12 years ago

thanks guys, really appreciate the help and time you have put into testing etc...

@tablatronix, no rush on it, nice work on GS the last few days BTW.

@outflux3 , site looks great. WIll add that to the improvements for this week. I had it there originally and removed it.

outflux3 commented 12 years ago

@n00dles thanks - that will be great; i'll post the other site i'm doing with matrix once it's out of the 'dev' subdomain next week... it's been a real lifesaver on these projects...

n00dles commented 12 years ago

Think this is sorted now.