4. Path tracking
------------------------------------------------------------
The classification creation implementation method has been introduced before. The information of the two stored classification paths is recorded in the classification table. Without any processing, the program can only go to the lowest classification in sequence and cannot go backwards (of course, you can use the browser's back key to go back, but this is incomplete for the program). Therefore, the information of router and router must be decomposed to complete the actual path indication.
Specific practices, if the database records such a classified information:
id:4
uid:2
type: Development Tool
rout_id:0:1:2:4
routine_char:system:linux:development tools
When the program goes to the classification 'development tool', in addition to the path information, it is also required to be able to go to any category on the path. What should I do? The exploit() function is needed here. Because the router_id and router_char are corresponding, they can be decomposed:
$path=explode(":",$rout_id);
$path_gb=explode(":",$rout_char);
At this time, all the classification information was decomposed. What we need to do now is to restore the path information in a link form:
for ($i=0;;$i++) {
$a=$i+1;
echo "<a
href=$php_self?func=showtype&u>",$path_gb[$i],"</a>:";
if (empty($path_gb[$i])) {
break;
}
}
The above code implements the function of linking and restoring the path. Because it implements infinite classification, there is no upper limit, so there is no scope limit in for($i=0;;$i++) and the condition for setting loop exit is that the value in $path_gb[$i] is empty, just insert this code into the program block of the category display layout:
<?
.....
.....
//Show classification******************************************************
if ($func=='showtype'):
echo "<table>";
//Judge the status of the classification
if ($uid!=0) {
$result=mysql_query("select * from type where id=$uid");
$type=mysql_result($result,0,"type");
//********* New code *******************
$rout_id=mysql_result($result,0,"rout_id");
$rout_char=mysql_result($result,0,"rout_char");
$path=explode(":",$rout_id);
$path_gb=explode(":",$rout_char);
echo "<tr><td>";
for ($i=0;;$i++) {
$a=$i+1;
echo "<a
href=$php_self?func=showtype&u>",$path_gb[$i],"</a>:";
if (empty($path_gb[$i])) {
break;
}
}
echo "</td></tr>";
//******** end ***********************
} else {
$type='parent classification';
}
echo "<tr><td><a href='$php_self?func=createtype&uid=$uid'>Create classification</a></td></tr>";
echo "<tr><td>$type</td></tr>";
$result=mysql_query("select * from type where uid=$uid");
$num=mysql_numrows($result);
if (!empty($num)) {
for ($i=0;$i<$num;$i++) {
$id=mysql_result($result,$i,"id");
$type=mysql_result($result,$i,"type");
echo "<tr><td>";
echo "<a href='$php_self?func=showtype&uid=$id'>$type</a>";
echo "</td></tr>";
}
}
echo "</table>";
endif; /* end showtype */
.....
.....
?>
After completing this function block, you can continue to display the classified information...
Previous page1234Read the full text