codeigniter calendar class error message - php

I use codeigniter calendar class and i am trying to display all reservations for the current month. In the field where the day is, I may have more than one result,and I would like to display them coma separated.
However, I get the following error message:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$reservationID
Filename: models/reservationcalendarmodel.php
Line Number: 81
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$reservationArrivalDate
Filename: models/reservationcalendarmodel.php
Line Number: 81
Error is displayed 10 times ( i expect 9 records from the database)
Here is the (relevant) code from the model:
function getReservations($year,$month) {
$currentHotelUser = $this->session->userdata('currentHotelUser');
$query = $this->db->query(
"SELECT r.*
FROM room r
LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate
FROM reservationroom rr
LEFT JOIN reservation re ON re.reservationID = rr.reservationID
WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%'))
sq ON sq.roomID = r.roomID
WHERE r.hotelID = ".$currentHotelUser['hotelID']."
AND sq.reservationID IS NOT NULL
");
$cal_data = array();
foreach($query->result() as $row) {
// BELLOW IS THE LINE 81 WHERE THE ERROR IS
$cal_data[substr($row->reservationArrivalDate,8,2)]= $row->reservationID;
}
return $cal_data;
}
function generate($year,$month) {
$cal_data = $this->getReservations($year, $month);
$this->load->library('calendar', $this->conf);
return $this->calendar->generate($year,$month,$cal_data);
}
Here is the (relevant) code from the controller:
$this->load->model('ReservationCalendarModel');
$data['calendar'] = $this->ReservationCalendarModel->generate($year,$month);
Here is the (relevant) code from the view:
echo $calendar;
Did anyone know why do I get the above error?

The problem is you query results not having reservationID and reservationArrivalDate. That is the reason, while looping through you are getting this error. Add these two columns in your main select query
"SELECT r.*, sq.roomID, sq.reservationId
FROM room r
LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate
FROM reservationroom rr
LEFT JOIN reservation re ON re.reservationID = rr.reservationID
WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%'))
sq ON sq.roomID = r.roomID
WHERE r.hotelID = ".$currentHotelUser['hotelID']."
AND sq.reservationID IS NOT NULL
"

Related

A Database Error Occurred table doesn't exist

After update codeignitor 3.1.11 there is a database error like
A Database Error Occurred
Error Number: 1146
Table 'db_bill_app.Users' doesn't exist
SELECT COUNT(*) AS `numrows` FROM `db_PaymentHistory` AS `PH` LEFT JOIN
Users AS U ON PH.fk_UserGlCode = U.intGlCode LEFT JOIN ManageAcc AS MA ON
PH.fk_UserGlCode = MA.intGlCode
Filename: D:/wamp/www/project/alpha/system/database/DB_driver.php
Line Number: 691
here is the solution after lots of try
system/database/DB_query_builder.php
in this line
$this->qb_join[] = $join = $type.'JOIN '.$table.$cond;
i have add some code like:
$word = $this->dbprefix;
if(strpos($table, $word) !== false){
$table = $table;
}else{
$table = $word.$table;
}
to add manually prefix before table name.. enjoy

My query does not output the column I want even when selected

Not sure how I am getting the undefined index error when my SELECT already gets the column that I want.
I have three tables:
clinics_branch.add.php
<?php
session_start();
require_once('clinics_branch_list.vc.php');
?>
<?php echo $lstBranch['usrmerchant']; ?>
the undefined index is in the echo usrmerchant
clinics_branch_list.vc.php
require_once($routePath . "_mc/Merchant.mc.php");
$mcMerchant = new Merchant_MC();
$lstBranch = $mcMerchant->SelectMainBranch_ByMerchantBranch($db, $merchantid);
Merchant.mc.php
Class Merchant_MC {
public function SelectMainBranch_ByMerchantBranch($db, $merchantid) {
$stmt = $db->prepare(
" SELECT mb.merchantid, m.usrmerchant
FROM `merchant_branch` mb
LEFT JOIN `merchant` m ON mb.merchantid = m.merchantid
WHERE mb.merchantid = $merchantid "
);
$stmt->bindValue(':merchantid', $merchantid, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $row;
}
}
here's the output of my select, as you can see there is content so the SQL is working
any help is appreciated, the full error is:
Notice: Undefined index: usrmerchant in clinics_branch_add.php
UPDATE:
changing my SQL line to WHERE mb.merchantid = :merchantid still shows the same error.
UPDATE:
switching to innjer join does not work either
SELECT mb.merchantid, m.usrmerchant
FROM merchant_branch mb
INNER JOIN merchant m
ON mb.merchantid = m.merchantid
WHERE mb.merchantid = :merchantid
You're doing a fetchAll, so $lstBranch will actually be an array of rows looking something like this:
array(0 => array('merchantid' => 30, 'usrmerchant' => 'dermadent'))
and you will need to access the usrmerchant value as
$lstBranch[0]['usrmerchant'];
Change
SELECT mb.merchantid, m.usrmerchant
FROM `merchant_branch` mb
LEFT JOIN `merchant` m ON mb.merchantid = m.merchantid
WHERE mb.merchantid = $merchantid "
To
SELECT mb.merchantid, m.usrmerchant
FROM merchant_branch mb
INNER JOIN marchant m
ON mb.merchantid = m.merchantid
WHERE mb.merchantid = :merchantid

Undefined index PHP/MySQL when trying to query database

This one is working fine #1 but when I try to relate other tables on the second one, it gives an error
Notice: Undefined index: recipe.id in C:\xampp\htdocs\hyukies\public\samples.php on line 30
Notice: Undefined index: recipe.ingredientid in C:\xampp\htdocs\hyukies\public\samples.php on line 31
RecipeID:
IngredientID:
Notice: Undefined index: recipe.id in C:\xampp\htdocs\hyukies\public\samples.php on line 30
Notice: Undefined index: recipe.ingredientid in C:\xampp\htdocs\hyukies\public\samples.php on line 31
RecipeID:
IngredientID:
Notice: Undefined index: recipe.id in C:\xampp\htdocs\hyukies\public\samples.php on line 30
Notice: Undefined index: recipe.ingredientid in C:\xampp\htdocs\hyukies\public\samples.php on line 31
RecipeID:
IngredientID:
<?php
$sql = mysqli_query($connection, "SELECT id, location FROM location");
$userinfo = array();
while ($row_user = mysqli_fetch_assoc($sql))
$userinfo[] = $row_user;
foreach ($userinfo as $user) {
echo "ID: {$user['id']}<br />"
. "Location: {$user['location']}<br /><br />";
}
?>
This one is not working error problem please help......
<?php
$sql_2 = mysqli_query($connection, "SELECT recipe.id, recipe.ingredientid, ingredients.id, ingredients.quantity, ingredients.`name` FROM recipe INNER JOIN ingredients ON ingredients.id = recipe.ingredientid");
$userinfo_2 = array();
while ($row_user_2 = mysqli_fetch_assoc($sql_2))
$userinfo_2[] = $row_user_2;
foreach ($userinfo_2 as $user_2) {
echo "RecipeID: {$user_2['recipe.id']}<br />"
. "IngredientID: {$user_2['recipe.ingredientid']}<br /><br />";
}
?>
Remove the back ticks from 'name' in your query
$sql_2 = mysqli_query($connection, "SELECT recipe.id, recipe.ingredientid, ingredients.id, ingredients.quantity, ingredients.`name` FROM recipe INNER JOIN ingredients ON ingredients.id = recipe.ingredientid");
Should be
$sql_2 = mysqli_query($connection, "SELECT recipe.id, recipe.ingredientid, ingredients.id, ingredients.quantity, ingredients.name FROM recipe INNER JOIN ingredients ON ingredients.id = recipe.ingredientid");
Also, remove 'recipe' from $user_2['recipe.id']. It should be $user2['id'], but it won't be clear which id you are getting. To selected them independently you can use 'AS' in your query to give them a unique identifier.
SELECT recipe.id AS id1, ingedients.id AS id2
The keys in the associative array just contain the column names, not the table names. So it should be:
echo "RecipeID: {$user_2['id']}<br />"
. "IngredientID: {$user_2['ingredientid']}<br /><br />";
The table names are not included in the result set, so the columns are only named id, ingredientid etc. You really should use as for naming them, like recipe.id as recipeid. There is no warning about there being to id fields and PHP will map them together.
You don't really need both id fields anyway, since you also have the ingredientid, but most probably you will get ingredients.id in the id field also since it's latter.
So update your query to something like
SELECT recipe.id AS recipeid,
recipe.ingredientid,
ingredients.quantity,
ingredients.name
FROM recipe
INNER JOIN ingredients ON ingredients.id = recipe.ingredientid
and then use recipeid to get the recipe.id. This will always be better, since it's clear what id you are getting.

PHP left join not displaying results

I am trying to left join to tables in PHP. I am a total noob to left join and I can't figure out what I'm doing wrong!
$value=$_GET['value'];
$storeid=$_GET['store'];
$id=$_GET['id'];
$latitude=$_GET['lat'];
$longitude=$_GET['long'];
$result = mysqli_query($con,"SELECT carlist.id, carlist.vin, link_qr.qr, link_qr.vin
FROM link_qr, carlist LEFT JOIN link_qr.vin ON carlist.vin
WHERE qr="$value";");
while($row = mysqli_fetch_array($result)) {
echo $row['id'];
echo $row['vin'];
echo $row['qr'];
}
Here is the table structure
Table: link_qr
id------vin---------qr------webid---------other
Table: carlist
id---stknum---vin----vt----stat---other---store_id---web_code---qrcode
When all done I would like to have the following.
I would like to join the carlist and the link_qr where the vins are equal to each other and then I need it to return the carlist id where that vin is equal to qr.
Here are the errors I'm getting:
**Notice: Undefined index: store in /api/app_request/left_join.php on line 13
Notice: Undefined index: id in /api/app_request/left_join.php on line 14
Notice: Undefined index: lat in /api/app_request/left_join.php on line 15
Notice: Undefined index: long in /api/app_request/left_join.php on line 16
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in api/app_request/left_join.php on line 22**
There are a couple things to note:
First, your SQL query is incorrect:
SELECT carlist.id, carlist.vin, link_qr.qr, link_qr.vin
FROM carlist
LEFT JOIN linkqr ON linkqr.vin=carlist.vin
WHERE qr="$value";
Should be the correct format so long as those tables and columns exist. Secondly, however, you should not be querying a database with an unescaped value. This leads to SQL Injection. More appropriately you could write your query like:
$query = <<<SQL
SELECT carlist.id, carlist.vin, link_qr.qr, link_qr.vin
FROM carlist
LEFT JOIN linkqr ON linkqr.vin=carlist.vin
WHERE qr=?
SQL;
$stmt = mysqli_prepare($query);
mysqli_bind_param($stmt, "s", $value); // this sets the ? in the sql query to $value
mysqli_execute($stmt);
$result = mysqli_get_result($stmt);
while($row = mysqli_fetch_array($result)) {
echo $row['id'];
echo $row['vin'];
echo $row['qr'];
}
Why not do:
"SELECT C.PrimaryId, Field, AnotherField
FROM tablename AS C
LEFT JOIN tablename AS L ON C.matching_id = T.matching_id
WHERE tablename.fieldname = :fieldname
?

notice trying to get property of non-object

what is the error in this please help!
here is the query from mysql :
public function stgradu($condition=">=50"){
$stmt=$this->db->prepare("SELECT
courses_has_schedule.mark as mark,
Sum(courses.crs_hours) as total_hrs
FROM
courses_has_schedule
Inner Join courses ON courses_has_schedule.crs_id = courses.crs_id
Inner Join schedule ON schedule.sch_id = courses_has_schedule.sch_id
Inner Join student ON student.st_id = schedule.st_id
where
student.st_id=? AND courses_has_schedule.mark $condition");
$stmt->execute(array($this->getCurrentStudent(true)));
return $stmt->fetchAll();
}
when i run this if statement :
$stgr = $dataService->stgradu(">=50");
if(($stgr->total_hrs==7) AND ($stgradu->mark >= 50)) {
echo Yes*";
}else
echo "No";
when i run the app its gives me this error
(( Notice: Trying to get property of non-object in C:\xampp\htdocs\samer\stgr.php on line >12))
please help all!
fetchAll returns an array and you are trying to acces it like an object. Try this:
if(($stgr['total_hrs']==7) AND ($stgradu['mark'] >= 50)) {
You need to pass PDO::FETCH_OBJ to fetchAll() because it returns an associative array by default.
public function stgradu($condition=">=50"){
$stmt=$this->db->prepare("SELECT
courses_has_schedule.mark as mark,
Sum(courses.crs_hours) as total_hrs
FROM
courses_has_schedule
Inner Join courses ON courses_has_schedule.crs_id = courses.crs_id
Inner Join schedule ON schedule.sch_id = courses_has_schedule.sch_id
Inner Join student ON student.st_id = schedule.st_id
where
student.st_id=? AND courses_has_schedule.mark $condition");
$stmt->execute(array($this->getCurrentStudent(true)));
return $stmt->fetchAll(PDO::FETCH_OBJ);
}
If you are supposed to get only one row then change it to fetch(PDO::FETCH_OBJ) and your code should run fine.
thanx all.. i knew it by my self :P the syntax should be...
return $stmt->fetchAll()[0];

Categories