Pull value from a column with select mysql to php

Asked

Viewed 103 times

-1

Hello!

I have this bank:

SELECT * FROM player_index WHERE player_index.empire

Query return: https://prnt.sc/pk8k1u

And I have this code below,: <?=$players[$i][1]?>

<table id="ranking_evento" data-ranking="player">
<?
$novo_vetor = mysqli_query(server_player(),"SELECT * FROM player WHERE player.name NOT LIKE '[%]%' ORDER BY evento DESC LIMIT 5");
while ($row = mysqli_fetch_assoc($novo_vetor)) {
?>
        <tr class="ranking_table_row">
        	<td class="ranking_icon"></td>
			<td class="ranking_playername"><?=$row['name']?></td>
			<td class="ranking_points">
            <div class="ranking_points_title"><?=l(8);?></div>
			<div class="ranking_points_value"><?=$row['level']?></div>
            <div class="top5kill"><div class="ranking_points_title"><?=l(244);?></div>
			<div class="ranking_points_value"><?=$row['evento']?></div></div>
            <td class="full_ranking_<?=$players[$i][1]?>_kingdom" style="background-size: 35px;"></td>
			</td>
		</tr>
<?PHP } ?>
	</table>

It turns out I need to insert the values from another column of another table in that row:

<td class="full_ranking_<?=$players[$i][1]?>_kingdom" style="background-size: 35px;"></td>

Where this is where the value should be.

In the image below I show a kind of Top5 with orde by. the Top5 above is correct. The flags is where I’m moving.

the first Top5 is complete with the correct flags, if you notice the "Colombian" he has the blue flag,if you notice the "God" he has the yellow flag, if you notice the other 3 red ok and this correct according to the bank.

If you look according to Top5 you will see that all flags are red where in fact the "Colombian" is blue, the God is yellow etc. the value is always the same.

https://prnt.sc/pk5q2c

Here is the code of Top5 that is ok:

    <table id="ranking_table" data-ranking="player">
<?PHP for($i = 1; $i <= 5; $i++){ ?>
        <tr class="ranking_table_row">
            <td class="ranking_icon"></td>
            <td class="ranking_playername"><?=$players[$i][0]?></td>
            <td class="ranking_points">
            <div class="ranking_points_title"><?=l(8);?></div>
            <div class="ranking_points_value"><?=$players[$i][2]?></div>
    		<div class="top5kill"><div class="ranking_points_title"><?=l(244);?></div>
			<div class="ranking_points_value"><?=$players[$i][6]?></div></div>
	        <td class="full_ranking_<?=$players[$i][1]?>_kingdom" style="background-size: 35px;"></td>
			</td>
		</tr>
<?PHP } ?>
    </table>

I hope I’ve been clear thanks for the help I’ve always been.

  • You could share the return of select * FROM player_index WHERE player_index.?

  • here it is: https://prnt.sc/pk8k1u Something else if I put <?=$Row['level']? > in place of <?=$players[$i][1]? > I can pull the correct value from another table. So I need it for <?=$Row['Empire']? >. <?= $players[$i][1]? > returns me always 1.

  • then the $players variable is return of this query, right?

  • Actually Juliano this query just gave example of where is the data I want to pull. I can’t pull the return of it. I pulled this <?=$players[$i][1]? > from another page that I intend to pull that same amount.

  • I believe this player comes pulled from here: https://pastebin.com/U4jhqBcA This code is on another page than all the data I want to pull. The code I want to put is in index.php these codes are all in player.php.

  • then, it is correct that the Empire value comes from the $Row variable’s for interaction

  • Ideally you would use a JOIN in the query to bring the Empire value if you don’t have it in the table you are using

  • That’s right I came from $Row

  • When I declare <?=$Row['Empire']? > does not return anything to me. when I place <?=$Row['level']? > pulls the data from the player table correctly. Here comes the question, how do I know where the $Row is pulling from?

  • $Row is pulling the select data from the $new_vector variable

  • Boy is not that I got :) you gave me a light so I did so and it worked, see what you think: https://pastebin.com/tu3D9mP4

  • that’s right, now just use that value inside the while

  • 1

    It was perfect! Could answer the question about JOIN so I mark as answer that solved?

  • Posted as reply @Renato

Show 9 more comments

1 answer

0


You can use the JOIN so I can grab the spine empire of the other related table, thus being able to use this value resulting from the JOIN in the WHILE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.