Ed Curtis wrote: > I'm having some trouble echoing a value to a file that is being > pulled from a MySQL database. I've included my code below I'm sure > it's something really simple but I'm not seeing it. > $row['users.name'] and $row['users.company'] echo nothing while > $row['cnt'] echoes it's expected values. If anyone can tell me what > I'm doing wrong I'd appreciate it. > > Thanks, > > Ed > > $ap = fopen("$ad_path/AdCount$issue.txt", "w"); > > mysql_connect ($local_host, $local_user, $local_pass); > > mysql_select_db ($local_db); > > $result = mysql_query ("SELECT *, COUNT(*) as cnt FROM users, > listings WHERE listings.user_id = users.id AND listings.active = '1' > GROUP BY users.company, users.name"); > > if ($row = mysql_fetch_array($result)) { > > do { > > fputs($ap, $row['users.name']); > fputs($ap, $sp); > fputs($ap, $sp); > fputs($ap, $row['users.company']); > fputs($ap, $sp); > fputs($ap, $sp); > fputs($ap, $row['cnt']); > fputs($ap, $nl); > > } > > while($row = mysql_fetch_array($result)); > > mysql_close(); } > > fclose($ap);
I'm not sure about MySQL, but I know for PostgreSQL when I prefix a field name with a table name in a query I don't need to specify the table name when accessing that fieldname in the query result. Try changing: fputs($ap, $row['users.name']); fputs($ap, $row['users.company']); To: fputs($ap, $row['name']); fputs($ap, $row['company']); That should do the trick. Cheers, Pablo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php