0
我想用這段代碼來完成兩件事情。我使用INSERT PHP Plugin將PHP直接寫入WP頁面。PHP和MySQL WP
1)查詢MySQL數據庫並將結果從一列返回到四列。
2)使每個結果都是它自己的超鏈接,它將用戶引導到在該頁面上運行新查詢的新WP頁面。
我能夠得到查詢來顯示結果,甚至將這些結果變成動態超鏈接,但我無法取得格式。現在它只是將結果返回到一列中。這裏是我有:
[insert_php]
$servername = "localhost";
$username = "login"; //edited for privacy
$password = "password"; //edited for privacy
$database = "database"; //edited for privacy
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
//get results from database
$result = mysqli_query($conn,"SELECT mine FROM mines ORDER BY mine");
$all_property = array(); //declare an array for saving property
//showing property
echo '<table class="data-table">
<tr class="data-heading">'; //initialize table tag
while ($property = mysqli_fetch_field($result)) {
echo '<td>' . $property->name . '</td>'; //get field name for header
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag
//showing all data
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
foreach ($all_property as $item) {
echo "<td><a href='urlhere/$row[$item]'>".$row[$item]. "</a>"."</td>"; //get items using property value
}
echo '</tr>';
}
echo "</table>";
[/insert_php]
感謝您的任何幫助,您可以提供。
我想結果看起來像這樣(每一個爲超鏈接):
您的查詢只抓住一列。你如何看待4列? – Eric
你能展示你期待什麼格式嗎? –
Eric - 我想將結果格式化爲頁面上的四列。 – user2267031