Cannot show out results with SUM operator in PHP [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
may I ask for help? I cannot show out the result. If I run the code without the SUM operator, it works properly. Please help, thank you very much.
$sql1 ="SELECT SUM(SeatAmount) FROM reservation
WHERE RsvDate BETWEEN '07/01/2013' AND '07/31/2013'";
$result1 = $con->query($sql1);
printf('<td>');
printf('<b>Seat Amount</b><br/>');
while ($row1 = $result1->fetch_object())
{
printf('
%d<br/>',$row1->SeatAmount);
}

In order for that to work, you'd need an alias:
SELECT SUM(SeatAmount) AS SeatAmount

what is $row1's structure?
You can specify what the sum should be returned as like:
SELECT SUM(SeatAmount) AS SeatAmount

$sql1 ="SELECT SUM(SeatAmount) AS Total FROM reservation
WHERE RsvDate BETWEEN '07/01/2013' AND '07/31/2013'";
$result1 = $con->query($sql1);
printf('<td>');
printf('<b>Seat Amount</b><br/>');
while ($row1 = $result1->fetch_object())
{
printf('
%d<br/>',$row1->Total);
}

Related

Assign empty string to php variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Just need help fixing this php code
if ($cmtx_set_name_value == "anonymous")
{
$cmtx_set_name_value = ""
}
thanks
Try adding ; after the assignment.
$cmtx_set_name_value = "";
your code is work fine just put ; to end of line
if ($cmtx_set_name_value == "anonymous"){
$cmtx_set_name_value = "" ; }

i need Apostrophe in a variable result MYSQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I receive data in this format like:
C00001,C00302,C00303,C00287,C00286,C00285,C00017
in a variable but i need in this shape:
'C00001','C00302','C00303','C00287','C00286','C00285','C00017'
i am new in mysql kindly any help
You can explode the data, modify it, then re-implode it.
$data = 'C00001,C00302,C00303,C00287,C00286,C00285,C00017';
$arr = explode(',', $data);
$new_arr = array_map(function($a){
return "'{$a}'";
}, $arr);
$new_data = implode(',', $new_arr);

PHP fetch data from mysql and put it in <select> [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can anyone please tell me , how to fetch names from mysql through php and then put all those names in hmtl select tag for user to choose one name
use a foreach
echo "<select name='username'>";
while($row=mysql_fetch_array($r))
{
$user=array( $row['fieldname']);
foreach($user as $val)
{
echo "<option value='\$val\'>".$val."</option>";
}
}
echo "</select>";
Hope this helps
Check here.
Hints are
// sql connection here
$query="SELECT * FROM emp";
$result=mysql_query($query);
while($r=mysql_fetch_array($result)
{
echo $r[0];
// all the row that u want to fetch
}
Use PDO. It let's you access the data from SQL which you can then output in a select.

What's wrong with this query? Syntax error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What's wrong with this? It returns "You have an error in your syntax... ...check if you have the right MySQL version to use near 'to, content, link) VALUES..."
$notito = $idoftheguy;
$contentofnoti = $username." just posted a comment on your update.";
$linkofnoti = "http://mywebsite.net/post.php?id=".$thepostid;
/* Now let's insert this */
$insertnoti = mysql_query("INSERT INTO newnotifications (to, content, link) VALUES ('$notito', '$contentofnoti', '$linkofnoti')");
All of the above things in the query are existent in the database. And here are the exact inputs that gave the error (haven't tried any other inputs):
$notito = 1;
$contentofnoti = "Schart just posted a comment on your update.";
$linkofnoti = "http://mywebsite.net/post.php?id=22";
As already mentioned. to is a reserverd word. Try this code:
$insertnoti = mysql_query("INSERT INTO newnotifications (`to`, `content`, `link`) VALUES ('$notito', '$contentofnoti', '$linkofnoti')");

how to find the count of letter 't' in the below paragraph mentioned using php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$a='Would you like to have responses to your questions sent to you via email'
for($a as $b=>c){
}
Kindly give me the solution
<?php echo substr_count($a, 't'); ?>
Here's a solution, though not necessarily the best
$letterCount = array_count_values(
str_split(strtolower($a))
);
$tCount = (isset($letterCount['t'])) ? $letterCount['t'] : 0;
$count = preg_match_all('/t/', $str);
check this one
<?php
$a = 'Would you like to have responses to your questions sent to you via email';
$t_explod = explode('t', strtolower($a));
echo count($t_explod) - 1;
?>

Categories