How to return data from the user who logged in?

Asked

Viewed 749 times

-1

I need someone to help me with the following problem. I want to realize a select in a Mysql database, select will be done via web service with PHP returning a Json to my Android app.

What happens, the user enters login and password and the app recognizes the user and opens a second screen, in this second screen has a listview and in that listview should contain all the companies of that user, and it is at this point that this the problem. For me to do this I realize a select in PHP in the database, however, select returns me all companies in the database and not only the user who logged in. I tried to save the company code using SESSION in PHP but it did not work I would like someone to help me, thanks.

Follow the code in PHP:

<?php

SESSION_START();
echo $_SESSION['Cod_Empresa'];
mysql_connect('localhost','','');
mysql_select_db('bd') or die (mysql_error());

$result = mysql_query( "SELECT UC, Instalacao, Nome_Logo FROM Tab_UC where Cod_Empresa ='".$_SESSION['Cod_Empresa']."'") or die('Could not query');
 for($rows = array(); $row = mysql_fetch_object($result); $rows[] = $row);
 {
    echo json_encode($rows);    
 } 



?>

1 answer

0

Well, from what I understand you want to search the companies of a logged-in user.

Looking at your query I saw that has a table Tab_uc, I deduce that it is the table responsible for the registered companies. And in its clause Where Cod_Empresa ='".$_SESSION['Cod_Empresa']."' you are filtering by company code. You should not filter by logged in user ID?

In my view, this code returns only one company.

  • and how it would be to filter by ID... could return me an example... thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.