lamajlooc Posted October 22, 2006 Share Posted October 22, 2006 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 23, 2006 Share Posted October 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
lamajlooc Posted October 23, 2006 Author Share Posted October 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
.josh Posted October 23, 2006 Share Posted October 23, 2006 [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 anywhile ($row = mysql_fetch_array($result)) { echo "{$row['username']} {$row['first_name']} etc.. ";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.