PDA

View Full Version : mysql query


chris1979
06-09-2009, 10:19 AM
I haven't used signatures on my forum before but I'd like to start.

To get started, is there a way I can use mysql to put whatever people have as their homepage into the signature field. I know how I'd do this if they were in the same table,

e.g. UPDATE user SET signature = homepage;

but in this case I think signature is in the usertext table and homepage is in the user table.

Any idea how I can do this then?

chris1979
06-28-2009, 03:53 PM
bump

deadlySniper
06-28-2009, 03:58 PM
Um, I don't... Sorry. =\

Cryo
06-28-2009, 06:05 PM
You could use a PHP script in your forum home directory like this...

<?

include("./global.php");

$get_SQL = "SELECT
a.userid,
a.username,
a.homepage
FROM
". TABLE_PREFIX ."user a,
". TABLE_PREFIX ".usertextfield b
WHERE
a.userid = b.userid
AND b.signature = \"\"
ORDER BY
a.userid ASC";

$get = mysql_query($get_SQL) or die(mysql_error());

while ($g = mysql_fetch_array($get)) {

$update_SQL = "UPDATE
". TABLE_PREFIX ."usertextfield
SET
signature = \"". mysql_real_escape_string($g["homepage"]) ."\"
WHERE
userid = \"". $g["userid"] ."\"";

$update = mysql_query($update_SQL) or die(mysql_error());

echo "". $g["username"] ."'s signature has been updated.<br />";

}

echo "All done!";

?>It will run an update that will make all signatures the user's homepage.