How to display input from sql Members database.

Started by Goodman854, July 03, 2016, 01:00:18 PM

Previous topic - Next topic

Goodman854

LONG STORY SHORT. I want to grab data from SMF database smf_members.
I want to get the members current ID and find out what the refered_by number associated to them is.


I'm sorry I did solve my last problem however I guess I didn't fully understand the code so I don't know how to apply it to my next issue.

So sorry if this issue is similar to another.

Anyways, Basically I found with referals mod who reffered you is saved to your ID under the sql members block.
So in the database looks something like:



id_memberrefered_by
0201


as opposed to before which was:



id_membervariablevalue
02cust_xboxtagjoejoe360



So I know this isn't the code. But How do I go about it?
I want the person to know who refered them.
$query = $smcFunc['db_query']('', '
    SELECT value
    FROM {db_prefix}members
    WHERE id_member = {int:member}
      AND variable = {string:referred_by}',
   
Something, something result...

  $row = $smcFunc['db_fetch_assoc']($query);
  $smcFunc['db_free_result']($query);

  echo 'The result is ', $referred_by;

Goodman854

Was looking around a bit more and thought maybe something like this would work.
global $context, $smcFunc;

$result = $smcFunc['db_query']('', '
SELECT referred_by
FROM {db_prefix}members
WHERE id_member = {int:id_member}
LIMIT 1',
array(
'id_member' => $context['id'],
)
);
echo 'You got refered by this id ',$result;


But I get, "The database value you're trying to insert does not exist: id_member" so I'm still lost if anyone knows where I am going wrong that'd be great. The SQL stuff is new to me when used with PHP.

Goodman854

Sorry I would edit my first post but I don't have an edit button any more. I'm not sure what that's about.

This is the final code I came up with.global $context, $smcFunc;

if (empty($context['user']['id']))
  echo 'The current user is a guest';
else
{
  echo 'The current user: id ', $context['user']['id'], ', username ', $context['user']['name'], '<br />';

  $query = $smcFunc['db_query']('', '
    SELECT referred_by
    FROM {db_prefix}members
    WHERE id_member = {int:member}
);

}


Which logically explains what I want but errors out and I'm not 100% sure where it goes wrong.

vbgamer45

Try something like

global $context, $smcFunc;

if (empty($context['user']['id']))
  echo 'The current user is a guest';
else
{
  echo 'The current user: id ', $context['user']['id'], ', username ', $context['user']['name'], '<br />';

  $query = $smcFunc['db_query']('', '
    SELECT referred_by
    FROM {db_prefix}members
    WHERE id_member = {int:member}',
array(
'member' => (int) $context['user']['id'],
)
);

}
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Goodman854

Quote from: vbgamer45 on July 05, 2016, 12:25:26 AM
Try something like

global $context, $smcFunc;

if (empty($context['user']['id']))
  echo 'The current user is a guest';
else
{
  echo 'The current user: id ', $context['user']['id'], ', username ', $context['user']['name'], '<br />';

  $query = $smcFunc['db_query']('', '
    SELECT referred_by
    FROM {db_prefix}members
    WHERE id_member = {int:member}',
array(
'member' => (int) $context['user']['id'],
)
);

}


Thanks I think that kind of works.

This is how i implemented it however.

global $context, $smcFunc;

if (empty($context['user']['id']))
  echo 'The current user is a guest';
else
{
  echo 'The current user: id ', $context['user']['id'], ', username ', $context['user']['name'], '<br />';

  $query = $smcFunc['db_query']('', '
    SELECT referred_by
    FROM {db_prefix}members
    WHERE id_member = {int:member}',
array(
'member' => (int) $context['user']['id'],
)
);

$row = $smcFunc['db_fetch_assoc']($query);
  $smcFunc['db_free_result']($query);
  echo 'The value of who refereed the user is ', $row['referred_by'];
$referredper = $row['referred_by'];

if ($referredper > 0) {
$query = $smcFunc['db_query']('', '
    SELECT value
    FROM {db_prefix}themes
    WHERE id_member = $referredper
      AND variable = {string:variable}',
    array(
      'member' => $context['user']['id'],
      'variable' => 'cust_xboxtag',
    )
  );
$row = $smcFunc['db_fetch_assoc']($query);
  $smcFunc['db_free_result']($query);

  echo 'The value of the custom field is ', $row['value'];
  $referrersbtc = $row['value'];

}

}


Everything works up until "if ($referredper > 0)"
Then I get a database error unless the user was referred by no one and it comes up as zero so that if statement isn't ran. But

What's wrong with my code in that statement?
I'm really sorry and apologize for being still ignorant with this at the moment :/ Sorry.

vbgamer45

mistake
should be

if ($referredper > 0) {
$query = $smcFunc['db_query']('', '
    SELECT value
    FROM {db_prefix}themes
    WHERE id_member = {int:member}
      AND variable = 'cust_xboxtag',
    array(
      'member' => $referredper,
    )
  );
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Goodman854

Quote from: vbgamer45 on July 05, 2016, 12:41:19 PM
mistake
should be

if ($referredper > 0) {
$query = $smcFunc['db_query']('', '
    SELECT value
    FROM {db_prefix}themes
    WHERE id_member = {int:member}
      AND variable = 'cust_xboxtag',
    array(
      'member' => $referredper,
    )
  );


Thank you so much dude. That's exactly what I was looking for.

Advertisement: