从数据库中选择每页10个条目。如何在5个条目后在列表中插入广告块?类似的东西:
public class RootUtil {
public static boolean isDeviceRooted() {
return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary("su")
|| checkForBinary("busybox") || checkForDangerousProps() || checkForRWPaths()
|| detectTestKeys() || checkSuExists();
}
public static boolean detectTestKeys() {
String buildTags = android.os.Build.TAGS;
String buildFinger= Build.FINGERPRINT;
String product=Build.PRODUCT;
String hardware=Build.HARDWARE;
String display=Build.DISPLAY;
return (buildTags != null) && (buildTags.contains("test-keys")|| buildFinger.contains("genric.*test-keys")||product.contains("generic")||product.contains("sdk")||hardware.contains("goldfish")||display.contains(".*test-keys"));
}
public static boolean detectRootManagementApps() {
return detectRootManagementApps(null);
}
public static boolean detectRootManagementApps(String[] additionalRootManagementApps) {
ArrayList<String> packages = new ArrayList<>();
packages.addAll(Arrays.asList(Constants.knownRootAppsPackages));
if (additionalRootManagementApps!=null && additionalRootManagementApps.length>0){
packages.addAll(Arrays.asList(additionalRootManagementApps));
}
return isAnyPackageFromListInstalled(packages);
}
public static boolean detectPotentiallyDangerousApps() {
return detectPotentiallyDangerousApps(null);
}
public static boolean detectPotentiallyDangerousApps(String[] additionalDangerousApps) {
ArrayList<String> packages = new ArrayList<>();
packages.addAll(Arrays.asList(Constants.knownDangerousAppsPackages));
if (additionalDangerousApps!=null && additionalDangerousApps.length>0){
packages.addAll(Arrays.asList(additionalDangerousApps));
}
return isAnyPackageFromListInstalled(packages);
}
public boolean detectRootCloakingApps() {
return detectRootCloakingApps(null);
}
public boolean detectRootCloakingApps(String[] additionalRootCloakingApps) {
ArrayList<String> packages = new ArrayList<>();
packages.addAll(Arrays.asList(Constants.knownRootCloakingPackages));
if (additionalRootCloakingApps!=null && additionalRootCloakingApps.length>0){
packages.addAll(Arrays.asList(additionalRootCloakingApps));
}
return isAnyPackageFromListInstalled(packages);
}
public boolean checkForSuBinary(){
return checkForBinary("su");
}
public boolean checkForBusyBoxBinary(){
return checkForBinary("busybox");
}
public static boolean checkForBinary(String filename) {
String[] pathsArray = Constants.suPaths;
boolean result = false;
for (String path : pathsArray) {
String completePath = path + filename;
File f = new File(completePath);
boolean fileExists = f.exists();
if (fileExists) {
result = true;
}
}
return result;
}
private static String[] propsReader() {
InputStream inputstream = null;
try {
inputstream = Runtime.getRuntime().exec("getprop").getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
String propval = "";
try {
propval = new Scanner(inputstream).useDelimiter("\\A").next();
} catch (NoSuchElementException e) {
}
return propval.split("\n");
}
private static String[] mountReader() {
InputStream inputstream = null;
try {
inputstream = Runtime.getRuntime().exec("mount").getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
if (inputstream == null) return null;
String propval = "";
try {
propval = new Scanner(inputstream).useDelimiter("\\A").next();
} catch (NoSuchElementException e) {
e.printStackTrace();
}
return propval.split("\n");
}
private static boolean isAnyPackageFromListInstalled(List<String> packages){
boolean result = false;
PackageManager pm = MobileTechnicianApp.getAppContext().getPackageManager();
for (String packageName : packages) {
try {
pm.getPackageInfo(packageName, 0);
result = true;
} catch (PackageManager.NameNotFoundException e) {
}
}
return result;
}
public static boolean checkForDangerousProps() {
final Map<String, String> dangerousProps = new HashMap<>();
dangerousProps.put("ro.debuggable", "1");
dangerousProps.put("ro.secure", "0");
boolean result = false;
String[] lines = propsReader();
for (String line : lines) {
for (String key : dangerousProps.keySet()) {
if (line.contains(key)) {
String badValue = dangerousProps.get(key);
badValue = "[" + badValue + "]";
if (line.contains(badValue)) {
result = true;
}
}
}
}
return result;
}
public static boolean checkForRWPaths() {
boolean result = false;
String[] lines = mountReader();
for (String line : lines) {
String[] args = line.split(" ");
if (args.length < 4){
continue;
}
String mountPoint = args[1];
String mountOptions = args[3];
for(String pathToCheck: Constants.pathsThatShouldNotBeWrtiable) {
if (mountPoint.equalsIgnoreCase(pathToCheck)) {
for (String option : mountOptions.split(",")){
if (option.equalsIgnoreCase("rw")){
result = true;
break;
}
}
}
}
}
return result;
}
public static boolean checkSuExists() {
Process process = null;
try {
process = Runtime.getRuntime().exec(new String[] { "which", "su" });
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
return in.readLine() != null;
} catch (Throwable t) {
return false;
} finally {
if (process != null) process.destroy();
}
}
}
PHP代码就是这样:
1. Lisa New York
2. Carl Los Angeles
3. Steve Chicago
4. Jennifer Houston
5. John New York
[ ADVERTISEMENT BLOCK ]
6. Paul Chicago
7. Andrew New York
8. Tom New York
9. Nicky Houston
10.Alex Los Angeles
[ NEXT PAGE ]
如何在5个条目后展示广告?像那样:
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $results_per_page;
$sql = "SELECT * FROM tbl ORDER BY ID ASC LIMIT $start_from, ".$results_per_page;
$rs_result = $conn->query($sql);
while($row = $rs_result->fetch_assoc()) {
?>
<ul>
<li><? echo $row["id"]; ?></li>
<li><? echo $row["name"]; ?></li>
<li><? echo $row["city"]; ?></li>
</ul>
<?php
};
$sql = "SELECT COUNT(ID) AS total FROM tbl;
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$total_pages = ceil($row["total"] / $results_per_page); // calculate total pages with results
for ($i=1; $i<=$total_pages; $i++) { // print links for all pages
echo "<a href='index.php?page=".$i."'";
if ($i==$page) echo " class='curPage'";
echo ">".$i."</a> ";
};
?>
答案 0 :(得分:3)
你走了:
$advertisment_block = ""; //Here define your advertisment
$row_number=0;
while($row = $rs_result->fetch_assoc()) {
$row_number++;
echo '
<ul>
<li>'.$row["id"].'</li>
<li>'.$row["name"].'</li>
<li>'.$row["city"].'</li>
</ul>';
if(($row_number % 5) == 0)
echo $advertisment_block;
};
答案 1 :(得分:0)
试试这个: -
$i=0;
while($row = $rs_result->fetch_assoc()) {
if($i==5) {
echo "Your Advertisement";
$i=0; //if you have rows more than 10 and you want to show advertisement block after every fifth row then need to reset $i to 0.
}
?>
<ul>
<li><? echo $row["id"]; ?></li>
<li><? echo $row["name"]; ?></li>
<li><? echo $row["city"]; ?></li>
</ul>
<?php
$i++;
};