Help! I want selecting field field_country_value from table content_type_profile and display him in my profile .Can you edit my module ?Sorry for my bad english.I speak to russian

<?
function select_user($op) {

if ($op == 'view' )
{
$sql = "SELECT field_country_value from content_type_profile";
$result = db_query(db_rewrite_sql($sql));
while ($data = db_fetch_object($result))
{
$country =($data->field_country_value);

$user->content['summary'] = array
(
'#type' => 'user_profile_item',
'#title' => t('Countries'),
'#value' => t($country)
);
}
}
}

?>

Comments

Anonymous’s picture

Sorry, I can't figure out what the context is here. What modules are you using -- is this content_profile? Also, just to confirm, this is drupal 6 your asking about?

A couple of comments about your code.

$sql = "SELECT field_country_value from content_type_profile";

should be:

$sql = "SELECT field_country_value FROM {content_type_profile}";

table names should be always encased in {} and keywords in ALL UPPER CASE.

while ($data = db_fetch_object($result)){
  $country =($data->field_country_value);
  $user->content['summary'] = array(
    '#type' => 'user_profile_item',
    '#title' => t('Countries'),
    '#value' => t($country)
  );
}

this really doesn't make sense to me. You've done a query that is likely to return many rows, and then you're using the fetched rows to set values in user->content over and over again. This makes no sense to me. I'm guessing you want to parameterize your query to search on a uid, but given just this code sample it is not clear. Can you provide more context or other information to help us better understand your question?

Thanks!

Netstat’s picture

dougstum I want take out various data from table content_profile
and represent their in my profile http://localhost/drupal/user/1 .
I need any example how can i insert sql query select in module .
Yes i use content profile.

jaypan’s picture

You need to use hook_user(), which it appears you are, assuming your module is named 'select'. But you need to add more parameters when you call it. Your function definition should look like this:

function select_user($op, &$edit, &$account, $category = NULL) {

Then you can use the value of 'load' for $op to execute your query and load the data into the $account object:

if($op == 'load')
{
  // run mysql queries, and add the data you want to the $account object
}

And then you can display the loaded data in when $op is equal to 'view', by adding data to the $account->content array:

if($op == 'view')
{
  $account->content['loaded_data'] = $account->data_from_database;
}

Good luck. You should probably spend some time reading over the hook_user() documentation. It's quite convoluted, but very powerful.

Contact me to contract me for D7 -> D10/11 migrations.

Netstat’s picture

Jay Matwichuk Pls check syntax

<?
function select_user($op, &$edit, &$account, $category = NULL)
{
if ($op=='load')
{

$sql = "SELECT field_country_value 
 from {content_type_profile}";
		$result = db_query(db_rewrite_sql($sql));
		while ($data = db_fetch_object($result))
		{
$name =($data->country);
}


if($op == 'view')
{
$account->content['summary']['country'] = array
(
'#type' => 'user_profile_item',
'#title' => t('names'),
'#value' => t($country));
}
}
}
?>
jaypan’s picture

Can you please wrap your code in <code> tags?

Contact me to contract me for D7 -> D10/11 migrations.

Netstat’s picture

Ok