0

I have a double search that happens within the script. When it searches for a players gear, it will take the player UID and bring back the name of that player. The only issue is that there may be more than 1 result that will return and it will only display the last UID with the name.

$ip = "localhost";
$user = "******";
$pass = "*******";
$db = "hivemind";
$ill1 = $_POST['search'];

//Database Connection
$con = @mysql_connect("$ip:3316", "$user", "$pass")
            or die(mysql_error());

//Select Database
$dbcon = @mysql_select_db($db, $con)
            or die(mysql_error());

$sql = mysql_query("select PlayerUID, Inventory, Backpack from character_data where Inventory like '%$ill1%'");

while ($row = mysql_fetch_array($sql)) {
    $puid = $row['PlayerUID'];
    $inv = $row['Inventory'];
    $back = $row['Backpack'];
    ?>
    <html>
    <body>
    <table>
    <tr>

                    <td><?php echo "$puid"; ?></td>
                    <td><?php echo "$inv"; ?></td>
                    <td><?php echo "$back"; ?></td>

    </tr>
    </table>
    </body>
    </html>
    <?php }?>

    <?php

//Database Connection
$con = @mysql_connect("$ip:3316", "$user", "$pass")
            or die(mysql_error());

//Select Database
$dbcon = @mysql_select_db($db, $con)
            or die(mysql_error());

$sql = mysql_query("select PlayerUID, PlayerName from player_data where PlayerUID like '%$puid%'");

while ($row = mysql_fetch_array($sql)) {

    $puid2 = $row['PlayerUID'];
    $plnm = $row['PlayerName'];
    ?>
    <html>
    <body>
    <table>
    <tr>    
                    <td><?php echo "$puid"; ?></td>
                    <td><?php echo "$plnm"; ?></td>


    </tr>
    </table>
    </body>
    </html>
     }

2 Answers 2

1

It is returning all the results. You're not printing them properly.

Move the html,body,table tags outside the while loop.

Change the loop to:

while ($row = mysql_fetch_array($sql)) {

    $puid2 = $row['PlayerUID'];
    $plnm = $row['PlayerName'];
    echo "<tr><td>".$puid."</td>";
    echo "<td>".$plnm."</td></tr>";
} 
Sign up to request clarification or add additional context in comments.

6 Comments

Just tried it. It still only pulls up the last PUID from above. <html> <body> <table> <tr> <? while ($row = mysql_fetch_array($sql)) { $puid2 = $row['PlayerUID']; $plnm = $row['PlayerName']; > <td><?php echo "$puid"; ?></td> <td><?php echo "$plnm"; ?></td> <? }> </tr> </table> </body> </html>
Sorry, just made an edit. The <tr></tr> needs to be inside the loop too. The loop will be executed for every row returned, so you'll need to create a <tr> element in each instance of the loop.
I just tried. Still only showing 1 <? while ($row = mysql_fetch_array($sql)) { $puid2 = $row['PlayerUID']; $plnm = $row['PlayerName']; echo "<tr><td>" .$puid. "</td>"; echo "<td>" .$plnm. "</td></tr>"; }> </table> </body> </html>
Paste the complete php page on pastebin.
You still have html,body,table inside the body of the first while loop. And you don't need to use html,head,body twice. I'd recommend you put html,head and body outside all php code.
|
0

print below code in loop

<td><?php echo "$puid"; ?></td>
  <td><?php echo "$plnm"; ?></td>

you print only one time , so overwrite value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.