<?php $servername = "xxx"; $username = "xxx"; $password = "xxx"; $v1 = "_wp282" $v2 = "_wp111"; $v3 = "_wp72"; $v4 = "_wp193"; $v5 = "_wp555"; $v6 = "_wp366"; $v7 = "_wp74"; $v8 = "_wp721"; $v9 = "_wp924"; $v10 = "_wp253"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; //Here I connect to both databases $query103 = mysqli_query($conn, "SELECT * FROM `$v1`.`wpd2_posts` where post_status='wc-processing' or post_status='wc-completed' or post_status='wc-failed' UNION SELECT * FROM `$v2`.`wpd2_posts` where post_status='wc-processing' or post_status='wc-completed' or post_status='wc-failed' order by post_date DESC ") or die(mysqli_error($conn)); ?> <br> <h2>Database 3</h2> <table style="width: 100%"> <tr> <td>ID</td> <td>??</td> <td>??</td> <td>??</td> <td>??</td> <td>??</td> </tr> <?php while($row = mysqli_fetch_array($query103)) { // Here I try to find what database the customer is on $id2 = $row['ID']; if($row['ID'] == ''){ echo "intet id"; }else { $query = mysqli_query($conn, "SELECT * FROM `$v1`.`wpd2_posts` where ID = '$id2' ORDER BY id") or die(mysqli_error($conn)); if(mysqli_num_rows($query) == '') { $query = mysqli_query($conn, "SELECT * FROM `$v2`.`wpd2_posts` where ID = '$id2' ORDER BY id") or die(mysqli_error($conn)); if(mysqli_num_rows($query) == '') { }else{ $version = "_wp111"; } }else{ $version = "_wp282"; } } echo "<tr>"; echo "<td>". $row['ID']."</td>"; echo "<td>". $row['post_date']."</td>"; echo "<td>". $row['post_status']."</td>"; //And here I try to get the data out $querynavn = mysqli_query($conn, "SELECT meta_value FROM `$version`.`wpd2_postmeta` where meta_key='_shipping_first_name' and post_id='$id2' ") or die(mysqli_error($conn)); while($row2 = mysqli_fetch_array($querynavn)) { $fornavn = urldecode($row2['meta_value']); } echo "<td>". $fornavn."</td>"; echo "<td>".$version."</td>"; echo "<td>6</td>"; echo "</tr>"; } ?> </table>
if(mysqli_num_rows($query) == '') { rettes til: if(mysqli_num_rows($query) == 0 ) {
SELECT *, '$v1' as version FROM `$v1`.`wpd2_posts` where post_status='wc-processing' or post_status='wc-completed' or post_status='wc-failed' UNION SELECT *, '$v2' as version FROM `$v2`.`wpd2_posts` where post_status='wc-processing' or post_status='wc-completed' or post_status='wc-failed' order by post_date DESC
$version = $row['version'];