i´me trying to update a database column with the values i get with COUNT on the database. <? include("con.php"); $mysql = new conexao; $listaclientes = $mysql->sql_query("SELECT file_author, COUNT(file_author) FROM phcdl_files GROUP BY file_author;"); $mysql->desconecta;while($clientes= mysql_fetch_array($listaclientes)){ $mysql->sql_query("UPDATE LOW_PRIORITY phcdl_users SET user_uploads=".clientes['COUNT(name)'] ." where file_author = $clientes['file_author'];"); } ?> Code (php): However, the page retrieves this > Parse error: syntax error, unexpected '[' in /home2/antivir5/public_html/legendaspt/perso/updater.php on line 20 I´me noob in php, so the codes are what i found in searches, i already found one with wich i could output the nr of uploads for each user, but what i i reallly need is to update the database Does someone knows what´s the problem??
try this <? include("con.php"); $mysql = new conexao; $sql = "SELECT file_author, COUNT(file_author) FROM phcdl_files GROUP BY file_author"; $listaclientes = $mysql->sql_query($sql) or die(mysql_error().'<br>'.$sql); //$mysql->desconecta; while($clientes= mysql_fetch_array($listaclientes)){ $sql = "UPDATE LOW_PRIORITY phcdl_users SET user_uploads='{$clientes['COUNT(name)']}' where file_author = '{$clientes['file_author']}'"; $mysql->sql_query($sql) or die(mysql_error().'<br>'.$sql); } ?> PHP:
" Unknown column 'file_author' in 'where clause' " the "file_author" is in the "phcdl_files" table, and the "user_uploads" is on the "phcdl_users" Is something related to that , the problem?
bump sorry for, but do you know how can i solve the problem? as i just said yd both columns are in diferent tables, what could i do to fix the problem?
Try this, I think the problem is with your apostrophes and quotes: <? include("con.php"); $mysql = new conexao; $listaclientes = $mysql->sql_query("SELECT file_author, COUNT(file_author) FROM phcdl_files GROUP BY file_author;"); $mysql->desconecta;while($clientes= mysql_fetch_array($listaclientes)){ $mysql->sql_query("UPDATE LOW_PRIORITY phcdl_users SET user_uploads="'".clientes['COUNT(name)'] ."'" where file_author = $clientes['file_author'];"); } ?> PHP:
something stills wrong Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home2/antivir5/public_html/legendaspt/perso/updata.php on line 6 Code (markup):
I stand by my code but I was relying on the essence of your sql to be right. Might pay to let us know the table structure (columns).