Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Alguem me ajuda não estou conseguindo resolver...
Olha os erros:
Success: A proper connection to MySQL was made! The my_db database is great. Host information: localhost via TCP/IP
Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\ranking.php on line 17
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\ranking.php on line 18
Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\ranking.php on line 104
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\ranking.php on line 105
Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\ranking.php on line 111
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\ranking.php on line 112
Notice: Undefined variable: tp in C:\xampp\htdocs\ranking.php on line 276
Warning: mysqli_close(): Couldn't fetch mysqli in C:\xampp\htdocs\ranking.php on line 284
Code da config.php:
<?php
ob_start();
session_start();
$conn = mysqli_connect("localhost", "root", "000", "novadb") or die(mysqli_error());
// Check connection
if (!$conn) {
die("Connection failed: " . mysql_connect_error());
//die("conexão falhou.");
}
if (!$conn) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($conn) . PHP_EOL;
mysqli_close($conn);
?>
Página do ranking.php
<?php
include "config.php";
//echo $_SESSION['id_usuario'] . "<br>";
//echo $_SESSION['usuario'];
/*
if ($_SESSION['usuario'] == "")
{
echo "É necessário realizar o login. Clique <a href='login.php'>aqui</a> e faça o login.";
exit;
}
*/
//echo $_SESSION['usuario'];
$id_marca = isset( $_GET["id"] );
$sql = mysqli_query($conn,"select * from tb_marca where id = '$id_marca'");
$rec = mysqli_fetch_array($sql);
$id_categoria = $rec["id_categoria"];
$total_reg = "100"; // número de registros por página
$pagina= isset($_GET['pagina']);
if ($pagina == 1)
{
$pagina= $_GET['pagina'];
}
if (!$pagina)
{
$pc = "1";
}
else
{
$pc = $pagina;
}
$inicio = $pc - 1;
$inicio = $inicio * $total_reg;
//echo $_SESSION['usuario'];
?>
<?php include 'layout/metas.php';?>
<?php include 'layout/config_layout.php';?>
<title><?PHP echo "" . $titleindex[0] . " - " . $title[0] . "" ?></title>
<meta name="description" content="<?PHP echo $descriptionindex; ?>" />
<?php include 'layout/header.php';?>
<?php include 'layout/logo.php';?>
<div class="content">
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td>
Selecione a Categoria:
</td>
<td>
<select name="cmbcategoria" class="form-control" id="cmbcategoria" onchange="CarregaCidades(this.value)">
<option value="">Selecione</option>
<?php
$sql = mysqli_query($conn,"SELECT * FROM tb_categoria order by categoria");
while($linha = mysqli_fetch_object($sql))
{
$id = $linha->Id;
$categoria = $linha->categoria;
?>
<option value="<?php echo $id;?>" <?php if ($id == $id_categoria) { echo "SELECTED"; } else { echo ""; }; ?>><?php echo $categoria;?></option>
<?php
}
//mysql_free_result( $resposta );
//mysql_close($conexao);
?>
</select>
</td>
</tr>
</table>
<br>
<div id="cidadeAjax">
<table border="0" class="table table-striped" cellpadding="3" cellspacing="3" width="100%">
<tr>
<td>
<b>#</b>
</td>
<td>
<b>Marca</b>
</td>
<td>
<b>Avaliação</b>
</td>
<td>
<b>Comentários</b>
</td>
</tr>
<?php
$sql = mysqli_query($conn,"select count(1) as total_coment, b.id_marca, a.marca, sum(b.avaliacao) as total, a.id_categoria
from tb_marca a, tb_comentario b where a.id = b.id_marca
group by b.id_marca, a.marca order by count(1) desc ");
$num_rows = mysqli_num_rows($sql);
//echo $num_rows;
if ($num_rows == 0)
{
$quer = mysqli_query($conn,"select a.Id, a.id_categoria, a.marca from tb_marca a, tb_categoria b where a.id_categoria = b.id and a.id_categoria = $id_categoria");
$rec1 = mysqli_fetch_array($quer);
$id_marca = $rec1["Id"];
$id_categoria = $rec1["id_categoria"];
$marca = $rec1["marca"];
$total_coment = "0";
$total_comentarios = "0";
?>
<tr onclick="location.href = 'marca.php?id_marca=<?php echo $id_marca;?>';" style="cursor:pointer;">
<td>
<?php echo "1";?>
</td>
<td>
<?php echo $marca;?>
</td>
<td>
<img src="layout/images/star_16x16.png">
<img src="layout/images/star_16x16.png">
<img src="layout/images/star_16x16.png">
<img src="layout/images/star_16x16.png">
<img src="layout/images/star_16x16.png">
</td>
<td>
<?php echo "0 comentário(s)"; ?>
</td>
</tr>
<?php
}
else
{
$j = 1;
/*$sql = mysqli_query($conn,"select count(1) as total_coment, b.id_marca, a.marca, sum(b.avaliacao) as total, a.id_categoria
from tb_marca a, tb_comentario b where a.id = b.id_marca
group by b.id_marca, a.marca order by count(1) desc LIMIT $inicio, $quantidade ");*/
$busca = "select count(1) as total_coment, b.id_marca, a.marca, sum(b.avaliacao) as total, a.id_categoria
from tb_marca a, tb_comentario b where a.id = b.id_marca
group by b.id_marca, a.marca order by count(1) desc";
$limite = mysqli_query($conn,"$busca LIMIT $inicio,$total_reg");
$todos = mysqli_query($conn,"$busca");
$tr = mysqli_num_rows($todos); // verifica o número total de registros
$tp = $tr / $total_reg; // verifica o número total de páginas
/*$sql = mysqli_query($conn,"select count(1) as total_coment, b.id_marca, a.marca, sum(b.avaliacao) as total, a.id_categoria
from tb_marca a, tb_comentario b where a.id = b.id_marca
group by b.id_marca, a.marca order by count(1) desc ");*/
//$limite = mysqli_query("$sql LIMIT $inicio,$total_reg");
//$todos = mysqli_query("$sql");
//$tr = mysqli_num_rows($todos); // verifica o número total de registros
//$tp = $tr / $total_reg; // verifica o número total de páginas
while($rec = mysqli_fetch_object($limite))
{
$id_marca = $rec->id_marca;
$id_categoria = $rec->id_categoria;
$marca = $rec->marca;
$total_coment = $rec->total_coment;
$total_comentarios = $rec->total_coment;
//traz avaliação
/*
$query = mysqli_query($conn,"select id_marca FROM tb_comentario where id_marca = $id_marca order by avaliacao desc");
$objRS = mysqli_fetch_array($query);
$cod_marca = $objRS["id_marca"];
echo $cod_marca;
*/
$sql_ = mysqli_query($conn,"select sum(avaliacao) as total FROM tb_comentario where id_marca = $id_marca");
$aval = mysqli_fetch_array($sql_);
$total = $aval["total"];
//$total = $total/2;
//echo $total_coment . " - " . $id_marca . "<br>";
//$sqlco = mysqli_query($conn,"select count(1) as total_coment from tb_comentario where id_marca = $id_marca");
//$obj = mysqli_fetch_array($sqlco);
//$total_coment = $obj["total_coment"];
?>
<tr onclick="location.href = 'marca.php?id_marca=<?php echo $id_marca;?>';" style="cursor:pointer;">
<td>
<?php echo $j;?>
</td>
<td>
<?php echo $marca;?>
</td>
<td>
<?php
if ($total_coment >= 5)
{
for ($i=1;$i<=5;$i++)
{
echo '<img src="layout/images/star1_16x16.png"> ';
}
}
elseif ($total_coment >=3 && $total_coment <5)
{
for ($i=1;$i<=$total_coment;$i++)
{
echo '<img src="layout/images/star1_16x16.png"> ';
}
for ($total_coment;$total_coment<5;$total_coment++)
{
echo '<img src="layout/images/star_16x16.png"> ';
}
}
elseif ($total_coment <=2)
{
for ($i=1;$i<=$total_coment;$i++)
{
echo '<img src="layout/images/star1_16x16.png"> ';
}
for ($total_coment;$total_coment<5;$total_coment++)
{
echo '<img src="layout/images/star_16x16.png"> ';
}
}
else
{
echo '<img src="layout/images/star_16x16.png"> ';
}
?>
</td>
<td>
<?php echo $total_comentarios . " comentários"; ?>
</td>
</tr>
<?php
$j = $j + 1;
}
}
?>
</table>
<br>
<?php
// agora vamos criar os botões "Anterior e próximo"
$anterior = $pc -1;
$proximo = $pc +1;
if ($pc>1) {
echo " <a href='?pagina=$anterior'><- Anterior</a> ";
}
echo "|";
if ($pc<$tp) {
echo " <a href='?pagina=$proximo'>Próxima -></a>";
}
?>
</div>
</div>
<?php include 'layout/footer.php';?>
<?php mysqli_close($conn);?>
<script language="javascript">
function CarregaCidades(codEstado)
{
//alert(codEstado);
if(codEstado){
var myAjax = new Ajax.Updater('cidadeAjax','lista_ranking.php?codEstado='+codEstado,
{
method : 'get',
}) ;
}
}
</script>Carregando comentários...