Page 1 of 1

Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 9:39 am
by bet0x
Hello.

I am trying to retrieve information from my mysqldb but I don't recieve the full information.

Code: Select all

$items = mysql_query("SELECT * FROM items WHERE owner_id = '" . $char_id . "'");
        while($row = mysql_fetch_array($items))
        {
            $show_adena = $row['count'];
            $item_id = $row['item_id'];
        }
That's the code I am using, and when I am echoing out $row['item_id']; I only recieve one "info", and when I check the database myself I see that there's alot more information that matches with the "$char_id" ..

Can someone help me out?

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 9:47 am
by papa
Are you echoing out in the loop itself?

Code: Select all

 
while($row = mysql_fetch_array($items))
{
             $show_adena = $row['count'];
              echo $item_id = $row['item_id'];
         }

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 9:49 am
by bet0x
Nope, I don't have a loop in it, do I need one?

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 9:57 am
by papa
No, what I mean is that the variable $item_id is getting overwritten each time the loop iterates or whatever you call it.

So either you need to echo that var when the loop runs or you can also save the data in a new array like this:

Code: Select all

 
$data = array();
while($row = mysql_fetch_array($items))
{
            $data[] = array("show_adena"=>$row['count'], "item_id"=>$row['item_id']);
}
 
print_r($data);
 

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 10:01 am
by bet0x
Yeah I get it, I tried the option you showed but then it just echoes out alot of $data[] = array("show_adena"=>$row['count'], "item_id"=>$row['item_id']); like that over the whole page? :p

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 10:03 am
by papa
Either you echo like my first example or you make use of the $data array. If you echo the array in the loop it will get messy :)

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 10:05 am
by bet0x
Yah I have tried the first example, but then it just echoes out one value, and there's like 3 more that should come out but they don't :s

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 10:08 am
by papa
Use mysql_assoc instead of fetch array:

http://us3.php.net/manual/en/function.m ... -assoc.php

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 10:12 am
by bet0x
Alright! Now it echoes out good again, but still only one value..?

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 10:15 am
by papa
Show your code so far?

You sure that $char_id is ok?

Re: Cant retrieve the information from my MySQL database

Posted: Mon Nov 16, 2009 10:17 am
by bet0x
Yeah cause otherwise it would show the full table and everything :p

I can show you the full code.

Code: Select all

<?php
 
getFacts();
if(isset($_GET['user']))
{
 
 
    $result = mysql_query("SELECT * FROM characters WHERE char_name = '" . $_GET['user'] . "'");
    while($row = mysql_fetch_array($result))
    {
    
    $time = mysql_real_escape_string($row['onlinetime']);
    $char_id = mysql_real_escape_string($row['charId']);
    $pvpkills = mysql_real_escape_string($row['pvpkills']);
    $pkkills = mysql_real_escape_string($row['pkkills']);
    $online = mysql_real_escape_string($row['online']);
        
        $items = mysql_query("SELECT * FROM items WHERE owner_id = '" . $char_id . "'");
        while($row = mysql_fetch_assoc($items))
        {
            $show_adena = $row['count'];
            $item_id = $row['item_id'];
        }
        
    ## TIME SETTINGS ##
    $d = floor ($time / 1440);
    $h = floor (($time - $d * 1440) / 60);
    $m = $time - ($d * 1440) - ($h * 60);
        
    echo 'The character <b>' . $_GET['user'] . '</b> is an : ' . $char_race . '<br>';
    echo 'Class: ' . $char_class . '<br>';
    echo 'PVP Kills: ' . $pvpkills . ' Pk Kills: ' . $pkkills . '<br>';
    echo 'Time playing -> Days: ' . $d . ' Hours: ' . $h . ' Minutes: ' . $m . ' <br>';
    echo 'Total amount of Adena: <font color="#226fff"><b>';
    if($show_adena == 0) echo 'None'; else echo number_format($show_adena);
    echo "</font></b><br>";
    echo 'This character is currently ';
    
    if($online == 1) echo ' <font color="#06f74a"><b>Online</b></font>'; else echo ' <font color="#f70606"><b>Offline</b></font>';
 
    
    
    echo '<br><br>Item Names:<br>';
    echo $item_id;
 
    
    
    }
 
}
 
 
 
if(isset($_POST['character']))
{
 
    $result = mysql_query("SELECT char_name FROM characters WHERE char_name = '" . $_POST['character'] . "'");
    if(mysql_num_rows($result) == 0) exit("The character that you are searching for does not exist.");
    else 
    {   
        while($row = mysql_fetch_array($result))
        {
        
            echo 'Found characters:<br>';
            echo "<a href='index.php?op=informer&user=" . $row['char_name'] . "'>" . $row['char_name'] . "</a>";
        
        }
    }
    
}
 
elseif (!isset($_GET['user']) && (!isset($_POST['character']))) {
 
?>
<p>The "Informer" is a great idea for all Lineage 2 servers. When we created it, we had a single goal in mind, to give the players the ability to check every player ingame, for stats and rankings. So put in a name, and enjoy.
</p>
    
<form method="post" action="index.php?op=informer">
<input type="text" name="character" value="Name of the character">
<input type="submit" value="Search">
</form>
 
<?php
}
 
?>