Estou tentando criar um sum
e apresentar em tela. Porém quase todos os exemplos que vejo usam a chamada do $conn
e no meu caso estou usando um arquivo que já traz a conexão com o banco e o select + query + row estão apresentando erro.
Segue o código:
<?php
require 'config.php';
?>
<?php
$gasto = "select sum(buy) from home"
$resultgasto = mysqli_query($gasto);
$resultGasto_query = mysqli_fetch_row($resultgasto);
?>
<html>
<head>
<title>Tabela poker</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
</head>
<body>
<table style="padding-top: 20px;height: 202px;width: 171px;" ID="tabelabk1" >
<tr>
<th>(%)</th>
<th>VALOR</th>
</tr>
<tr>
<td bgcolor="darkgreen">Gasto</td>
<?php <td bgcolor="#FF6347">.$$resultGasto_query['buy'].</td>?>
</tr>
<?php
require_once 'config.php';
?>
<?php
$gasto = "select sum(buy) as buy from home;";
$resultgasto = mysqli_query($pdo, $gasto);
$resultGasto_query = mysqli_fetch_assoc($resultgasto);
?>
<html>
<head>
<title>Tabela poker</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
</head>
<body>
<tr>
<td bgcolor="darkgreen">Gasto</td>
<td bgcolor="#FF6347"><?php echo $resultGasto_query['buy']; ?></td>
</tr>
<?php
$dsn = "mysql:dbname=poker;host=localhost";
$dbuser = "root";
$dbpass = "";
try {
$pdo = new PDO($dsn, $dbuser, $dbpass);
}
catch(PDOExeption $e) {
echo "falhou: ".$e->getMessage();
}
?>
( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, object given in C:\wamp\www\poker\home\index.php on line 7
Call Stack
# Time Memory Function Location
1 0.0003 135360 {main}( ) ...\index.php:0
2 0.0040 142680 mysqli_query ( ) ...\index.php:7
( ! ) Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\poker\home\index.php on line 8
Call Stack
# Time Memory Function Location
1 0.0003 135360 {main}( ) ...\index.php:0
2 0.0555 143080 mysqli_fetch_assoc ( ) ...\index.php:8
<?php
$sql = "SELECT * FROM home ORDER BY id_home";
$sql = $conexao->query($sql);
if($sql->rowCount() > 0) {
foreach ($sql->fetchAll() as $home) {
echo '<tr>';
echo '<td>'.$home['id_home'].'</td>';
echo '<td>'.$home['buy'].'</td>';
echo '<td>'.$home['premio'].'</td>';
echo '<td>'.$home['torneio'].'</td>';
echo '<td>'.$home['jogadores'].'</td>';
echo '<td>'.$home['saldo'].'</td>';
echo '<tr>';
}
}
<?php
require_once 'config.php';
?>
<?php
$gasto = "select sum(buy) as buy from home;";
$resultgasto = mysqli_query($pdo, $gasto);
$resultGasto_query = mysqli_fetch_assoc($resultgasto);
?>
<html>
<head>
<title>Tabela poker</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
</head>
<body>
<tr>
<td bgcolor="darkgreen">Gasto</td>
<td bgcolor="#FF6347"><?php echo $resultGasto_query['buy']; ?></td>
</tr>
<?php
$dsn = "mysql:dbname=poker;host=localhost";
$dbuser = "root";
$dbpass = "";
try {
$pdo = new PDO($dsn, $dbuser, $dbpass);
}
catch(PDOExeption $e) {
echo "falhou: ".$e->getMessage();
}
?>
( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, object given in C:\wamp\www\poker\home\index.php on line 7 Call Stack # Time Memory Function Location 1 0.0003 135360 {main}( ) ...\index.php:0 2 0.0040 142680 mysqli_query ( ) ...\index.php:7
( ! ) Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\poker\home\index.php on line 8 Call Stack # Time Memory Function Location 1 0.0003 135360 {main}( ) ...\index.php:0 2 0.0555 143080 mysqli_fetch_assoc ( ) ...\index.php:8
Fatal error: Call to undefined method mysqli_result::rowCount() in C:\wamp\www\poker\home\index.php on line 126 Call Stack
Time Memory Function Location
1 0.0002 135728 {main}( ) ...\index.php:0