Check checkbox with column from table - checkbox

Can anyone show me, what i'm doing wrong?
I using c_id from company to give checkbox a value for later use.
I using name from company to write the name of the company next to the checkbox.
I using c_id from artistscompany to print "checked" in the checkboxes, where c_id from artistscompany are equal to c_id from artists.
$slsql = 'SELECT * FROM artistscompany WHERE a_id='.$ad_id;
$blsql = 'SELECT c_id, name FROM company WHERE c_id > 1';
if (($bl_result = mysqli_query($dbh, $blsql))AND($sl_result = mysqli_query($dbh, $slsql))) {
while($bl_row = mysqli_fetch_assoc($bl_result)){
$sl_raekke = mysqli_fetch_assoc($sl_result);
foreach((array)$sl_raekke as $sl_row){}
echo '<input type="checkbox" name="belongs[]" value="'.$bl_row['c_id'].'"'; if($sl_row == $bl_row['c_id']){echo'checked';}ELSE{echo'';} echo'> '.$bl_row['name'].'<br />';
}
mysqli_free_result($bl_result);
mysqli_free_result($sl_result);
}

$query = 'SELECT * FROM artistscompany a, company c WHERE c.c_id > 1 AND
c.c_id=a.c_id AND a_id='.$ad_id;
Now use this query to fetch and display from db.
a and c are used to refer to the fields. You want the c_id > 1 from company table, a_id=$variable and the same company ID in both tables. Correct me if I am wrong.

Related

What tables hold the job category class and types?

In SQL Server.
In the table msdb.dbo.syscategories how do I get the value for the ids category_class and category_type name
i.e: class 1 = JOB
type 1 = LOCAL
You get it from the docs:
Column name
Data type
Description
category_id
int
ID of the category
category_class
int
Type of item in the category:
1 = Job
2 = Alert
3 = Operator
category_type
tinyint
Type of category:
1 = Local
2 = Multiserver
3 = None
name
sysname
Name of the category
The system catalog views typically don't have "lookup tables" for each of these.

Select specific columns with repository in Entity Framework Core

I have a big table with a binary column for picture. I need to show contents of this table in a view and make it searchable. I have tried only selecting a subset of columns that are needed in this. However, the generated SQL always has all the columns of the table in the generated query.
public IQueryable<ApplicantDTO> GetApplicantQueryable()
{
return DataContext.Applicants
.Include(a => a.Nationality)
.Select(x => new ApplicantDTO
{
Id = x.Id,
BirthDate = x.BirthDate,
Gender = x.Gender,
FirstName = x.FirstName,
LastName = x.LastName,
OtherName = x.OtherName,
MobileNo = x.MobileNo,
Age = x.Age,
Nationality = x.Nationality.National,
Admitted = x.admitted,
Completed = x.Completed
})
.Where(a => a.Admitted == false && a.Completed == true)
.OrderBy(a => a.LastName)
.AsNoTracking();
}
But instead of just specifying the above rows, the generated SQL from profiler is
SELECT
[a].[Id], [a].[BirthDate], [a].[BirthPlace], [a].[CompleteDate],
[a].[Completed], [a].[ContentType], [a].[CreateDate],
[a].[Denomination], [a].[Disability], [a].[Email],
[a].[FirstName], [a].[Gender], [a].[HomeTown], [a].[LastName],
[a].[MarryStatus], [a].[MatureApp], [a].[MobileNo], [a].[NationalityID],
[a].[OtherName], [a].[Passport], [a].[Pin], [a].[PostalAddress],
[a].[Region], [a].[Religion], [a].[ResAddress], [a].[SerialNo],
[a].[Title], [a].[VoucherID], [a].[admitted], [a.Nationality].[National]
FROM
[Applicants] AS [a]
INNER JOIN
[Nationality] AS [a.Nationality] ON [a].[NationalityID] = [a.Nationality].[Id]
WHERE
([a].[admitted] = 0)
AND ([a].[Completed] = 1)
ORDER BY
[a].[LastName]
With all the underlying columns all included in the query.
I tried putting it in an anonymous type before casting it to the ApplicantDTO but still the same effect.
What's wrong?

Need help for a query

my current query is:
public function teachers_manage() {
$this->db->select('users.user_id, teacher_id, COUNT(student_id) AS S, COUNT(DISTINCT(users.class)) AS C, schools.region, schools.school_name');
$this->db->from('teacher_student_conn');
$this->db->join('users', 'teacher_student_conn.student_id=users.user_id','left');
$this->db->join('schools', 'schools.school_id=users.school_id');
$this->db->where('users.deactivated_at = "0000-00-00 00:00:00" OR users.deactivated_at IS NULL ');
$this->db->where('users.role_id', '1');
$this->db->group_by("teacher_student_conn.teacher_id");
$result=$this->db->get();
return $result->result();
}
It shows me teachers and for each teacher number of classes he teaches and number of students he teaches. I have made join 2 tables - users and teacher_student_conn by users=user_id=teacher_student_conn.student_id and I've put where clause for student not to be deactivated - shows active students. But how to do that also fot the teachers? Another join will change the results. I only want to add where clause for teachers to be active.
My tables look like this:
users
user_id
school_id
class
role_id
created_at
deactivated_at
teacher-student_conn
id
teacher_id
student_id
created_at
I suggest to add a column for "status" to more easily distinguish the status of student and teacher.
And this is my recommended query
SQL Query:
select
from users a
join teacher-student_conn b on a.user_id = b.student_id
join schools c on c.school_id = a.school_id
where (a.status = "Deactivated") and (b.status = "Deactivated")
For codeigniter:
$this->db->select('a.user_id, b.teacher_id, COUNT(b.student_id) AS S, COUNT(DISTINCT(a.class)) AS C, c.region, c.school_name');
$this->db->join('teacher_student_conn b', 'b.student_id = a.user_id','left');
$this->db->join('schools c', 'c.school_id = a.school_id');
$this->db->where('a.status = "Deactivated" or b.status = "Deactivated" ');
$this->db->where('a.role_id', '1');
$this->db->group_by("b.teacher_id");
$result=$this->db->get("users a");
return $result->result();

Add value into database plus 1

In my database I have:
Row ID - Driver ID - Log ID.
Row ID is unique and auto-increments. What I want is for the Log ID to be unique for each row that has that Driver ID.
For example say a row is inserted with Driver ID 1 I want that row to have a Log ID of 1 but the next time a row is inserted with Driver ID 1 I want it to have a Log ID of 2.
How can I achieve this?
By way for database i am using PHPMyAdmin.
----------------Edit----------------------
This is what i have in my PHP now, but it says:
On the webpage: Incorrect integer value: '' for column 'FinesCost' at row 1
And i dump the variables and get this: string(2) "16" string(2) "16" string(2) "16" so i dont understand why it is saying incorrect integer value and why it is saying they are undefines because they are very clearly defined.
In the PHP error log: [19-Jul-2013 10:44:18 Europe/Minsk] PHP Notice: Undefined variable: FinesCostP‌ost2 in C:\inetpub\wwwroot\hosting\Dan\JWT\drivers-log-send.php on line 336
[19-Jul-2013 10:44:18 Europe/Minsk] PHP Notice: Undefined variable: TravelExpensesPo‌​st2 in C:\inetpub\wwwroot\hosting\Dan\JWT\drivers-log-send.php on line 336
///PHP TO INSERT DRIVER'S BANK DETAILS INTO BANK DATABASE
session_start();
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="jwtdriversbank"; // Table name
$un = "";
$usrname = "";
$usrpass = "";
$userID = "";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if(isset ($_SESSION['usrName']))
{
$usrname = $_SESSION['usrName'];
}
else
{
echo "4";
}
//var_dump ($usrname);
if(isset ($_SESSION['usrPass']))
{
$usrpass = $_SESSION['usrPass'];
}
else
{
echo "5";
}
$sql="SELECT * FROM jwtdrivers WHERE username='$usrname' and password='$usrpass'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$userID = $rows['id'];
//var_dump ($userID);
if($userID == "")
{
echo "3";
}
else
{
$TotalProfitPost = $TotalProfit;
$LateFeePost = $LateFee;
$FinesCostPost2 = $FinesCost;
$TravelExpensesPost2 = $TravelExpenses;
$FuelCostPost = $FuelCost;
$CargoDamagePost = $CargoDamage;
$TruckDamagePost = $TruckDamage;
var_dump ($TotalProfitPost);
var_dump($FinesCostPost2);
var_dump($TravelExpensesPost2);
$sql="INSERT INTO jwtdriversbank2 (DriverID, LogID, TotalProfit, LateFee, FinesCost, TravelExpenses, FuelCost, CargoDamage, TruckDamage) VALUES ('$userID', COALESCE((Select MAX(LogID) from jwtdriversbank2 tab2 where tab2.DriverID = '$userID'),0)+1,'$TotalProfitPost','$LateFeePost', '$FinesCostP‌ost2' , '$TravelExpensesPo‌​st2' ,'$FuelCostPost','$CargoDamagePost','$TruckDamagePost')";
$result = mysql_query($sql);
if($result)
{
}
else
{
die(mysql_error());
}
}
Add a primary key for the two columns.
It should do the trick.
Look at this link for help
ALTER TABLE table_name
ADD CONSTRAINT pk_DriverID PRIMARY KEY (DriverID,LogID)
Do not forget to drop the first primary key because you will not need it no more.
EDIT : COMPLETE WITH THE OTHER ANSWER
Here is the code to insert your data.
Insert into <table_name>
values p_RowID, p_DriverID, COALESCE((Select MAX(Log_id) from <table_name> tab2 where tab2.Driver_id = p_DriverID),0)+1;
That should close the question.
You did not defined variable because PHP can't read them.
I opened your program inside VIM editor and I found "<200c>" char inside $FineCostPost2 in the SQL query. You have to change it to make it work.
A quick solution would be to use a subquery to find the maximum log (last log id) then increment it, something like this
Insert into <table_name>
values p_RowID, p_DriverID, COALESCE((Select MAX(Log_id) from <table_name> tab2 where tab2.Driver_id = p_DriverID),0)+1;
Here p_RowID and p_DriverID are the values you pass to insert into your table. The Coalesce function would check the given value and if it is NULL then it would replace it with the second parameter, in this case 0

How can I add text to my column's select statement

I want to prepend text to sql select,
I can do this:
SELECT (1328724983-time)/60/60 AS status
FROM voting
WHERE account = 'ThElitEyeS' AND vid = 1
This will show time left.
What I'd like to do is this though:
SELECT 'Please try after' + (1328724983-time)/60/60 AS status
FROM voting
WHERE account = 'ThElitEyeS' AND vid = 1
Is there any way I can accomplish this?
Just use cast or convert to convert it all to varchar for instance.
SELECT 'Please try after' + CAST((1328724983-time)/60/60 as varchar(80)) AS status
FROM voting
WHERE account = 'ThElitEyeS' AND vid = 1;
See the MSDN on Cast / Convert
Based on your comments you can do:
SELECT 'Please try again after' + CAST(MyColForHours as varchar(25)) + ' hours', AnyOtherColumns FROM Table
Was trying this today and getting an error
SQL0420N Invalid character found in a character string argument of the function "DECFLOAT". SQLSTATE=22018
Apparently we now need to use || instead of + to join the sections.
http://www-01.ibm.com/support/docview.wss?uid=swg21448700

Resources