Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I would like to subtract one column of data from another, namely gdded from gppy; both are stored in a MySQL database.
Here is my code but it seems there is something wrong. I've searched anywhere but I cannot find the right answer.
My script below
INSERT INTO denmrk
(EMPID, NAME, DATE_FR, DATE_TO, Tangkay, Alis, gppy, gdded , NET_PAY, SSS_comboE, IBG_EMPLYE, PROCESSED_DATE)
VALUES
(6666, 'JUAN DELACRUZ', '2014-02-01 00:00:00', '2014-02-01 00:00:00', 'BBBB CO', 'DRIVER', 3383.04, 300, gppy- gdded , 150, 150, GETDATE() );
With the given code and implied database structure, how can I can achieve this?
BTW there is no need to store the manipulated result in the database. You can do this when you are select the data from the database. SO it would be better to drop that col and the idea to store the calc result in the database as well.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to Select one record from a table Named 'sms_students' by using Student Id or Student Telephone
Here is My Code
$student_rand_id=$_GET['std_rand'];
$std_tell=$_GET['std_tell'];
$view_student = $config->prepare("SELECT * FROM sms_students WHERE st_rand = :random_id || st_tel =: st_tel");
$view_student->execute(['random_id' => $student_rand_id]);
$view_student->execute(['st_tel' => $std_tell]);
$row = $view_student->fetch();
Since you call execute twice, this executes twice, both times with an incomplete set of arguments. It's an easy fix though:
$view_student = $config->prepare("SELECT * FROM sms_students WHERE st_rand = :random_id OR st_tel = :st_tel");
$view_student->execute(['random_id' => $_GET['std_rand'], 'st_tel' => $_GET['std_tell'] ]);
$row = $view_student->fetch();
Try and get rid of single-use variables, they're almost always unnecessary, and do try and steer towards having names that match precisely. Seeing st_tel and std_tell together is a sign something's not quite right. Get your code to agree on names and stick with them.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to update next table named 'book' but this UPDATE code is not working
"UPDATE books SET Quantity=Quantity-1 Where Book_ID='$Book_ID'";
this code should update the books table by decreasing the value of Quantity by 1
You need to decrease from column value, not PHP variable. Remove the dollar sign and quotes, of you have there integers.
UPDATE books SET Quantity = Quantity - 1 Where Book_ID = '$Book_ID'
Don't forget that you are vulnerable to SQL injection in WHERE clause.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am trying to use code from the following old question:
MySQL: Count occurrences of distinct values
My query is as follows:
$result = $db->query("SELECT name,COUNT(*) as cnt FROM `table` GROUP BY name ORDER BY cnt DESC");
$row = mysqli_fetch_array($result);
var_dump($row);
In phpmyadmin this code will output all the name and COUNT columns. When I run var_dump($row) it will only have one row for me to work with (the first one, ie the one with the most occurrences), which I can't figure out why. Any ideas? Thanks.
From the documentation on mysqli_fetch_array:
Fetch a result row as an associative, a numeric array, or both
As you found out, it does just that: it fetches a row.
Maybe you were expecting the behaviour of mysqli_fetch_all?
Fetches all result rows as an associative array, a numeric array, or both
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I want to write some Data in my MySQL database but it seems to not work.
All the variables are filled, tested it by echoing them. Now I want to insert them into my sip table but it just doesnt do it.
Where did I go wrong on this?
echo $a_dw.$a_name.$a_an.$a_pw."<br>";
$sql = "INSERT INTO sip VALUES ('".$a_dw."','".$a_name."', '".$a_an."', '".$a_pw."')";
mysql_query($sql);
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
You forgot the column names.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
SOLVED
Rows 1, 4, and 10 have a field with a single quote character in them, so I was SQL injecting myself. More reason to switch to prepared statements!
I have a very simple bulk UPDATE query sent from my PHP form which, oddly enough, only affects certain rows. Rows 1, 4, and 10 doesn't get updated; but all other rows get updated.
Here is the query:
$query = "SELECT * FROM SkillDescriptions";
$result = mysql_query($query);
for ($i=1; $i<=mysql_num_rows($result); $i++){
$skillKey = 'Skill' . (string)$i;
$categoryKey = 'Category' . (string)$i;
$descriptionKey = 'Description' . (string)$i;
$sql="UPDATE SkillDescriptions SET
Skill='$_POST[$skillKey]',
Category='$_POST[$categoryKey]',
Description='$_POST[$descriptionKey]'
WHERE id='$i'
";
$result2=mysql_query($sql);
}
I've got a parallel form that does the exact same PHP form processing as this one but has a different database table, which works properly: so the problem most likely lies in the database table (configuration?) and not the code.
Why do only certain rows get updated, in a seemingly random pattern?
UPDATE
Before:
http://i.stack.imgur.com/2hk2l.png
After: (I appended test to the columns)
http://i.stack.imgur.com/ObMn5.png