Log in

View Full Version : Updateing A Table


Logikos
08-13-2004, 11:24 PM
Okay i have a table in my database that has a few rows. There called:

Userid
Threadid
date

You can obvioulsly tell what there for.
Anyway, I added a new row called 'threadtitle' but the values are all blank. Is there anyway that i can run a update query to add all the threadtitles to the proper threadid. All the thread ids have the correct threadid, but now i want to be able to use the thread title.

Basicly, i just want to update the row threadtitle with the correct thread titles based on the threadid row. TIA!

Reeve of shinra
08-14-2004, 12:31 AM
Disclaimer, I have no idea what I am doing. That said:

Something like this I imagine, but I wonder if you could use an * instead of a value (if I understood correctly)


update tablename set fieldname='1' where fieldname='2';

Modin
08-14-2004, 08:25 AM
as far as I know you can't do it in a single query, you'll need a quick script.

<?php
require('global.php');

$threads = $DB_site->query("SELECT threadid, title FROM " . TABLE_PREFIX . "thread");
while($thread = $DB_site->fetch_array($threads))
{
$DB_site->query("UPDATE YourTable SET title='$thread[title]' WHERE threadid='$thread[threadid]'");
}
echo "Script Done";
?>


Hopefully that works for ya :)

Logikos
08-14-2004, 08:13 PM
kool trying now thanks

Logikos
08-17-2004, 04:03 AM
Hey Modin Thanks alot, worked perfect. Just had too change


SET title='$thread[title]'



SET threadtitle = '" . addslashes($thread['title']) . "'


Due to some characters in thread titles.

Modin
08-17-2004, 10:11 PM
ah good call there... slipped by me.

glad it worked, for the most part :)