Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I am a code noob. I want to display a number from a mysql database based on the value of 2 dropdown boxes i.e
box a = 100
box b = 600
return value 36.50
box a= 40
box b= 100
return value 125.95
Please help with the php code.
I assume you are using MySQLi and not officially removed MySQL API.
Here is the Query:
$query = "SELECT price FROM database WHERE pallets = ? AND SKU = ?";
$stmt = $DB->prepare($query);
$stmt->bind_param("ii", $aValue, $bValue);
$stm->execute();
$stmt->get_result();
while($row = $stmt->fetch(MYSQL_ASSOC))
{
echo "This is the price: " . $row['price'];
}
Note that your php version should at least be 5.4 for the above code to work.
$aValue and $bValue are respectively the value of two dropBoxes.
"ii" means respectively that values are of integer type.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 2 years ago.
Improve this question
I'm a begginer to PHP and I want to know how can I fetch some text from the corresponding ID and store it as a variable in PHP.
The table is like
ID----NAME----ACCOUNT----PASSWORD
1----name1----accont1----password2
2----name2----accont2----password2
3----name3----accont3----password3
Now if I want to get the account2 as text and save it in an variable (say acc2) then what should I do. Assuming that I have connection information in connect.php.
Edit: I want to select the account2 using the ID like from ID 2 select account.
Thanks In Advance!!!
Assuming you use MySQL, the table is named users and you are using PDO, this would get what you need:
$stmt = $conn->query("SELECT * FROM users WHERE ID = 2");
$row = $stmt->fetch()
$account = $row['ACCOUNT']
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 3 years ago.
Improve this question
I have two tables in mysql db. The two tables are connected through a key :
five_day_general_information.days_dates_id = five_weekly_day_calander.id
SELECT
five_weekly_day_calander.Total_working_days
FROM five_day_general_information
INNER JOIN five_weekly_day_calander
ON five_day_general_information.days_dates_id = five_weekly_day_calander.id
WHERE five_day_general_information.Pro_id = 133;
enter image description here
AS YOU SEE IN THE PICTURE,
How can I add the 5 and 2 and return the results which is 7 so I can use that results in php
I think you just want aggregation:
SELECT SUM(fwdc.Total_working_days) as Total_working_days
FROM five_day_general_information fdgi JOIN
five_weekly_day_calander fwdc
ON fdgi.days_dates_id = fwd.id
WHERE fdgi.Pro_id = 133;
You can refer to the returned value as Total_working_days in the PHP result set.
Note that table aliases make the query easier to write and to read.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 6 years ago.
Improve this question
I have one table which need to find all date and put the name just once (this is workig = $sql), but i have problem to select the that name of data and count how much time is repeats in same table. So where is name Test(down) there needs to be count for how much time that name repeats in whole table.
If I put one more while function the table dies.
Im stacked. Im not very good with php and mysql. If someone can help.
$sql = "SELECT DISTINCT one,two FROM results";
$sql2 = "select test, count(*) as foo_count from results group by test;";
$result = mysqli_query($conn,$sql);
$result2 = mysqli_query($conn,$sql2);
<?php
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>".$row["one"]."</td><td>".$row["two"]."</td><td>";}?> Test</td></tr>
I'm having a little bit of a hard time following your question, but I think you are looking for a single sql statement like this
$sql = "select test, count(one) as foo_count from results group by test";
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 5 months ago.
Improve this question
I have this code
$SQL = "UPDATE cart SET a = ? WHERE b = ? AND c = ?";
if($stmt2 = mysqli_prepare($conn, $SQL )){
mysqli_stmt_bind_param($stmt2, "iii", $a1, $b1, $c1);
mysqli_stmt_execute($stmt2);
if(mysqli_affected_rows($conn)){
echo "updated";
mysqli_stmt_close($stmt2);
}
else
echo "nope";
}
I was figuring out why above code never work. I have debug every way that I know.
Lastly I delete the if condition. Somehow, it is working. Tried to browse on the internet to figure out what is the cause but did not find any. Can somebody please explain to me why does it happen so?
You should be using
mysqli_stmt_affected_rows($stmt2);
mysqli_stmt::$affected_rows -- mysqli_stmt_affected_rows — Returns the total number of rows changed, deleted, or inserted by the last executed statement
Instead of
mysqli_affected_rows($conn);
which is for plain query executions.
Manual
Edit
I just noticed that your question title mentions the right function name, and your code uses the wrong one.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I need to insert image row from table 'users2' to 'allbets'. But suddenlly this code don't working and I don't know why.. What is wrong with this?
$q2 = $pdo->prepare('INSERT INTO allbets (image) SELECT users2.image FROM users2 WHERE username = ?');
$q2->bindValue(1, $_SESSION['name']);
$q2 -> execute();
This code did not suddenly stop working, it never could have worked with its present query syntax. Change the query to this -
$q2 = $pdo -> prepare('INSERT INTO allbets (user, bet, komanda, teams, cof, data, image) VALUES ($user, $bet, $komanda, $teams, $cof, $data, (SELECT `users2`.`image` FROM `users2` WHERE `username` = ?));
Do yourself a service and error checking to your PHP code and to your PDO. This will let you know where to look when errors occur.