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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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