2
I’m having a problem when creating a system, I need to make a select:
$select = $mysqli->query("SELECT * FROM `guild` WHERE `user_id`='$userid'");
$row = $select->num_rows;
$get = $select->fetch_array();
$guild = $get['guild'];
Transform the variable $guild
in one array and catch it in the other select
$select = $mysqli->query("SELECT * FROM `guild` WHERE `guild` != '$guild' AND `user_id` != '$userid' ORDER BY `score` DESC LIMIT 5");
$row = $select->num_rows;
$get = $select->fetch_array();
$guild_name = $get['guild'];
$guild_icn = $get['icn'];
$guild_score = $get['score'];
Exactly what I need is that in this select
all results of the array
, but I have no idea how to do that.
Complete code:
<?php
require_once ("includes/connection.php");
require_once ("includes/start-session.php");
require_once ("includes/encript.php");
$ip = $_SERVER["REMOTE_ADDR"];
$iusername = "Trabzera";
$userid = "10";
$select = $mysqli->query("SELECT * FROM `data` WHERE username='$iusername' AND `ip`='$ip'");
$row = $select->num_rows;
$get = $select->fetch_array();
if ($row > 0) {
$select = $mysqli->query("SELECT * FROM `guild` WHERE `user_id`='$userid'");
$row = $select->num_rows;
$get = $select->fetch_array();
$guild = $get['guild'];
#----------------------
$select = $mysqli->query("SELECT * FROM `guild` WHERE `guild` != '$guild' AND `user_id` != '$userid' ORDER BY `score` DESC LIMIT 5");
$row = $select->num_rows;
$get = $select->fetch_array();
$guild_name = $get['guild'];
$guild_icn = $get['icn'];
$guild_score = $get['score'];
$score_result = round($guild_score/1000);
$count = 1;
echo '<div id="guild-central">Central da Guild</div>
<div id="guild-central-msg">Selecione abaixo a opção desejada:</div>
<menu id="create-guild">
<div id="create-guild-msg">Criar uma Guild</div>
<div id="create-guild-txt">Para criar uma Guild é necessário alguns requerimentos:</div>
<div id="create-guild-req1">- Nível 10+</div>
<div id="create-guild-req2">- 1000 KP (Knautiluz Points)</div>
<div id="create-guild-reqok">Caso atenda esses requsistos clique abaixo:</div>
<button id="create-guild-button">Criar uma Guild</button>
</menu>';
echo '<menu id="join-guild">
<div id="join-guild-msg">Juntar-se a uma Guild</div>';
#-----------------------------------------------------
if ($row > 0) {
while ($count <= $row) {
echo'
<script>
$("#guild-join-request-'.$count.'").click (function() {
var guildName = $("#guild-join-name-'.$count.'").html();
var src = $("#guild-join-icn-'.$count.'").attr("src");
var iusername = "'.$iusername.'";
var userid = "'.$userid.'";
$.ajax({
url: "systems/join-guild.php",
type: "POST",
data: {iusername: iusername, userid: userid, guildName: guildName, src: src},
beforeSend: function() {
$("#sucess").html("Carregando...");
},
success: function (result) {
$("#user-painel-2").html(result);
}
});
});
</script>';
echo'
<div id="guild-join-'.$count.'" class="guild-join">
<img src="'.$guild_icn.'" id="guild-join-icn-'.$count.'"></img>
<div id="guild-join-name-'.$count.'" class="guild-join-name">'.$guild_name.'</div>
<div id="guild-join-score-'.$count.'" class="guild-join-score" >- '.$score_result.'K</div>
<input style="cursor:pointer;" type="button" id="guild-join-request-'.$count.'" value="Solicitar" class="guild-join-request"></input>
<div id="guild-join-underline-'.$count.'" class="guild-join-underline"></div>
</div>';
$get = $select->fetch_array();
$guild_name = $get['guild'];
$guild_icn = $get['icn'];
$guild_score = $get['score'];
$score_result = round($guild_score/1000);
$count++;
}
echo'<menu id="guild-request">
<div id="guild-request-msg">Solicitações Pendentes:</div>';
#---------------------------------------------------------------
$select = $mysqli->query("SELECT * FROM `guild` WHERE `user_id` ='$userid'");
$row = $select->num_rows;
$get = $select->fetch_array();
$guild_name = $get['guild'];
$guild_icn = $get['icn'];
$guild_score = $get['score'];
$score_result = round($guild_score/1000);
$count = 1;
if($row > 0) {
while ($count <= $row) {
echo'
<div id="guild-request-'.$count.'" class="guild-request">
<img src="'.$guild_icn.'" id="guild-request-icn-'.$count.'"></img>
<div id="guild-request-name-'.$count.'" class="guild-request-name" >'.$guild_name.'</div>
<div id="guild-request-score-'.$count.'" class="guild-request-score">- '.$score_result.'K</div>
<button id="guild-request-cancel-'.$count.'" class="guild-request-cancel">Cancelar</button>
<div id="guild-request-underline-'.$count.'" class="guild-request-underline"></div>
</div>';
$get = $select->fetch_array();
$guild_name = $get['guild'];
$guild_icn = $get['icn'];
$guild_score = $get['score'];
$score_result = round($guild_score/1000);
$count++;
}
echo '</div>
</menu>';
} else {
echo'
<menu id="guild-request">
<div id="guild-request-msg">Solicitações Pendentes:</div>
<div id="no-requests">Nenhuma solicitação pendente.</div>
</menu></menu>';
}
#---------------------------------------------------------------
} else {
echo "Ainda não existe nenhuma guild.";
}
} else {
echo "Erro.";
}
I didn’t understand very well... aren’t you managing to make the request disappear at click time? or it is as if the request had not been sent?
– LocalHost
No, for example: the user clicks to request, registers the request in the BD, then when refreshing the page the option to request that Guild goes down there, and goes down as in the image, but only one result is missing, the rest continues.
– Raizant
Then that code from above, is the one that displays the requests and the one from below is the pending? You checked if you are sending the request?
– LocalHost
I edited the question, I do not know if it has improved. The request is sent, registered. After updating only one result some of the Guilds options, the rest continues as request even if they have already been requested. The request is being sent normally, so much so that it appears down there, but as he has already requested it should disappear from up there... :/
– Raizant
It would be nice if you put it the way it is in the picture, her code. Because it’s hard to understand, but I know where the possible error might be, because I’m working with array as a result, and if that result results in multiple data, and I don’t use a repetition structure, Voce will simply take a record which is what seems to be happening
– LocalHost
The method fetch_array of
mysqli
returns one result row as an associative, numeric or both array. That is, Voce is only taking the first result of its query. I think the fetch_all should be useful in your case.– rdleal
I edited the whole question. That’s right Pantera, I need to transform the Rows in an array to pick up at the time of the other select, but I don’t know how to do, I don’t understand much about arrays...
– Raizant