Ir para conteúdo
Fórum Script Brasil
  • 0

Pesquisa banco de dados


ehcampos

Pergunta

Tenho 2 tabelas(characters e character_reco_bonus), quero fazer uma pesquisa aonde eu pqgue oos dados rec/id da character_reco_bonus, e os nomes referentes aos id na tabela characters .

E na hora de colocar na tela coloque em orde DESC o campo rec.

<?
Include ('../../Configuration/Config.php');
$sql = mysql_query("SELECT * FROM characters where ".$acesso2." <= 1 ") or die(mysql_error());
$i = 1;
while($a = mysql_fetch_object($sql)) {
    $b = mysql_query("SELECT * FROM character_reco_bonus where ".$a->charId." = charId ORDER BY rec_have DESC LIMIT 10" );
    $c = mysql_fetch_object($b);


?>
<table>
<tr>
<td><?php echo $a->charId; ?></td>
<td><?php echo $a->char_name; ?></td>
<td><?php echo $c->rec_have; ?></td>
</tr>
</table>
<?
$i++;
}
?>

So marinheiro de primeira viagem, concegui chegar ate ao, mas não concigo colocar os dados em orden decrescente.

Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0
Tenho 2 tabelas(characters e character_reco_bonus), quero fazer uma pesquisa aonde eu pqgue oos dados rec/id da character_reco_bonus, e os nomes referentes aos id na tabela characters .

E na hora de colocar na tela coloque em orde DESC o campo rec.

<?
Include ('../../Configuration/Config.php');
$sql = mysql_query("SELECT * FROM characters where ".$acesso2." <= 1 ") or die(mysql_error());
$i = 1;
while($a = mysql_fetch_object($sql)) {
    $b = mysql_query("SELECT * FROM character_reco_bonus where ".$a->charId." = charId ORDER BY rec_have DESC LIMIT 10" );
    $c = mysql_fetch_object($b);


?>
<table>
<tr>
<td><?php echo $a->charId; ?></td>
<td><?php echo $a->char_name; ?></td>
<td><?php echo $c->rec_have; ?></td>
</tr>
</table>
<?
$i++;
}
?>
So marinheiro de primeira viagem, concegui chegar ate ao, mas não concigo colocar os dados em orden decrescente.
Tenta alguma coisa mais ou menos assim:
$query = "SELECT crb.charId, crb.rec_have, c.char_name FROM character_reco_bonus as crb INNER JOIN characters as c WHERE crb.charId = c.charId AND c.charId = '".$a->charId."' ORDER BY crb.rec_have DESC LIMIT 10";
$result = mysql_query($query) or die('Erro:'.mysql_error());
while ($row = mysql_fetch_object($result)) {
    // resto do seu cógido.
}

Adotando o fato da tabela 'characters' ter um campo charId.

Link para o comentário
Compartilhar em outros sites

  • 0
Adotando o fato da tabela 'characters' ter um campo charId.

Sim as duas tem.

Bom o código fico assim.

<?
Include ('../../Configuration/Config.php');
$query = "SELECT crb.charId, crb.rec_have, c.char_name FROM character_reco_bonus as crb INNER JOIN characters as c WHERE crb.charId = c.charId AND c.charId = '".$a->charId."' ORDER BY crb.rec_have DESC LIMIT 10";
$result = mysql_query($query) or die('Erro:'.mysql_error());
while ($row = mysql_fetch_object($result)) {
    $b = mysql_query("SELECT * FROM character_reco_bonus where ".$a->charId." = charId ORDER BY rec_have DESC LIMIT 10" );
    $c = mysql_fetch_object($b);


?>
<table>
<tr>
<td><?php echo $a->charId; ?></td>
<td><?php echo $a->char_name; ?></td>
<td><?php echo $c->rec_have; ?></td>
</tr>
</table>
<?
$i++;
}
?>

Esta correto?

Ele não deu erro nem uma mas não carrego nem um dado na tela.

Editado por ehcampos
Link para o comentário
Compartilhar em outros sites

  • 0
Adotando o fato da tabela 'characters' ter um campo charId.

Sim as duas tem.

Bom o código fico assim.

<?
Include ('../../Configuration/Config.php');
$query = "SELECT crb.charId, crb.rec_have, c.char_name FROM character_reco_bonus as crb INNER JOIN characters as c WHERE crb.charId = c.charId AND c.charId = '".$a->charId."' ORDER BY crb.rec_have DESC LIMIT 10";
$result = mysql_query($query) or die('Erro:'.mysql_error());
while ($row = mysql_fetch_object($result)) {
    $b = mysql_query("SELECT * FROM character_reco_bonus where ".$a->charId." = charId ORDER BY rec_have DESC LIMIT 10" );
    $c = mysql_fetch_object($b);


?>
<table>
<tr>
<td><?php echo $a->charId; ?></td>
<td><?php echo $a->char_name; ?></td>
<td><?php echo $c->rec_have; ?></td>
</tr>
</table>
<?
$i++;
}
?>
Esta correto? Ele não deu erro nem uma mas não carrego nem um dado na tela.
Hehehe porque ta tudo erado =P. Tenta esse:
<?
Include ('../../Configuration/Config.php');
$query = "SELECT crb.charId, crb.rec_have, c.char_name FROM character_reco_bonus as crb INNER JOIN characters as c WHERE crb.charId = c.charId AND c.charId = '".$a->charId."' ORDER BY crb.rec_have DESC LIMIT 10";
$result = mysql_query($query) or die('Erro:'.mysql_error());
while ($row = mysql_fetch_array($result)) {
?>
    <table>
        <tr>
            <td><?php echo $row['charId']; ?></td>
            <td><?php echo $row['char_name']; ?></td>
            <td><?php echo $row['rec_have']; ?></td>
        </tr>
    </table>
<?
}
?>

Link para o comentário
Compartilhar em outros sites

  • 0

Não era bem o que queria mas concegui alguma coisa.

<html>
<head>
<script>
function click() {
if (event.button==2||event.button==3) {
oncontextmenu='return false';
}
}
document.onmousedown=click
document.oncontextmenu = new Function("return false;")
</script>
<title></title>
<style type="text/css">
<!--
.style1 {
    font-size: 22px;
    color: #0099CC;
}
#top {
    color:#CCCCCC;
    height:25px;
    line-height:25px;
    background:#333333;}
    
#sub {
    height:25px;
    line-height:25px;
    font-size:11px;}
#cont {
    list-style:none;
    }
-->
</style>
<body>
<div>
<?
Include ('../../Configuration/Config.php');

$sql = mysql_query("SELECT * FROM character_reco_bonus ORDER BY rec_have DESC LIMIT 10") or die(mysql_error());

?>
<table width="100%" align="center">
  <tr id="top">
    <td width="10%">#</td>
    <td width="35%">Nome do Char </td>
    <td width="21%">Recomend</td>
    <td width="36%">Clan</td>
  </tr>
<?
$i = 1;
$cor = 0;
while($a = mysql_fetch_object($sql)) {
    $b = mysql_query("SELECT * FROM characters WHERE charId = '".$a->charId."'")  or die(mysql_error());
    $c = mysql_fetch_object($b);
$cor = $cor + 1;
$bg  = $cor % 2 == 0 ? '#F1F1F1' : '#E8E8E8';
$contando = $contando+1;

if($i == 1) {
$img = "<img class='img' src='Pages/Ranking/$contando.png' alt=\"1&ordm; Lugar\">";
}elseif($i == 2) {
$img = "<img class='img' src='Pages/Ranking/$contando.png' alt=\"2&ordm; Lugar\">";
}elseif($i == 3) {
$img = "<img class='img' src='Pages/Ranking/$contando.png' alt=\"3&ordm; Lugar\">";
}else{
$img = "<li id='cont'> $contando&ordm; Lugar </li>";
}

$clan = mysql_query("SELECT * FROM clan_data WHERE clan_id = '".$a->clanid."'") or die(mysql_error());
$clans = mysql_fetch_object($clan);


$clans->clan_name = empty($clans->clan_name) ? 'Sem info.' : $clans->clan_name;

?>
  <tr id="sub" bgcolor="<? echo $bg; ?>">
    <td style="padding-left:10px"><?php echo $img; ?></td>
    <td style="padding-left:10px"><?php echo $c->char_name; ?></td>
    <td style="padding-left:10px"><?php echo $a->rec_have;  ?></td>
    <td style="padding-left:10px"><?php echo $clans->clan_name; ?></td>
  </tr>
<?
$i++;
}
?>
</table>
</div>
</body>
</html>

Ele so não filtra o accesslevel, era para exibir apenas asslevel<1 ai ele mostra tudo.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...