Codeigniter Transaction inside Control - php

Since I have several functions executing in the following control as a single transaction I couldn't surround each function as a transaction in the model. So I did it the following way. Please someone let me know if there is any problem. Works fine for now, but have no idea whether it will get any concurrency issues or there is any other way?
if(isset($_POST['btnsave']))
{
$mcodes = $_POST['tblmcode'];
$count = count($mcodes);
//echo $count;
$issue = new Materialissue_model();
$this->db->trans_start(); //Here starts my transaction
$issue->setIssuecode($this->input->post('txtissuecode'));
if($issue->checkNoExistence()) {
$issue->setDate($this->input->post('txtdate'));
$issue->setCustomer($this->input->post('txtcustomer'));
$issue->setFromlocation($this->input->post('txtlocation'));
$issue->setResponsible($this->input->post('txtresponsible'));
$issue->setComments($this->input->post('txtcomments'));
$issue->setTotal($this->input->post('txttotal'));
$issue->setUser($this->session->userdata('username'));
$issue->setStatus($this->input->post('txtstatus'));
for ($i = 0; $i < $count; $i++) {
$issue->setMaterialcode($_POST['tblmcode'][$i]);
$issue->setMaterialname($_POST['tblmname'][$i]);
$issue->setCost($_POST['tblcost'][$i]);
$issue->setQty($_POST['tblqty'][$i]);
$issue->setSubtotal($_POST['tblsubtotal'][$i]);
$issue->saveIssueDetail();
$stock = new Materialstock_model();
$stock->setItemcode($_POST['tblmcode'][$i]);
$stock->setItemlocation($this->input->post('txtlocation'));
$stock->setQty($_POST['tblqty'][$i]);
$stock->setRefno($this->input->post('txtissuecode'));
$stock->setLasttransaction('MATERIAL-ISSUE');
$stock->updateMaterialIssueStock();
$transaction = new Transaction_model();
$transaction->setDescription("MATERIAL-ISSUE");
$transaction->setItemcode($_POST['tblmcode'][$i]);
$transaction->setRecqty("0");
$transaction->setTransqty("0");
$transaction->setIssueqty($_POST['tblqty'][$i]);
$transaction->setDate($this->input->post('txtdate'));
$transaction->setUser($this->session->userdata('username'));
$transaction->saveMaterialTransaction();
}
$result = $issue->saveIssue();
$this->db->trans_complete(); //Here ends my transaction
if ($result) {
$message = new Message_model();
$data['message'] = $message->recordadded;
$data['type'] = "success";
$data['returnpage'] = base_url() . "index.php/materialissue_control/show";
$data["print"] = base_url() . "index.php/Notegenerator_control/showMaterialIssueNote?code=".$issue->getIssuecode();
$this->load->view('messageprint_view', $data);
}
}else{
$message = new Message_model();
$data['message'] = $message->issuecodeexists;
$data['type'] = "error";
$data['returnpage'] = base_url() . "index.php/materialissue_control/show";
$this->load->view('message_view', $data);
}
}

I prefer like using trigger to handle many functions in one controller, this make mycode clean and easy to track. example:
user writes article, this action will call one action in model write_article combine with 1 transaction, but this function run any query :
1.insert post
2.lock count post category
3.lock count user post
4.lock count post by date
example in code
public function write_article($post) {
$this->cms->db->trans_start(TRUE);
$this->cms->db->set('content', $posts->get_content());
$this->cms->db->insert('t_posts');
$this->cms->db->trans_complete();
if($this->cms->db->trans_status() === TRUE){
$this->cms->db->trans_commit();
}else{
$this->cms->db->trans_rollback();
}
}
This reference about trigger
www.sitepoint.com/how-to-create-mysql-triggers

Related

Laravel mysql data input.. Check if Users follow each other

public function follow(Request $request){
$response = array();
$response['code'] = 400;
$following_user_id = $request->input('following');
$follower_user_id = $request->input('follower');
$element = $request->input('element');
$size = $request->input('size');
$following = User::find($following_user_id);
$follower = User::find($follower_user_id);
if ($following && $follower && ($following_user_id == Auth::id() || $follower_user_id == Auth::id())){
$relation = UserFollowing::where('following_user_id', $following_user_id)->where('follower_user_id', $follower_user_id)->get()->first();
if ($relation){
if ($relation->delete()){
$response['code'] = 200;
if ($following->isPrivate()) {
$response['refresh'] = 1;
}
}
}else{
$relation = new UserFollowing();
$relation->following_user_id = $following_user_id;
$relation->follower_user_id = $follower_user_id;
if ($following->isPrivate()){
$relation->allow = 0;
}else{
$relation->allow = 1;
}
if ($relation->save()){
$response['code'] = 200;
$response['refresh'] = 0;
if ($following && $follower){
$relationz = new UserRelationship();
$relationz->main_user_id = $following_user_id;
$relationz->relation_type = 1;
$relationz->related_user_id = $follower_user_id;
$relationz->allow = 1;
$relationz->save();
}
}
}
if ($response['code'] == 200){
$response['button'] = sHelper::followButton($following_user_id, $follower_user_id, $element, $size);
}
}
return Response::json($response);
}
Hey guys, I have this code which creates a follow among two users.
I added a function to be personal friends 'relationz' as well.
Currently when you follow a user, you become 'relationz' automatically..
I would like to create a new 'relationz' only when the follower is also followed by the same person, my question is what change must I make here to either:
a) stop an auto-friend when only one user follows..
b) detect when each person follows each other..
I'm not sure which is the better logic?
I was wrongly thinking the simple "if (follower && following)" was enough, maybe it is just in the wrong place?
Thanks for any help!
How is your relations set up?
since i see a whole lot of code and if the follow function is in you controller, that will be a mess to sort out later when bug fixing.
so you have a many to many relation ship called followers in the user model?
so if user a would follow user b user a would give a follower result of 1
and if user b would have followers than it would be 0 correct?
so what i would do, if both are following each other you should have 2 rows with both users in the pivot table.
so I would create a new relationship relationz with a wherehas query in it
public function relationz {
return $this->belongsToMany(Follower::class)->whereHas('followers' , function($query) {
$query->where('followed_id', auth()->user_id);
})
}
Something like that.

Processing multi-step form in Laravel

I am quite new to laravel I have to insert many form fields in database so I divided the fields into multiple sections what I want to achieve is to store data of each section when user clicks next button and step changes and when user clicks previous button and makes some changes the database should be updated and if user leaves the form incomplete then when he logins next time form fill should fill up from the step he left in, till now i have successfully achieved to change steps and in first step 1 inserted the data into database and for other step i updated the database but I am having trouble if user comes to first step and again changes the forms fields how to update again first step data i am using ajax to send data and steps number
My Controller
function saveJobPostFirstStage(Request $request)
{
$currentEmployer = Auth::guard('employer')->user();
//$data['currentEmployer'] = $currentEmployer;
$employer_id = $currentEmployer->id;
$random = $this->generateRandomString();
$jobOne = new Job();
//Session::pull('insertedId');
if ($request->ajax()) {
try {
$stepPost = $request->all();
$step = $stepPost['stepNo'];
$insertedId = $stepPost['insertedId'];
switch ($step) {
case '1':
if ($insertedId == 0) {
$jobOne->employer_id = $employer_id;
$jobOne->job_title = $stepPost['jobTitle'];
$jobOne->company_id = (int)$stepPost['companyName'];
$jobOne->country_id = (int)$stepPost['country'];
$jobOne->state_id = (int)$stepPost['state'];
$jobOne->city_id = (int)$stepPost['city'];
$jobOne->street_address = $stepPost['street'];
$jobOne->job_code = $random;
$stepOne = $jobOne->save();
if ($stepOne) {
Session::put('insertedId',$jobOne->id);
//session(['insertedId'=>$jobOne->id]);
$success = ['success' => "Success",
'insertedId' => $jobOne->id];
//return json_encode($success);
}
}
else
{
$jobOne->employer_id = $employer_id;
$jobOne->job_title = $stepPost['jobTitle'];
$jobOne->company_id = (int)$stepPost['companyName'];
$jobOne->country_id = (int)$stepPost['country'];
$jobOne->state_id = (int)$stepPost['state'];
$jobOne->city_id = (int)$stepPost['city'];
$jobOne->street_address = $stepPost['street'];
$jobOne->job_code = $random;
$stepOne = $jobOne->whereId($insertedId)->update(['employer_id'=>$jobOne->employer_id,'job_title'=>$jobOne->job_title,'company_id'=> $jobOne->company_id,'state_id'=>$jobOne->state_id,'country_id'=>$jobOne->country_id,'city_id'=>$jobOne->city_id,'street_address'=>$jobOne->street_address,'job_code'=>$jobOne->job_code = $random]);
if ($stepOne) {
$success = ['success' => "Changes Made Successfully"];
return json_encode($success);
}
}
break;
case '2':
$jobOne->employment_type_id = (int)($stepPost['employmentType']);
$jobOne->job_type_id = (int)($stepPost['jobType']);
$jobOne->job_level_id = (int)($stepPost['jobLevel']);
$jobOne->industry_type_id = (int)($stepPost['industryType']);
$jobOne->job_category_id = (int)($stepPost['jobCategory']);
//$jobOne->salary = $stepPost['jobSalaryRange'];
$jobOne->salary_period_id = (int)$stepPost['salaryPeriod'];
//$jobOne->vacancy_end_date = $stepOne['applicationDeadline'];
$stepOne = $jobOne->whereId($insertedId)->update(['employment_type_id'=> $jobOne->employment_type_id,'job_type_id'=>$jobOne->job_type_id,'job_level_id'=> $jobOne->job_level_id,'industry_type_id'=>$jobOne->industry_type_id,'job_category_id'=>$jobOne->job_category_id,'salary_period_id'=>$jobOne->salary_period_id]);
if ($stepOne) {
$success = ['success' => "Changes Made Successfully"];
return json_encode($success);
}
break;
case '3':
$jobOne->job_description = $stepPost['jobDescription'];
$jobOne->job_specification = $stepPost['jobSpecifications'];
$jobOne->job_responsibilities = $stepPost['jobResponsibilities'];
$stepOne = $jobOne->whereId($insertedId)->update(['job_description'=>$jobOne->job_description,'job_specification'=>$jobOne->job_specification,'job_responsibilities'=>$jobOne->job_responsibilities]);
if ($stepOne) {
$success = ['success' => "Changes Made Successfully"];
return json_encode($success);
}
default:
# code...
break;
}
return json_encode($stepPost);
//$this->alertMessage = 'Your Phone has been added Successfully.';
//$this->alertType = 'success';
} catch (QueryException $e) {
return $e->getMessage();
}
/* return redirect()->route('employer-account-page')
->with([
'alertMessage' => $this->alertMessage,
'alertType' => $this->alertType
]);*/
// $stepPost = Input::all();
}
/*$stepOne = $request->all();
$country_Id = (int)$stepOne['country'];
return json_encode((getType($country_Id)));*/
}
First of, your code is messy.
You should have a single table per form where each form have it's parent id.
The next step to refactor the code would be to create a single controler per form (you don't need it, but you want this)
Each form (a model) should have a method that recalculates the values of itself based on other forms, so that if you change a first form, then you can call the method that recalculates the second form, then call method of second form that recalculates the third form, etc.
This interface could be helpful
interface IForm {
public function getPreviousForm() : ?IForm; // These notations are since PHP7.1
public function recalculate() : void;
public function getNextForm() : ?IForm;
}
A simple code how it should work in practice
$formX->save();
$formX->getNextForm()->recalculate(); // This will call formX->recalculate(); formX+1->getNextForm()->recalculate()
// which will call formX+1->recalculate(); formX+2->getNextForm()->recalculate()
// etc...
// while getNextForm() != null
You may also need this if you would need to insert another form in the middle of the chain.
Hope it helps

PHP+Apache2+Ubuntu Server: How to get all threads to work in parallel?

I usually work with web hosting companies but I decided to start learning working with servers to expand my knowledge.
I'll better give a real example to explain my question the best:
I have a web application that gathers data from a slow API that returns JSON data of products.
I have a function running every 1AM running a lot of queries on "id"s in my database.
Crontab:
0 1 * * * cd /var/www/html/tools; php index.php aso Cli_kas kas_alert
So this creates a process for the app (please correct me here if I'm wrong) and each process creates threads, and just to be more accurate, they are multi-threads since they do more than one thing: like pulling data from the DB to get the right variables and string them to the API queries, getting the data from the API, organizing it, searching the relevant data, and then inserting new data to the database.
The main PHP functions:
// MAIN: Cron Job Function
public function kas_alert() {
// 0. Deletes all the saved data from the `data` table 1 month+ ago.
// $this->kas_model->clean_old_rows();
// 1. Get 'prod' table
$data['table'] = $this->kas_model->prod_table();
// 2. Go through each row -
foreach ( $data['table'] as $row ) {
// 2.2. Gets all vars from the first query.
$last_row_query = $this->kas_model->get_last_row_of_tag($row->tag_id);
$last_row = $last_row_query[0];
$l_aaa_id = $last_row->prod_aaa_id;
$l_and_id = $last_row->prod_bbb_id;
$l_r_aaa = $last_row->dat_data1_aaa;
$l_r_and = $last_row->dat_data1_bbb;
$l_t_aaa = $last_row->dat_data2_aaa;
$l_t_and = $last_row->dat_data2_bbb;
$tagword = $last_row->tag_word;
$tag_id = $last_row->tag_id;
$country = $last_row->kay_country;
$email = $last_row->u_email;
$prod_name = $last_row->prod_name;
// For the Weekly report:
$prod_id = $last_row->prod_id;
$today = date('Y-m-d');
// 2.3. Run the tagword query again for today on each one of the tags and insert to DB.
if ( ($l_aaa_id != 0) || ( !empty($l_aaa_id) ) ) {
$aaa_data_today = $this->get_data1_aaa_by_id_and_kw($l_aaa_id, $tagword, $country);
} else{
$aaa_data_today['data1'] = 0;
$aaa_data_today['data2'] = 0;
$aaa_data_today['data3'] = 0;
}
if ( ($l_and_id != 0) || ( !empty($l_and_id) ) ) {
$bbb_data_today = $this->get_data1_bbb_by_id_and_kw($l_and_id, $tagword, $country);
} else {
$bbb_data_today['data1'] = 0;
$bbb_data_today['data2'] = 0;
$bbb_data_today['data3'] = 0;
}
// 2.4. Insert the new variables to the "data" table.
if ($this->kas_model->insert_new_tag_to_db( $tag_id, $aaa_data_today['data1'], $bbb_data_today['data1'], $aaa_data_today['data2'], $bbb_data_today['data2'], $aaa_data_today['data3'], $bbb_data_today['data3']) ){
}
// Kas Alert Outputs ($SEND is echoed in it's original function)
echo "<h1>prod Name: $prod_id</h1>";
echo "<h2>tag id: $tag_id</h2>";
var_dump($aaa_data_today);
echo "aaa old: ";
echo $l_r_aaa;
echo "<br> aaa new: ";
echo $aaa_data_today['data1'];
var_dump($bbb_data_today);
echo "<br> bbb old: ";
echo $l_r_and;
echo "<br> bbb new: ";
echo $bbb_data_today['data1'];
// 2.5. Check if there is a need to send something
$send = $this->check_if_send($l_aaa_id, $l_and_id, $l_r_aaa, $aaa_data_today['data1'], $l_r_and, $bbb_data_today['data1']);
// 2.6. If there is a trigger, send the email!
if ($send) {
$this->send_mail($l_aaa_id, $l_and_id, $aaa_data_today['data1'], $bbb_data_today['data1'], $l_r_aaa, $l_r_and, $tagword, $email, $prod_name);
}
}
}
For #Raptor, this is the function that get's the API data:
// aaa tag Query
// Gets aaa prod dataing by ID.
public function get_data_aaa_by_id_and_tg($id, $tag, $query_country){
$tag_for_url = rawurlencode($tag);
$found = FALSE;
$i = 0;
$data = array();
// Create a stream for Json. That's how the code knows what to expect to get.
$context_opts = array(
'http' => array(
'method' => "GET",
'header' => "Accepts: application/json\r\n"
));
$context = stream_context_create($context_opts);
while ($found == FALSE) {
// aaa Query
$json_query_aaa = "https://api.example.com:443/aaa/ajax/research_tag?app_id=$id&term=$tag_for_url&page_index=$i&country=$query_country&auth_token=666";
// Get the Json
$json_query_aaa = file_get_contents($json_query_aaa, false, $context);
// Turn Json to a PHP array
$json_query_aaa = json_decode($json_query_aaa, true);
// Get the data2
$data2 = $json_query_aaa['tag']['data2'];
if (is_null($data2)){ $data2 = 0; }
// Get data3
$data3 = $json_query_aaa['tag']['phone_prod']['data3'];
if (is_null($data3)){ $data3 = 0; }
// Finally, the main prod array.
$json_query_aaa = $json_query_aaa['tag']['phone_prod']['app_list'];
if ( count($json_query_aaa) > 2 ) {
for ( $j=0; $j<count($json_query_aaa); $j++ ) {
if ( $json_query_aaa[$j]['id'] == $id ) {
$found = TRUE;
$data = $json_query_aaa[$j]['data'] + 1;
break;
}
if ($found == TRUE){
break;
}
}
$i++;
} else {
$data = 0;
break;
}
}
$data['data1'] = $data;
$data['data2'] = $data2;
$data['data3'] = $data3;
return $data;
}
All threads are stacked one after an other, and when one thread is done, only then - the second thread can proceed, ect'.
And in technical view on this, all threads wait in the RAM until the one before them is done working "inside" the CPU. (correct me if I'm wrong again :] )
This doesn't even "tickle" the servers RAM or CPU when looking at it in the process manager (I use "htop"). RAM is at 400M/4.25G and CPU at ONLY 0.7%-1.3%.
Making me feel this isn't the best I can get from my current server, and getting slow results from my web app.
How do I get things done in a way that all threads work in parallel, but not to a point that my app crashes due to lacks of CPU or RAM?

Advanced search Using Pagination in codeigniator

I want to set all the advanced search parameter using session how to set all the parameter at time.
I am using following function but it only set one parameter at time how to set all the parameter at time
public function searchterm_handler($searchterm)
{
if($searchterm)
{
$this->session->set_userdata('searchterm', $searchterm);
return $searchterm;
}
elseif($this->session->userdata('searchterm'))
{
$searchterm = $this->session->userdata('searchterm');
return $searchterm;
}
else
{
$searchterm ="";
return $searchterm;
} }
Method one (recommended)
So for pagination in CodeIgniter, you have 3 main variables you must set and a configuration method to call. You also have a library you must load.
The library is $this->load->library('pagination');
The 3 variables and configuration look like this:
//This next line is used mainly so the page number links on your pagination work.
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = $NumberOfRecords;
$config['per_page'] = 20;
$this->pagination->initialize($config);
If you are using MVC then this is quite simple. You would use the above code in your controller, grab the data you want to display starting at the nth row, where n is the page number * $config['per_page'], and ending at ((page number * $config['per_page']) + $config['per_page'])-1.
After getting the necessary data you would return that and the link code to your view. The link code is $this->pagination->create_links();
So your return might look something like this:
$data["results"] = $this->MyModel->MySqlMethod($config["per_page"], $CurrentPage);
$data["links"] = $this->pagination->create_links();
Then in your view you would loop through the $data["results"] and after the loop you would display the $data["links"]
This would give you your data displayed then the pagination at the bottom would look something like
So your controller all together should look like:
$config['base_url'] = 'http://example.com/index.php/controllerName/ViewName/';
$config['total_rows'] = $NumberOfRecords;
$config['per_page'] = 20;
$this->pagination->initialize($config);
$data["results"] = $this->MyModel->MySqlMethod($config["per_page"], $CurrentPage);
$data["links"] = $this->pagination->create_links();
return $this->load->view("ViewName", $data);
Method Two (NOT recommended)
Now you mentioned something about storing that data in Session Variables. I mean if you want you can do this. If you are going to use that method, then that tell you are not using MVC. CodeIgniter is meant for MVC. If you are not using MVC then you probably do not need CodeIgniter. If you are comfortable using CodeIgniter and do not want to try and implement the MVC, by all means go ahead.
To do the CodeIgniter Pagination in this method, you would change your public searchterm_handler($searchterm) function. The thing with session variables is that they are stored on the users browser so that way you, the programmer, can access them anywhere on your site without having to return and pass them from class to class or method to method. If you set a session variable then you return it, that is redundent and unnecessary.
You don't really need this method, it is unnecessary, but you could do something like this:
public function searchterm_handler($searchterm) {
$result = mysqli_query("SELECT count(*) FROM User_info");
$row = mysqli_fetch_row($result);
$TotalDataCount = $row[0];
$this->session->set_userdata("TotalDataCount", $TotalDataCount);
$this->session->set_userdata("RecordsPerPage", 20);
$this->session->set_userdata("BaseURL", www.example.com/link/to/your/page.php);
$this->pagination->initialize($config);
if($searchterm) {
$this->session->set_userdata('searchterm', $searchterm);
//Unnecessary
//return $searchterm;
} else {
$this->session->set_userdata('searchterm', "");
//return $searchterm;
}
}
Then in the code that called searchterm_handler($searchterm), you would do this:
searchterm_handler($input);
$searchterm = $this->session->userdata('searchterm');
$dataToReturn = array();
if($searchterm!="") {
$result = mysqli_query("SELECT * FROM table WHERE field LIKE '%$this->session->userdata('searchterm')%'");
if($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
echo $this->pagination->create_links();
LET ME WORN YOU
This second method, is gross and ugly and yucky and very badly written. There is no real good way to write what you want to write. The purpose of using CodeIgniter is for MVC and built in CodeIgniter functionality, which you lose almost all of it when you get rid of MVC.
I know there is a chance I misunderstood what you are trying to do, but this was my best guess. My best advice for you is to use MVC in CodeIgniter.
Here are some sources that may help you if you use the first method:
https://www.sitepoint.com/pagination-with-codeigniter/
https://www.codeigniter.com/userguide3/libraries/pagination.html
I hope this helps, I spent a lot of time writing it...
Update - Method 3
I tried looking at your question again and maybe this will help
public function searchterm_handler($searchterm)
{
if($searchterm && $this->session->userdata('email'))
{ //user logged in
$this->session->set_userdata('searchterm', $searchterm);
$array = array(
"searchterm" => $searchterm,
"email" => $this->session->userdata('email'),
"username" => $this->session->userdata('username')
);
return $array;
}
else if($searchterm && !$this->session->userdata('searchterm'))
{ //user not logged in
$this->session->set_userdata('searchterm', $searchterm);
return $searchterm;
}
elseif($this->session->userdata('searchterm') && $this->session->userdata('searchterm'))
{ //user logged in
$searchterm = $this->session->userdata('searchterm');
$array = array(
"searchterm" => $searchterm,
"email" => $this->session->userdata('email'),
"username" => $this->session->userdata('username')
);
return $array;
}
elseif($this->session->userdata('searchterm') && !$this->session->userdata('searchterm'))
{ //user not logged in
$searchterm = $this->session->userdata('searchterm');
return $searchterm;
}
else
{
$searchterm ="";
return $searchterm;
} }
sorry if this is may, I did it on my phone

Getting Data from MYSQL DB

I'm facing problems when trying to get data from a MySQL Database in an Android application
The output is:
06-29 11:40:42.123: E/JSON(1426): {"tag":"getroute","success":1,"error":0,"products":[]}
I think the problem I’m facing is in my PHP file (this is the code of the tag):
if( . . . )
{
. . .
}
else if ($tag == 'getroute')
{
$endloc = $_POST['end'];
$op = $db->getRoutes($endloc);
if ($op)
{
$response["products"] = array();
while($data= mysql_fetch_assoc($op))
{
$product = array();
$product ["uname"] = $data["uname"];
$product ["start"] = $data["start"];
$product ["end"] = $data["end"];
$product ["meet1"] = $data["meet1"];
$product ["meet1time"] = $data["meet1time"];
$product ["meet2"] = $data["meet2"];
$product ["meet2time"] = $data["meet2time"];
$product ["meet3"] = $data["meet3"];
$product ["meet3time"] = $data["meet3time"];
$product ["ismoke"] = $data["ismoke"];
$product ["iwomen"] = $data["iwomen"];
$product ["ctime"] = $data["ctime"];
$product ["seats"] = $data["seats"];
// push single product into final response array
array_push($response["products"], $product);
}
$response["success"] = 1;
echo json_encode($response);
// user stored successfully
}
else
{
// user failed to store
$response["error"] = 1;
$response["error_msg"] = "Error occured in Making Route";
echo json_encode($response);
}
}
I don’t know where the problem is. I searched over the internet and I found some tutorials but they always give me this error.
Function getroute :
public function getRoutes($endlocation)
{
$result = mysql_query("SELECT * FROM routes WHERE end = '$endlocation'");
return $result;
}
Try checking the number of results with mysql_num_rows() before you begin your while.
Additionally, immediately after your while, try using print_r($data) to verify that there is stuff in your record.
It seems to me that you're just having issues with your data source.

Categories