acsonline Posted March 9, 2011 Share Posted March 9, 2011 Hey Guys, I have a DB with two tables, one is field names, the other is the data. So for example, I log in and I am user ID 1..... I need to query the DB to show all fields where user_id = 1 Field1 - Data1 Field2 - Data2 etc etc... This is what I have so far, but I dont get any output... $sql = "SELECT * FROM ".WPSC_TABLE_DATA." WHERE `user_id` == .$cu. ORDER BY id DESC"; $user= $wpdb->get_row($sql); while($user) { echo $user->name .' : '. $user->value .'<br />'; } Can you help please? Quote Link to comment Share on other sites More sharing options...
acsonline Posted March 9, 2011 Author Share Posted March 9, 2011 I've been playing and have written this: $sql = "SELECT data.USER_ID, data.VALUE AS value, fields.NAME AS name FROM wordpdem_cimy_uef_data AS data INNER JOIN wordpdem_cimy_uef_fields AS fields ON ( fields.ID = data.ID ) WHERE data.USER_ID = '1' ORDER BY data.ID DESC I echo it and it shows, and then I ran a test on it directly in SQL, which shows no rows found, however there are 5 rows with user_id of 1.... Any clues? Quote Link to comment Share on other sites More sharing options...
Nuv Posted March 9, 2011 Share Posted March 9, 2011 I think this belongs to wordpress ? I am curious though, in $sql = "SELECT * FROM ".WPSC_TABLE_DATA." WHERE `user_id` == .$cu. ORDER BY id DESC"; Is WPSC_TABLE_DATA the table name or variable ? Quote Link to comment Share on other sites More sharing options...
acsonline Posted March 9, 2011 Author Share Posted March 9, 2011 Ah yes it is a wordpress plugin, but as its a php prob I thought I would ask here Its the table name: // Define the database table names define('WPSC_TABLE_DATA', "{$wp_table_prefix}cimy_uef_data"); define('WPSC_TABLE_FIELDS', "{$wp_table_prefix}cimy_uef_fields"); If I run it with the user ID of 4 then it works, however 1 and 5 dont (I only have the 3 users registered... How come I only get the 4th user? Quote Link to comment Share on other sites More sharing options...
acsonline Posted March 9, 2011 Author Share Posted March 9, 2011 My tables are: (FIELDS TABLE) ID NAME LABEL 1 ADDRESS add 2 ADDRESS2 add2 3 TOWN town (DATA TABLE) ID USER_ID FIELD_ID VALUE 1 4 1 Test home address 2 4 3 York 3 1 2 Second Home Address 4 1 3 Fife 5 2 3 Yarmouth So if I search for User ID 1 then I should get 2 results.... Quote Link to comment Share on other sites More sharing options...
acsonline Posted March 10, 2011 Author Share Posted March 10, 2011 Any ideas? Quote Link to comment Share on other sites More sharing options...
acsonline Posted March 11, 2011 Author Share Posted March 11, 2011 Can anyone point me in the right direction? My JOIN doesnt appear to be working.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.