Android Question sql query for php side

tufanv

Expert
Licensed User
Longtime User
Hello,

I am not familiar with php so i need help for this:

in php code that connecting my app to mysql :

Case "Getpersons":
$q = mysql_query("SELECT username, surname FROM users");
in the app:
Dim GetPersons As HttpJob
GetPersons.Initialize("GetPers", Me)
GetPersons.download2("mysite/file.php", Array As String ("action", "GetPersons"))

it works without any problem ( thanks to a user who posted the tutorial i dont remember his name)

i dont know how to edit both app and php code to use with where clause
for example i want to add
SELECT username, surname FROM users where id = txtidbox.text

so what must i add to both app side and php side. I need help about this. 1 little example wil be enough
thank you !
 

mc73

Well-Known Member
Licensed User
Longtime User
YOu should add the new parameter, for e.g.
B4X:
Array As String ("action", "GetPersons","personid","aPersondID")
.
In your php you could use
B4X:
$personID=$_POST['personid'];
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
ty . in php code where do i add the clause WHERE ?
YOu should add the new parameter, for e.g.
B4X:
Array As String ("action", "GetPersons","personid","aPersondID")
.
In your php you could use
B4X:
$personID=$_POST['personid'];
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
To give more than one parameter to php you need something like
B4X:
    job.download2("http://domain.tld:8080/stunden/b4a.php", Array As String( _
        "action", Query, _
        "personID", personID, _
        "filter", filter _
    ))
and in php then
PHP:
if (isset($_REQUEST['action'])){$action=StrToLower(trim($_REQUEST['action']));} else {$action="";}
if (isset($_REQUEST['personID'])){$personID=trim($_REQUEST['personID']);} else {$personID="";}
$q = mysql_query("SELECT username, surname FROM users WHERE userid=".$personID.";");

Assuming personID is an INT-Value you better can use
PHP:
if (isset($_REQUEST['personID'])){$personID=intval(trim($_REQUEST['personID']));} else {$personID=0;}
to prevent that $personID is a string (whatever it´s content is)
IntVal return an int. if the given $_REQUEST['personID'] is for example "test" (or any other that is not an int) intval will return 0
 
Last edited:
Upvote 0

tufanv

Expert
Licensed User
Longtime User
To give more than one parameter to php you need something like
B4X:
    job.download2("http://domain.tld:8080/stunden/b4a.php", Array As String( _
        "action", Query, _
        "personID", personID, _
        "filter", filter _
    ))
and in php then
PHP:
if (isset($_REQUEST['action'])){$action=StrToLower(trim($_REQUEST['action']));} else {$action="";}
if (isset($_REQUEST['personID'])){$personID=trim($_REQUEST['personID']);} else {$personID="";}
$q = mysql_query("SELECT username, surname FROM users WHERE userid=".$personID.";");

Assuming personID is an INT-Value you better can use
PHP:
if (isset($_REQUEST['personID'])){$personID=intval(trim($_REQUEST['personID']));} else {$personID=0;}
to prevent that $personID is a string (whatever it´s content is)
IntVal return an int. if the given $_REQUEST['personID'] is for example "test" (or any other that is not an int) intval will return 0

Thank you !
 
Upvote 0
Top