Jump to content

Running a query


acsonline

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/230102-running-a-query/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/230102-running-a-query/#findComment-1185036
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/230102-running-a-query/#findComment-1185044
Share on other sites

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....

Link to comment
https://forums.phpfreaks.com/topic/230102-running-a-query/#findComment-1185055
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.