Function to get profile ID of "person"'s profile currently being viewed

i'm working on my next thang which involves adding fields to the database and then viewing those fields on each persons profile. Is there a built in function to get the id or profile id of the member whose profile i'm currently viewing. there are a couple functions to get currently logged in ID, but i can't find one to get the "persons" id that im currently looking at. I tried grabbing it from the url but that doesn't work correctly with php for some reason. There may be another way to do this, any help would be appreciated. I'm currently using $.post to get fields from database using a php script, but i can only get currently logged in ID. I need the ID of whatever profile is being viewed. php script below.

 

<?php
$servername = "localhost";
$username = "my user";
$password = "my pass";
$dbname = "my database name";

$conn = new mysqli($servername, $username, $password, $dbname);

function damnslashes($string)
{
$string=implode("/",explode("\/",$string));
return stripslashes(trim($string));
}
function damncomma($string)
{
$string=implode("},",explode("}",$string));
return stripslashes(trim($string));
}

require_once('inc/header.inc.php');

$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // trying to just get it from url :/
$urlArray = explode('=',$url);
$last = $urlArray[sizeof($urlArray)-1]; //  <-- doesn't work
$id = getLoggedId();  < --- Function that gets logged in id, but that's no good :(


$return_arr = array();
$sql = "SELECT * FROM sys_accounts WHERE id = $id";
$result = $conn->query($sql);
header('Access-Control-Allow-Origin: *');
$row_array = array();
while($row = $result->fetch_assoc()) {
  $row_array['FirstName'] = $row['FirstName'];
  $row_array['MiddleName'] = $row['MiddleName'];
  $row_array['LastName'] = $row['LastName'];
  $row_array['Initiation_Date'] = damnslashes($row['Initiation_Date']);
  print_r(json_encode($row));
}


then using jquery to disp correct fields...

 


?>

  • 1235
  • More
Replies (3)
    • so I ended up using jquery to get the id from the url, using file_put_contents() to write to a json file and then $.getJSON() to get the info and writing to correct divs. holy hannah! there HAS to be a better way!

      • On a side note, there will DEF be issues when too many people are on at the same time. I will have to use a better method eventually

        • Usually fields for a person can be added/changed/removed via Account > Studio > Fields > Select module: Persons > Select display: View person. 

          However ID is used for inner reference and can't be added via Fields builder.

          Login or Join to comment.