PHP - SHOW A SPECIFIC DETAIL FROM THE USER IN SESSION

Hey guys,

I’ve got a problem with my code…
The objective of this code is to show a specific data from the user in session.
But something is wrong…

Can someone help me to complete the code?

[php]$user_id = SearchUser($_SESSION[‘user’][‘id’]);
$ok = true;

	//Check user function "SearchUser"
	if(SearchUser($user_id)) {
		
		$dbh = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password);
		$procurarUser = $dbh->prepare("SELECT ID_Article,ID_Utilizador, Data_Compra, Price, Cred_Depois FROM reg_log ORDER BY Data_Compra WHERE id='$user_id'");
		$procurarUser->execute();		
		$checkUser = $procurarUser->fetchAll();
		  
		  foreach($checkUser as $User)
		  {
		  echo "<table>";
		  echo "<tr>";
		  echo "<td><b>Artigo</b></td>";
		  echo "<td><b>ID</b></td>";
		  echo "<td><b>Preço</b></td>";
		  echo "<td><b>Creditos Anteriores</b></td>";
		  echo "<td><b>Data & Hora</b></td>";
		  echo "</tr>";
		  echo "<br /><tr><td>" . $User['ID_Article'] . "</td><td>". $User['ID_Utilizador'] . "</td><td>" . $User['Price'] . "</td><td>". $User['Cred_Depois'] . "</td><td>" . $User['Data_Compra'] . "</td></tr> " ;
		  echo "</table>";
		  }
		
			$ok = true;
			$dbh = null; //close db
	
	} else {
			echo "You have no purchases.";
			$ok = false;
	}[/php]

Do you get any errors? Is something you expect to happen not happening? What is wrong?

That is the problem… is WOrking good, but dont show the detail about the user in session, the code show all details in the database->table

And i want show only the user

HUH? Just delete the cells you do not what in your table. YOU create a table displaying the data, just remove
the items you do not want there. Remove the headings and the data cells and all should be good…

( If that is what you are asking for ! )

You no understand what i want…

Look this… http://prntscr.com/9n0f9r

I just want the RED LINE

The blue line is what i no want…

And the code is showing ALL content…

EDIT THE CODE, BUT STILL NO GIVING WHAT I WANT…

[php] $id = SearchUser($_SESSION[‘user’][‘id’]);
//$id = $_SESSION[‘user’][‘ID_utilizador’];

if(SearchUser($id) == True)   
    {

    $dbh = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password);           
    $search = $dbh->prepare("SELECT ID_Article, ID_Utilizador, Data_Compra, Price, Cred_Depois FROM reg_log WHERE ID_Utilizador='$id'");           
    $search->execute();         
    $checkUser = $search->fetchAll();

         foreach($checkUser as $u)
          {
          echo "<table>";
          echo "<tr>";
          echo "<th><b>Article ID</b></th>";
          echo "<th><b>User ID</b></th>";			  
          echo "<th><b>Price</b></th>";
          echo "<th><b>Savings</b></th>";
          echo "<th><b>Data & Hora</b></th>";

          echo "</tr>";
          echo "<br /><tr><td>" . $u['ID_Article'] . "</td><td>". $u['ID_Utilizador'] . "</td><td>". $u['Price'] . "</td><td>" . $u['Cred_Depois'] . "</td><td>" . $u['Data_Compra'] . "</td></tr> " ;
          echo "</table>";


    $dbh = null; //close db
    }    

    } else {       
        echo "You have no purchases.";

	}[/php]

You have a table inside of a loop. That means it will create a new table on each run. If you want one row, you don’t need a loop. If you want the headings only once, they should not be included inside the loop.

Ok…still no understand…
What loop are u talking?

So, you didn’t write that if you have no idea what a loop is or what it looks like.

“Foreach” is a loop ok… Yes i write this but i’m confuse amd its 05h00… I’m asking u help… Thats why im here…

This is marked solved. Did you solve it? If so let us know. If not, you just need to remove the loop. Or, you
can limit your query to just one item. Either will work.

Sponsor our Newsletter | Privacy Policy | Terms of Service