The specific implementation code, as follows: The following will give a simple description.
Copy Code code as follows:
<?php
/*
1. Configure your database connection
2. Note that the prefix of the data table name defaults to Dede_
3. You must first back up your database or backup dede_archives table if the loss I am not responsible for
*/
Database connection Settings
$ip = "localhost"; Address
$user = "jb51"; User name
$PW = "Www.jb51.net"; Password
$db = "jb51"; Table name
$conn =mysql_connect ($ip, $user, $PW);
mysql_select_db ($DB);
mysql_query ("Set names GBK"); Set Encoding to GBK
Get the body data.
function Body ($id) {
$exec = "SELECT * from Dede_addonsoft where aid = '" $id. "'";
$result =mysql_query ($exec);
$rs =mysql_fetch_object ($result);
$id = $rs->introduce;
return $id = $id;
}
It's over! Get Body Data
Get started! Extract the first picture address in a variable
function Bodyimg ($obj) {
if (Isset ($obj)) {
if (Preg_match ("return $obj = $regs [1];
} else {
echo "Erro: No picture Address!" <br> ";
return $obj = 1;
}
}
}
The end! Extracts the first picture address in a variable
Start modifying rchives, inserting the acquired image address
function Changearchives ($pic, $id) {
$sql = "UPDATE ' dede_archives '"
SET ' litpic ' = ' ". $pic." '
WHERE ' id ' = '. $id. "'";
$result =mysql_query ($sql);
if ($result ==1) echo modifies the data successfully! <br> ";
else echo "Modify data failure!<br>";
}
End Modify Rchives, insert acquired image address
Display Datasheet Contents
$exec = "SELECT * from Dede_archives where typeid in ( 494,495,496,497,498,499,500,501,502,503,504,374,375,376,377,378,379,488) and litpic = ' "; Channel= ' 1 ' is the article channel can also use typeid= '
$result =mysql_query ($exec); Specify a column ID but only the ID of the smallest category, Litpic = ' meaning the thumbnail address is empty
while ($rs =mysql_fetch_object ($result))
{
$id = $rs->id;
echo $id. " ";
$body = Body ($id); Call function to get body content
$pic = bodyimg ($body); Call function to get the first picture address inside the body
if ($pic <>1) {
Changearchives ($pic, $id); Call function Insert get address
}
}
Mysql_close ($conn);
?>
I also just learn PHP above the code is also a patchwork of do a detailed annotation beginners can also come to see
Because the above code can not automatically get the next level of directories, so compare the manual add directory ID, commonly used statements have.
$exec = "SELECT * from Dede_archives where typeid in (1,2,3) and litpic = '"; Channel= ' 1 ' is the article channel can also use typeid= '
The code above is to get the data for typeID 1 and 2 and 3.
If you perform a modification of an ID, you can use the following statement
$exec = "SELECT * from Dede_archives where typeid= ' 1 ' and litpic = '";
If it's a channel, you can use it.
$exec = "SELECT * from Dede_archives where channel= ' 1 ' and litpic = '";
Note that the first backup, or do not casually test, note that the dedecms5.1 version, the other version should also adapt. Multi-Test (under the premise of backup). )