how can i print the mySQL sum() 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
I have this query and i am asking if i can print the result in PHP without saving the result in other table.
SELECT SUM(weekly_fees) FROM scout_cabs

You start by giving it an alias to output:
SELECT SUM(`weekly_fees`) AS `total` FROM `scout_cabs`
Then you parse it as any normal request via mysql.
<?php
$sql = "SELECT SUM(`weekly_fees`) AS `total` FROM `scout_cabs`";
$run = mysql_query($sql);
$result = mysql_fetch_assoc($run);
echo 'The sum of the query is: ' . number_format($result['total']);
It may also be worth looking into mysqli_ if you are not already using it, as mysql_ is now deprecated.

Related

How to echo value from a column using PHP? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I am new to PHP and having problems with printing values from database.
This is my code:
<?
$level = $db->Query("SELECT `level` FROM users WHERE `id` = '" . $data['id'] . "'");
$r2 = mysql_fetch_object($level);
?>
And this is what it looks like when I try to print it:
<?php
echo $r2;
?>
And when I try to echo it it doesn't print the value from level but it only loads half of the page.
I would really appreciate if someone could tell me what the problem is?
$level is a mysql result resource. Try adding the following
while ($row = $level->fetch_row()) {
var_dump($row);
}
The query is returning a result resource. You need to use that with a fetch function of some kind to retrieve the actual data. If you're using MySQLi, then you can use mysqli_fetch_row() or similar.

How to know the stored procedure parameters in 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
I want to populate my MSSQL database, so, I will run some procedures with random data. I have to get the parameters of every SP. How I can do that?
Thanks.
You can find it with simple query -
SELECT p.name
FROM sys.objects o
INNER JOIN sys.parameters p ON p.[object_id] = o.[object_id]
WHERE o.[name] = 'stored_proc_name' AND o.[type] = 'P'

sort data in alphabetical order 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
I get the data from database and I want to sort hotel_name in alphabetical order. How can I do it using php's sort function or any other method ?
foreach($selData as $row)
{
$name=$row['hotel_name'];
$distance_colombo=$row['distance_colombo'];
$distance_airport=$row['distance_airport'];
$description=$row['description'];
$activities=$row['activities'];
$str=(explode(',',$activities));
print_r($str);
}
There's no need to use sort() here. Just use ORDER BY in your SQL query.
Example:
SELECT * FROM table_name ORDER BY hotel_name

select query for date between [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 am doing a project where i have to fetch data of between dates plus the name of user.
The query for only date betweenis working fine but with and operater its going in wrong way so please suggest me how to implement it to achieve desired output.
this is my code:
$qry11=mysqli_query($con,"select * from entry where (create_date between '$first' and '$second') && cnor='$nme'");
so please suggest ne how to do this....any idea will be appreciate with highly gratitude.
&&
should be replaced with
AND
You seem to be already using AND in your query right
(create_date between '$first' and '$second')
use the query like below
$qry11=mysqli_query($con,"select * from entry where (create_date between '$first' and '$second') and cnor='$nme'");

Use this php code wih WHERE [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 I use this php code wih WHERE? SELECT SUM(buzz) as buzz FROM $table I want to calculate sumation of some spesific rows.
If you want specifically in PHP then this might help you
SELECT SUM(buzz) as buzz FROM $table WHERE $where
No, you can't use PHP code in an SQL where condition. Databases typically don't include a PHP interpreter.
What you can do is use PHP to generate the where clause that you need.

Categories