0

I'm trying to pull information from a table in mysql 'ptb_stats'. This is being pulled through 'user_id' specific so that each member of the site can only see their stats.

So far all that is happening is i'm getting the image echoed" on the page and the information being pulled just says array?

Any suggestions where im going wrong please?

Thanks

This is the function:

function get_stats() {
            global $connection;
            global $_SESSION;
            $query = "SELECT  s.location, s.nationality, s.hobbies, s.role, s.friends, s.height, s.weight
                        FROM ptb_stats s
                        WHERE user_id = \'$profile_id\'";



                        $stats_set = mysql_query($query, $connection);
            confirm_query($query, $connection);
            return $stats_set;
        }

This is the fetch array:

 <?php
        $stats_set = get_stats();

        while ($stats = mysql_fetch_array($stats_set)) {


            ?>
    <table width="100%" border="0">
  <tr>
    <td width="13%"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td>
      <td width="25%"><?php echo " $stats"?> </td>
      <td width="13%"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td>
      <td width="25%"><?php echo " $stats"?> </td>
      <td width="13%"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td>
      <td width="20%"><?php echo " $stats"?> </td>
      </tr>
      <tr>
      <td height="36"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td>
      <td><?php echo " $stats"?> </td>
      <td><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td>
      <td><?php echo " $stats"?> </td>
      <td><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td>
      <td><?php echo " $stats"?> </td>
      </tr>
      </table>
<?php
        }

        ?>
6
  • you didn't pass $profile_id to getStats function Commented Oct 21, 2012 at 10:42
  • ok sorry i'm new to sql. how do i do that? Commented Oct 21, 2012 at 10:42
  • and you are always echoing <?php echo " $stats"?> instead of <?php echo $stats['location']?> etc Commented Oct 21, 2012 at 10:44
  • thanks but now when i change it i get this error message: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/PTB1/includes/mod_profile/mod_profile.php on line 285 Commented Oct 21, 2012 at 10:49
  • this is whats on line 285: while ($stats = mysql_fetch_array($stats_set)) { Commented Oct 21, 2012 at 10:49

1 Answer 1

1

$stats is an array with all your results. You need to define which values you want to display like that :

<?php echo $stats['location']; ?>

Futhermore, you should write your code like this way :

<?php
    $stats_set = get_stats();
    while ($stats = mysql_fetch_assoc($stats_set)) : 
?>

<table width="100%" border="0">
<tr>
    <td width="13%"><?php echo $stats['location']; ?></td>
</tr>
</table>

<?php endwhile; ?>

EDIT

You need to use mysql_fetch_assoc instead of mysql_fetch_array (or specify MYSQL_ASSOC) http://php.net/manual/fr/function.mysql-fetch-assoc.php

Sign up to request clarification or add additional context in comments.

3 Comments

that didnt work :( still getting same error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/PTB1/includes/mod_profile/mod_profile.php on line 285
Code above is correct, you have a sql request problem : bad connection, sql syntax error, .... What is confirm_query? Check error using mysql_error after your mysql_query function : php.net/manual/fr/function.mysql-error.php
What do you mean by "is $stats_set"? After mysql_query() (if no error) $stats_set is a ressource, but when you are using in the mysql_fetch_assoc function it is not. Possibilities are : mysql error somwwhere or something bad happends to $stats_set in your confirm_query() function

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.