第一次问这样请好一点:)...我试图根据我的数据库中的内容动态创建一个新表。该表应该有3列,每列都有自己的标题(第一种情况:“植物”,第二种:“用户”第三种:“电子邮件”)以及与数据库中的数据一样多的行。此外,每个数据都重定向到另一个PHP链接。你能帮我吗?
这是页面应该是什么样子的图形:
Example of the table im trying to do
这是我的代码:
<?php
$cn = mysql_connect("localhost","pablokvitca","") or
die("No se pudo conectar: " . mysql_error());
mysql_select_db("gaea");
$searched=$_GET['search'];
$sql1= "SELECT * FROM Plantas WHERE Nombre LIKE '%$searched%'";
$sql2= "SELECT * FROM Usuarios WHERE Username LIKE '%$searched%'";
$sql3= "SELECT * FROM Usuarios WHERE email LIKE '%$searched%'";
$result1=mysql_query($sql1);
$result2=mysql_query($sql2);
$result3=mysql_query($sql3);
$e1 = "";
$e2 = "";
$e3 = "";
$e1.='<table align="center" align="top">';
//$e1.='<th>Plantas</th>';
//$e2.='<th>Usuarios</th>';
//$e3.='<th>Mails</th>';
while ($row1 = mysql_fetch_array($result1)) { //plants
$e1 .= '<tr align=left>';
$pln = $row1['Nombre'];
$idp = $row1['idPlanta'];
$e1 .= '<td>';
$e1 .= "<div style=color:black;margin-left:50px;font-size:25px;>";
$e1 .= '<p> <a href="newPlanta.php?pltID='.$idp.'&viewer=true">Planta:'.$pln.'</a></p>';
$e1 .= "</div>";
$e1 .= '</td>';
$e1 .= '</tr>';
}
echo $e1;
//$e1.='</tr>';
//echo $e1;
while ($row2 = mysql_fetch_array($result2)) { //user
$e2 .= '<tr align=left>';
$usu = $row2['username'];
$e2 .= '<td>';
$e2 .= "<div style=color:black;margin-left:50px;font-size:25px;>";
$e2 .= '<p> <a href="perfil.php?id='.$usu.'">Usuario:'.$usu.'</a></p>';
$e2 .= "</div>";
$e2 .= '</td>';
$e2 .= '</tr>';
}
echo $e2;
while ($row3 = mysql_fetch_array($result3)) { //email
$ml = $row3['username'];
$e3 .= '<tr align=left>';
$e3 .= '<td>';
$e3 .= "<div style=color:black;margin-left:50px;font-size:25px;>";
$e3 .= '<p> <a href="perfil.php?id='.$ml.'">Email:'. $row3['email'].'</a></p>';
$e3 .= "</div>";
$e3 .= '</td>';
$e3 .= '</tr>';
}
echo $e3;
$e3.='</table>';
?>
答案 0 :(得分:1)
虽然我必须承认,我不明白为什么你想以这种方式安排这个表。但是,我无法抗拒挑战!
我获取了所有数据并使用您想要的相同表结构构建了一个数组。然后,一旦数组完成,我们就可以运行foreach循环来构建表。
我没有测试过这个,因为我没有让你的数据库运行。在我的脑海里,它虽然有效。
public class ThousandDigits {
public static void main(String[] args) {
int greatest = 0;
String num = ("73167176531330624919225119674426574742355349194934"
+ "96983520312774506326239578318016984801869478851843"
+ "85861560789112949495459501737958331952853208805511"
+ "12540698747158523863050715693290963295227443043557"
+ "66896648950445244523161731856403098711121722383113"
+ "62229893423380308135336276614282806444486645238749"
+ "30358907296290491560440772390713810515859307960866"
+ "70172427121883998797908792274921901699720888093776"
+ "65727333001053367881220235421809751254540594752243"
+ "52584907711670556013604839586446706324415722155397"
+ "53697817977846174064955149290862569321978468622482"
+ "83972241375657056057490261407972968652414535100474"
+ "82166370484403199890008895243450658541227588666881"
+ "16427171479924442928230863465674813919123162824586"
+ "17866458359124566529476545682848912883142607690042"
+ "24219022671055626321111109370544217506941658960408"
+ "07198403850962455444362981230987879927244284909188"
+ "84580156166097919133875499200524063689912560717606"
+ "05886116467109405077541002256983155200055935729725"
+ "71636269561882670428252483600823257530420752963450");
int max = -1;
for (int n = 0; n < num.length() - 4; n++) {
greatest = ((num.charAt(n) - '0') * 10000 + (num.charAt(n + 1) - '0') * 1000
+ (num.charAt(n + 2) - '0') * 100 + (num.charAt(n + 3) - '0') * 10 + (num.charAt(n + 4) - '0'));
if (max < greatest) {
max = greatest;
}
}
System.out.print(max);
}
}