PHP improve data retrieving












0














I am retrieving 5000 plus data in my MYSQL database. I takes 5-10 minutes to retrieve the data (it is only just local slower when over the network) is there a way to improve the speed without using a plugin?



$ContactID = $_GET["Contact"];

$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar = array(
'ContactID' => $row['ContactID'],
'FileAs' => $row['FileAs'],
'FirstName' => $row['FirstName'],
'MiddleName' => $row['MiddleName'],
'LastName' => $row['LastName'],
'Position' => $row['Position'],
'Company' => $row['Company'],
'CompanyID' => $row['CompanyID'],
'ContactType' => $row['ContactType'],
'RetailerType' => $row['RetailerType'],
'PresStreet' => $row['PresStreet'],
'PresBarangay' => $row['PresBarangay'],
'PresDistrict' => $row['PresDistrict'],
'PresTown' => $row['PresTown'],
'PresProvince' => $row['PresProvince'],
'PresCountry' => $row['PresCountry'],
'Landmark' => $row['Landmark'],
'Telephone1' => $row['Telephone1'],
'Telephone2' => $row['Telephone2'],
'Mobile' => $row['Mobile'],
'Email' => $row['Email'],
'Employee' => $row['Employee'],
'Customer' => $row['Customer'],
'Coordinator' => $row['Coordinator'],
'ServerUpdate' => $supdate,
'MobileUpdate' => $mupdate
);
}

print json_encode($ar);
}









share|improve this question






















  • @BehzadDadashpour I am not display the data I am passing the data to my app
    – Lawrence Agulto
    Nov 14 '18 at 6:30






  • 1




    Be very careful with how you use variables in your queries. It's possible to perform SQL injection through the ContactID parameter. Use prepared statements.
    – Tordek
    Nov 14 '18 at 6:32










  • @Tordek yes I am going to do it I need to improve the speed of retrieving data
    – Lawrence Agulto
    Nov 14 '18 at 6:34










  • mySql DATE_FORMAT for date converting maybe help
    – Behzad Dadashpour
    Nov 14 '18 at 6:36








  • 1




    I saw in a comment for one of the answers that this is retrieving a large data set. First you need to identify what process it is that 's slow. Is it the SQL query? (Is the Coordinator column properly indexed?) Is it your while loop? Is it the json_encode()? Is it outputting the result with print_r()?
    – Magnus Eriksson
    Nov 14 '18 at 6:49


















0














I am retrieving 5000 plus data in my MYSQL database. I takes 5-10 minutes to retrieve the data (it is only just local slower when over the network) is there a way to improve the speed without using a plugin?



$ContactID = $_GET["Contact"];

$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar = array(
'ContactID' => $row['ContactID'],
'FileAs' => $row['FileAs'],
'FirstName' => $row['FirstName'],
'MiddleName' => $row['MiddleName'],
'LastName' => $row['LastName'],
'Position' => $row['Position'],
'Company' => $row['Company'],
'CompanyID' => $row['CompanyID'],
'ContactType' => $row['ContactType'],
'RetailerType' => $row['RetailerType'],
'PresStreet' => $row['PresStreet'],
'PresBarangay' => $row['PresBarangay'],
'PresDistrict' => $row['PresDistrict'],
'PresTown' => $row['PresTown'],
'PresProvince' => $row['PresProvince'],
'PresCountry' => $row['PresCountry'],
'Landmark' => $row['Landmark'],
'Telephone1' => $row['Telephone1'],
'Telephone2' => $row['Telephone2'],
'Mobile' => $row['Mobile'],
'Email' => $row['Email'],
'Employee' => $row['Employee'],
'Customer' => $row['Customer'],
'Coordinator' => $row['Coordinator'],
'ServerUpdate' => $supdate,
'MobileUpdate' => $mupdate
);
}

print json_encode($ar);
}









share|improve this question






















  • @BehzadDadashpour I am not display the data I am passing the data to my app
    – Lawrence Agulto
    Nov 14 '18 at 6:30






  • 1




    Be very careful with how you use variables in your queries. It's possible to perform SQL injection through the ContactID parameter. Use prepared statements.
    – Tordek
    Nov 14 '18 at 6:32










  • @Tordek yes I am going to do it I need to improve the speed of retrieving data
    – Lawrence Agulto
    Nov 14 '18 at 6:34










  • mySql DATE_FORMAT for date converting maybe help
    – Behzad Dadashpour
    Nov 14 '18 at 6:36








  • 1




    I saw in a comment for one of the answers that this is retrieving a large data set. First you need to identify what process it is that 's slow. Is it the SQL query? (Is the Coordinator column properly indexed?) Is it your while loop? Is it the json_encode()? Is it outputting the result with print_r()?
    – Magnus Eriksson
    Nov 14 '18 at 6:49
















0












0








0







I am retrieving 5000 plus data in my MYSQL database. I takes 5-10 minutes to retrieve the data (it is only just local slower when over the network) is there a way to improve the speed without using a plugin?



$ContactID = $_GET["Contact"];

$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar = array(
'ContactID' => $row['ContactID'],
'FileAs' => $row['FileAs'],
'FirstName' => $row['FirstName'],
'MiddleName' => $row['MiddleName'],
'LastName' => $row['LastName'],
'Position' => $row['Position'],
'Company' => $row['Company'],
'CompanyID' => $row['CompanyID'],
'ContactType' => $row['ContactType'],
'RetailerType' => $row['RetailerType'],
'PresStreet' => $row['PresStreet'],
'PresBarangay' => $row['PresBarangay'],
'PresDistrict' => $row['PresDistrict'],
'PresTown' => $row['PresTown'],
'PresProvince' => $row['PresProvince'],
'PresCountry' => $row['PresCountry'],
'Landmark' => $row['Landmark'],
'Telephone1' => $row['Telephone1'],
'Telephone2' => $row['Telephone2'],
'Mobile' => $row['Mobile'],
'Email' => $row['Email'],
'Employee' => $row['Employee'],
'Customer' => $row['Customer'],
'Coordinator' => $row['Coordinator'],
'ServerUpdate' => $supdate,
'MobileUpdate' => $mupdate
);
}

print json_encode($ar);
}









share|improve this question













I am retrieving 5000 plus data in my MYSQL database. I takes 5-10 minutes to retrieve the data (it is only just local slower when over the network) is there a way to improve the speed without using a plugin?



$ContactID = $_GET["Contact"];

$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar = array(
'ContactID' => $row['ContactID'],
'FileAs' => $row['FileAs'],
'FirstName' => $row['FirstName'],
'MiddleName' => $row['MiddleName'],
'LastName' => $row['LastName'],
'Position' => $row['Position'],
'Company' => $row['Company'],
'CompanyID' => $row['CompanyID'],
'ContactType' => $row['ContactType'],
'RetailerType' => $row['RetailerType'],
'PresStreet' => $row['PresStreet'],
'PresBarangay' => $row['PresBarangay'],
'PresDistrict' => $row['PresDistrict'],
'PresTown' => $row['PresTown'],
'PresProvince' => $row['PresProvince'],
'PresCountry' => $row['PresCountry'],
'Landmark' => $row['Landmark'],
'Telephone1' => $row['Telephone1'],
'Telephone2' => $row['Telephone2'],
'Mobile' => $row['Mobile'],
'Email' => $row['Email'],
'Employee' => $row['Employee'],
'Customer' => $row['Customer'],
'Coordinator' => $row['Coordinator'],
'ServerUpdate' => $supdate,
'MobileUpdate' => $mupdate
);
}

print json_encode($ar);
}






php mysql mysqli






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 6:24









Lawrence Agulto

777




777












  • @BehzadDadashpour I am not display the data I am passing the data to my app
    – Lawrence Agulto
    Nov 14 '18 at 6:30






  • 1




    Be very careful with how you use variables in your queries. It's possible to perform SQL injection through the ContactID parameter. Use prepared statements.
    – Tordek
    Nov 14 '18 at 6:32










  • @Tordek yes I am going to do it I need to improve the speed of retrieving data
    – Lawrence Agulto
    Nov 14 '18 at 6:34










  • mySql DATE_FORMAT for date converting maybe help
    – Behzad Dadashpour
    Nov 14 '18 at 6:36








  • 1




    I saw in a comment for one of the answers that this is retrieving a large data set. First you need to identify what process it is that 's slow. Is it the SQL query? (Is the Coordinator column properly indexed?) Is it your while loop? Is it the json_encode()? Is it outputting the result with print_r()?
    – Magnus Eriksson
    Nov 14 '18 at 6:49




















  • @BehzadDadashpour I am not display the data I am passing the data to my app
    – Lawrence Agulto
    Nov 14 '18 at 6:30






  • 1




    Be very careful with how you use variables in your queries. It's possible to perform SQL injection through the ContactID parameter. Use prepared statements.
    – Tordek
    Nov 14 '18 at 6:32










  • @Tordek yes I am going to do it I need to improve the speed of retrieving data
    – Lawrence Agulto
    Nov 14 '18 at 6:34










  • mySql DATE_FORMAT for date converting maybe help
    – Behzad Dadashpour
    Nov 14 '18 at 6:36








  • 1




    I saw in a comment for one of the answers that this is retrieving a large data set. First you need to identify what process it is that 's slow. Is it the SQL query? (Is the Coordinator column properly indexed?) Is it your while loop? Is it the json_encode()? Is it outputting the result with print_r()?
    – Magnus Eriksson
    Nov 14 '18 at 6:49


















@BehzadDadashpour I am not display the data I am passing the data to my app
– Lawrence Agulto
Nov 14 '18 at 6:30




@BehzadDadashpour I am not display the data I am passing the data to my app
– Lawrence Agulto
Nov 14 '18 at 6:30




1




1




Be very careful with how you use variables in your queries. It's possible to perform SQL injection through the ContactID parameter. Use prepared statements.
– Tordek
Nov 14 '18 at 6:32




Be very careful with how you use variables in your queries. It's possible to perform SQL injection through the ContactID parameter. Use prepared statements.
– Tordek
Nov 14 '18 at 6:32












@Tordek yes I am going to do it I need to improve the speed of retrieving data
– Lawrence Agulto
Nov 14 '18 at 6:34




@Tordek yes I am going to do it I need to improve the speed of retrieving data
– Lawrence Agulto
Nov 14 '18 at 6:34












mySql DATE_FORMAT for date converting maybe help
– Behzad Dadashpour
Nov 14 '18 at 6:36






mySql DATE_FORMAT for date converting maybe help
– Behzad Dadashpour
Nov 14 '18 at 6:36






1




1




I saw in a comment for one of the answers that this is retrieving a large data set. First you need to identify what process it is that 's slow. Is it the SQL query? (Is the Coordinator column properly indexed?) Is it your while loop? Is it the json_encode()? Is it outputting the result with print_r()?
– Magnus Eriksson
Nov 14 '18 at 6:49






I saw in a comment for one of the answers that this is retrieving a large data set. First you need to identify what process it is that 's slow. Is it the SQL query? (Is the Coordinator column properly indexed?) Is it your while loop? Is it the json_encode()? Is it outputting the result with print_r()?
– Magnus Eriksson
Nov 14 '18 at 6:49














2 Answers
2






active

oldest

votes


















4














$ContactID = $_GET["Contact"];
$ar = array();
$sql = "SELECT ContactID,FileAs, FirstName ,MiddleName ,LastName ,Position ,Company ,CompanyID ,ContactType ,RetailerType ,PresStreet
,PresBarangay ,PresDistrict ,PresTown , PresProvince ,PresCountry ,Landmark ,Telephone1 , Telephone2 ,Mobile
,Email ,Employee ,Customer ,Coordinator FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
$rowCount = 0;
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar[$rowCount] = $row;
$ar[$rowCount]['ServerUpdate'] = $supdate;
$ar[$rowCount]['ServerUpdate'] = $mupdate;
$rowCount++;
}

print json_encode($ar);
}


You must declare the variable of array first in the top.



You can directly call from mysql what data needed. Hope can help.






share|improve this answer



















  • 1




    why do I need to declare the variable array first?
    – Lawrence Agulto
    Nov 14 '18 at 6:46






  • 1




    You're not adding the rest of row's values to ar.
    – Tordek
    Nov 14 '18 at 6:48










  • edited up there.
    – j3thamz
    Nov 14 '18 at 6:56










  • What is the difference between SELECT * and SELECT (Column specified)?
    – Lawrence Agulto
    Nov 14 '18 at 6:56










  • @LawrenceAgulto this may occur when you have many array data to fetch.
    – j3thamz
    Nov 14 '18 at 6:57



















0














It could be like this way.



$contactID = $_GET["Contact"];
$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$contactID'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
$data = array();
while($row = mysqli_fetch_array($result)){

$row['supdate'] = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$row['supdate'] = date("Y-m-d h:i", strtotime($row['MobileUpdate']));

$data = $row;
}
print json_encode($data);
}


updated for multiple records






share|improve this answer























  • I am only getting 1 row
    – Lawrence Agulto
    Nov 14 '18 at 6:32










  • Agreed because you are passing contactId so it will return one id. and that's why I removed while loop. Secondly one row is in result so no need to pass in array as row is already an array.
    – Naveed Ramzan
    Nov 14 '18 at 6:38










  • When I use the query it returns 5000 rows. That is why I have while loop. I need that 5000 rows What I need is to improve the retrieval time
    – Lawrence Agulto
    Nov 14 '18 at 6:40










  • @LawrenceAgulto Updated for multiple rows.
    – Naveed Ramzan
    Nov 14 '18 at 6:45










  • use ar= instead of print
    – Tordek
    Nov 14 '18 at 6:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294251%2fphp-improve-data-retrieving%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














$ContactID = $_GET["Contact"];
$ar = array();
$sql = "SELECT ContactID,FileAs, FirstName ,MiddleName ,LastName ,Position ,Company ,CompanyID ,ContactType ,RetailerType ,PresStreet
,PresBarangay ,PresDistrict ,PresTown , PresProvince ,PresCountry ,Landmark ,Telephone1 , Telephone2 ,Mobile
,Email ,Employee ,Customer ,Coordinator FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
$rowCount = 0;
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar[$rowCount] = $row;
$ar[$rowCount]['ServerUpdate'] = $supdate;
$ar[$rowCount]['ServerUpdate'] = $mupdate;
$rowCount++;
}

print json_encode($ar);
}


You must declare the variable of array first in the top.



You can directly call from mysql what data needed. Hope can help.






share|improve this answer



















  • 1




    why do I need to declare the variable array first?
    – Lawrence Agulto
    Nov 14 '18 at 6:46






  • 1




    You're not adding the rest of row's values to ar.
    – Tordek
    Nov 14 '18 at 6:48










  • edited up there.
    – j3thamz
    Nov 14 '18 at 6:56










  • What is the difference between SELECT * and SELECT (Column specified)?
    – Lawrence Agulto
    Nov 14 '18 at 6:56










  • @LawrenceAgulto this may occur when you have many array data to fetch.
    – j3thamz
    Nov 14 '18 at 6:57
















4














$ContactID = $_GET["Contact"];
$ar = array();
$sql = "SELECT ContactID,FileAs, FirstName ,MiddleName ,LastName ,Position ,Company ,CompanyID ,ContactType ,RetailerType ,PresStreet
,PresBarangay ,PresDistrict ,PresTown , PresProvince ,PresCountry ,Landmark ,Telephone1 , Telephone2 ,Mobile
,Email ,Employee ,Customer ,Coordinator FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
$rowCount = 0;
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar[$rowCount] = $row;
$ar[$rowCount]['ServerUpdate'] = $supdate;
$ar[$rowCount]['ServerUpdate'] = $mupdate;
$rowCount++;
}

print json_encode($ar);
}


You must declare the variable of array first in the top.



You can directly call from mysql what data needed. Hope can help.






share|improve this answer



















  • 1




    why do I need to declare the variable array first?
    – Lawrence Agulto
    Nov 14 '18 at 6:46






  • 1




    You're not adding the rest of row's values to ar.
    – Tordek
    Nov 14 '18 at 6:48










  • edited up there.
    – j3thamz
    Nov 14 '18 at 6:56










  • What is the difference between SELECT * and SELECT (Column specified)?
    – Lawrence Agulto
    Nov 14 '18 at 6:56










  • @LawrenceAgulto this may occur when you have many array data to fetch.
    – j3thamz
    Nov 14 '18 at 6:57














4












4








4






$ContactID = $_GET["Contact"];
$ar = array();
$sql = "SELECT ContactID,FileAs, FirstName ,MiddleName ,LastName ,Position ,Company ,CompanyID ,ContactType ,RetailerType ,PresStreet
,PresBarangay ,PresDistrict ,PresTown , PresProvince ,PresCountry ,Landmark ,Telephone1 , Telephone2 ,Mobile
,Email ,Employee ,Customer ,Coordinator FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
$rowCount = 0;
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar[$rowCount] = $row;
$ar[$rowCount]['ServerUpdate'] = $supdate;
$ar[$rowCount]['ServerUpdate'] = $mupdate;
$rowCount++;
}

print json_encode($ar);
}


You must declare the variable of array first in the top.



You can directly call from mysql what data needed. Hope can help.






share|improve this answer














$ContactID = $_GET["Contact"];
$ar = array();
$sql = "SELECT ContactID,FileAs, FirstName ,MiddleName ,LastName ,Position ,Company ,CompanyID ,ContactType ,RetailerType ,PresStreet
,PresBarangay ,PresDistrict ,PresTown , PresProvince ,PresCountry ,Landmark ,Telephone1 , Telephone2 ,Mobile
,Email ,Employee ,Customer ,Coordinator FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
$rowCount = 0;
while ($row = mysqli_fetch_array($result)) {
$supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
$ar[$rowCount] = $row;
$ar[$rowCount]['ServerUpdate'] = $supdate;
$ar[$rowCount]['ServerUpdate'] = $mupdate;
$rowCount++;
}

print json_encode($ar);
}


You must declare the variable of array first in the top.



You can directly call from mysql what data needed. Hope can help.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 6:55

























answered Nov 14 '18 at 6:42









j3thamz

764




764








  • 1




    why do I need to declare the variable array first?
    – Lawrence Agulto
    Nov 14 '18 at 6:46






  • 1




    You're not adding the rest of row's values to ar.
    – Tordek
    Nov 14 '18 at 6:48










  • edited up there.
    – j3thamz
    Nov 14 '18 at 6:56










  • What is the difference between SELECT * and SELECT (Column specified)?
    – Lawrence Agulto
    Nov 14 '18 at 6:56










  • @LawrenceAgulto this may occur when you have many array data to fetch.
    – j3thamz
    Nov 14 '18 at 6:57














  • 1




    why do I need to declare the variable array first?
    – Lawrence Agulto
    Nov 14 '18 at 6:46






  • 1




    You're not adding the rest of row's values to ar.
    – Tordek
    Nov 14 '18 at 6:48










  • edited up there.
    – j3thamz
    Nov 14 '18 at 6:56










  • What is the difference between SELECT * and SELECT (Column specified)?
    – Lawrence Agulto
    Nov 14 '18 at 6:56










  • @LawrenceAgulto this may occur when you have many array data to fetch.
    – j3thamz
    Nov 14 '18 at 6:57








1




1




why do I need to declare the variable array first?
– Lawrence Agulto
Nov 14 '18 at 6:46




why do I need to declare the variable array first?
– Lawrence Agulto
Nov 14 '18 at 6:46




1




1




You're not adding the rest of row's values to ar.
– Tordek
Nov 14 '18 at 6:48




You're not adding the rest of row's values to ar.
– Tordek
Nov 14 '18 at 6:48












edited up there.
– j3thamz
Nov 14 '18 at 6:56




edited up there.
– j3thamz
Nov 14 '18 at 6:56












What is the difference between SELECT * and SELECT (Column specified)?
– Lawrence Agulto
Nov 14 '18 at 6:56




What is the difference between SELECT * and SELECT (Column specified)?
– Lawrence Agulto
Nov 14 '18 at 6:56












@LawrenceAgulto this may occur when you have many array data to fetch.
– j3thamz
Nov 14 '18 at 6:57




@LawrenceAgulto this may occur when you have many array data to fetch.
– j3thamz
Nov 14 '18 at 6:57













0














It could be like this way.



$contactID = $_GET["Contact"];
$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$contactID'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
$data = array();
while($row = mysqli_fetch_array($result)){

$row['supdate'] = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$row['supdate'] = date("Y-m-d h:i", strtotime($row['MobileUpdate']));

$data = $row;
}
print json_encode($data);
}


updated for multiple records






share|improve this answer























  • I am only getting 1 row
    – Lawrence Agulto
    Nov 14 '18 at 6:32










  • Agreed because you are passing contactId so it will return one id. and that's why I removed while loop. Secondly one row is in result so no need to pass in array as row is already an array.
    – Naveed Ramzan
    Nov 14 '18 at 6:38










  • When I use the query it returns 5000 rows. That is why I have while loop. I need that 5000 rows What I need is to improve the retrieval time
    – Lawrence Agulto
    Nov 14 '18 at 6:40










  • @LawrenceAgulto Updated for multiple rows.
    – Naveed Ramzan
    Nov 14 '18 at 6:45










  • use ar= instead of print
    – Tordek
    Nov 14 '18 at 6:49
















0














It could be like this way.



$contactID = $_GET["Contact"];
$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$contactID'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
$data = array();
while($row = mysqli_fetch_array($result)){

$row['supdate'] = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$row['supdate'] = date("Y-m-d h:i", strtotime($row['MobileUpdate']));

$data = $row;
}
print json_encode($data);
}


updated for multiple records






share|improve this answer























  • I am only getting 1 row
    – Lawrence Agulto
    Nov 14 '18 at 6:32










  • Agreed because you are passing contactId so it will return one id. and that's why I removed while loop. Secondly one row is in result so no need to pass in array as row is already an array.
    – Naveed Ramzan
    Nov 14 '18 at 6:38










  • When I use the query it returns 5000 rows. That is why I have while loop. I need that 5000 rows What I need is to improve the retrieval time
    – Lawrence Agulto
    Nov 14 '18 at 6:40










  • @LawrenceAgulto Updated for multiple rows.
    – Naveed Ramzan
    Nov 14 '18 at 6:45










  • use ar= instead of print
    – Tordek
    Nov 14 '18 at 6:49














0












0








0






It could be like this way.



$contactID = $_GET["Contact"];
$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$contactID'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
$data = array();
while($row = mysqli_fetch_array($result)){

$row['supdate'] = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$row['supdate'] = date("Y-m-d h:i", strtotime($row['MobileUpdate']));

$data = $row;
}
print json_encode($data);
}


updated for multiple records






share|improve this answer














It could be like this way.



$contactID = $_GET["Contact"];
$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$contactID'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
$data = array();
while($row = mysqli_fetch_array($result)){

$row['supdate'] = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
$row['supdate'] = date("Y-m-d h:i", strtotime($row['MobileUpdate']));

$data = $row;
}
print json_encode($data);
}


updated for multiple records







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 6:54

























answered Nov 14 '18 at 6:28









Naveed Ramzan

2,62531625




2,62531625












  • I am only getting 1 row
    – Lawrence Agulto
    Nov 14 '18 at 6:32










  • Agreed because you are passing contactId so it will return one id. and that's why I removed while loop. Secondly one row is in result so no need to pass in array as row is already an array.
    – Naveed Ramzan
    Nov 14 '18 at 6:38










  • When I use the query it returns 5000 rows. That is why I have while loop. I need that 5000 rows What I need is to improve the retrieval time
    – Lawrence Agulto
    Nov 14 '18 at 6:40










  • @LawrenceAgulto Updated for multiple rows.
    – Naveed Ramzan
    Nov 14 '18 at 6:45










  • use ar= instead of print
    – Tordek
    Nov 14 '18 at 6:49


















  • I am only getting 1 row
    – Lawrence Agulto
    Nov 14 '18 at 6:32










  • Agreed because you are passing contactId so it will return one id. and that's why I removed while loop. Secondly one row is in result so no need to pass in array as row is already an array.
    – Naveed Ramzan
    Nov 14 '18 at 6:38










  • When I use the query it returns 5000 rows. That is why I have while loop. I need that 5000 rows What I need is to improve the retrieval time
    – Lawrence Agulto
    Nov 14 '18 at 6:40










  • @LawrenceAgulto Updated for multiple rows.
    – Naveed Ramzan
    Nov 14 '18 at 6:45










  • use ar= instead of print
    – Tordek
    Nov 14 '18 at 6:49
















I am only getting 1 row
– Lawrence Agulto
Nov 14 '18 at 6:32




I am only getting 1 row
– Lawrence Agulto
Nov 14 '18 at 6:32












Agreed because you are passing contactId so it will return one id. and that's why I removed while loop. Secondly one row is in result so no need to pass in array as row is already an array.
– Naveed Ramzan
Nov 14 '18 at 6:38




Agreed because you are passing contactId so it will return one id. and that's why I removed while loop. Secondly one row is in result so no need to pass in array as row is already an array.
– Naveed Ramzan
Nov 14 '18 at 6:38












When I use the query it returns 5000 rows. That is why I have while loop. I need that 5000 rows What I need is to improve the retrieval time
– Lawrence Agulto
Nov 14 '18 at 6:40




When I use the query it returns 5000 rows. That is why I have while loop. I need that 5000 rows What I need is to improve the retrieval time
– Lawrence Agulto
Nov 14 '18 at 6:40












@LawrenceAgulto Updated for multiple rows.
– Naveed Ramzan
Nov 14 '18 at 6:45




@LawrenceAgulto Updated for multiple rows.
– Naveed Ramzan
Nov 14 '18 at 6:45












use ar= instead of print
– Tordek
Nov 14 '18 at 6:49




use ar= instead of print
– Tordek
Nov 14 '18 at 6:49


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294251%2fphp-improve-data-retrieving%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)