I need to add two values in two colums to every row in the database. So I am thinking I do a select statement then an update statement.. but I am having trouble. I tried doing a search but I cant come up with anything useful... so heres the code...
////open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Error: Unable to
connect to database. Try again later!");
// select database
mysql_select_db($db) or die ("Unable to select database. Try again later!");
// generate and execute query
$query = "SELECT id, category, link FROM table ORDER BY id DESC";
$result = mysql_query($query) or die ("Error: Page Under Construction");
// if records present
if (mysql_num_rows($result) > 0) {
// iterate through resultset
// print title with links to edit and delete scripts
while($row = mysql_fetch_object($result)) {
$id = "$row->id";
$link= "$row->link";
///////insert some code to generate new column data ($newdata1 and $newdata2)
// generate and execute query
$query = "UPDATE table SET newcolumn = '$newdata1', newcolumn2 = '$newdata2' WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
} ///while
// if no records present
// display message
} ////row
else {
print "ERROR RETRIEVING DATA";
}
// close connection
mysql_close($connection);
// ....
include "footer.php";
?>
So is this something that can be done? Or what is another way to get it done?