As you will see I am fetching the column, and trying to update column with new data.
$result2 line is my problem, I don’t think I can add $row[0] in there. How do I do it?
$result = mysql_query("SELECT link FROM items LIMIT 3");
while($row = mysql_fetch_array($result))
{
$url=($row[0]);
$rez2 = get_final_url($url);
$result2 = mysql_query("UPDATE items SET link = $rez2 WHERE id = $row[0] LIMIT 1")
or die(mysql_error());
You should use quotes:
And it would be ideal to use mysql_escape_string() function.
So:
Also you’re trying to use $row[0] as link and as id. Most likely you want $row[0] element to be an ID, and something like $row[n] where n > 0 to be a link. But if you still want to use link you should query in the following manner:
And do not forget to escape $row
It is a good idea to use mysql_fetch_assoc() function – in this case you’ll get an associative array, so you’ll be able access elements by sql column names. And as result you could do something like:
Also if ID is a primary key you do not need LIMIT 1 in the update query.