Jump to content

Where's the data in my array? (Reading from an SQL database)


lamajlooc

Recommended Posts

Hi,
This should be a simple problem to fix.  What I want to do is read a bunch of user data from an SQL table and print it.  I've checked my syntax on PHP.net, I've used similar code before....I have no idea what is going wrong and I think it's a case of cognitive dissonance.

There are no errors returned upon running the script so I'm kind of at a loss.  Any help would be appreciated, thanks.

Here's the code:
<?php # the user index page
    require_once ('../includes/config.inc');

    $page_title = "Welcome Home";
    include_once ('../includes/header.html');
    require_once ('../not_web/mysql_connect.php');
    $query = "SELECT username, first_name, daily_score, agg_score, av_score, winner, times_won, win_circle, date_last_in FROM users WHERE username = '{$_SESSION['username']}'";
    $result = @mysql_query($query); // Do the query
   
    echo "Welcome {$_SESSION['first_name']}";
    [color=orange]// Here I used both just to check that I wasn't crazy but originally I was using MYSQL_NUM with correct syntax[/color]
    while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
        echo $row[0], '<br />';
        echo $row["first_name"], '<br />';
        echo $row[2], '<br />';
        echo $row[3], '<br />';
        echo $row[4], '<br />';
        echo $row[5], '<br />';
        echo $row[6], '<br />';
        echo $row[7], '<br />';
        echo $row[8], '<br />';
    }
    mysql_free_result($result);
    mysql_close();
    include_once('../includes/footer.html');
?>

Thanks again.
Link to comment
Share on other sites

Replace this line:

[code]$result = @mysql_query($query); // Do the query[/code]

With this:

[code]$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // Do the query, show problems if any[/code]

That should help.
Link to comment
Share on other sites

Thanks for your help, but it didn't change much.  I threw in print_r($result); after the query so it looks like this:

$query = "SELECT username, first_name, daily_score, agg_score, av_score, winner, times_won, win_circle, date_last_in FROM users WHERE username = '{$_SESSION['username']}'";
    $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // Do the query, show problems if any
    print_r($result);
    echo "Welcome {$_SESSION['first_name']}";

Now it outputs "Resource id #5". 

Any ideas? 

Thanks again.
Link to comment
Share on other sites

[code]
<?php

$query = "SELECT username, first_name, daily_score, agg_score, av_score, winner, times_won, win_circle, date_last_in FROM users WHERE username = '{$_SESSION['username']}'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // Do the query, show problems if any

while ($row = mysql_fetch_array($result)) {
  echo "{$row['username']}  {$row['first_name']} etc.. ";
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.