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. Link to comment https://forums.phpfreaks.com/topic/24785-wheres-the-data-in-my-array-reading-from-an-sql-database/ 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. Link to comment https://forums.phpfreaks.com/topic/24785-wheres-the-data-in-my-array-reading-from-an-sql-database/#findComment-112938 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. Link to comment https://forums.phpfreaks.com/topic/24785-wheres-the-data-in-my-array-reading-from-an-sql-database/#findComment-112945 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] Link to comment https://forums.phpfreaks.com/topic/24785-wheres-the-data-in-my-array-reading-from-an-sql-database/#findComment-112989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.