2017-01-26 2 views
1

Hier ist die Herausforderung und ich bin mir sicher, dies ist nicht das erste Mal, dass jemand in dieses Problem kam jedoch keine brauchbare Lösung für diesen spezifischen Prozess innerhalb der Seiten gefunden von Stack Überlauf oder ein anderes Entwicklungsforum für diese Angelegenheit.So rufen Sie benutzerspezifische Daten aus einer externen Datenbank in WordPress

Hier ist die Aufgabe, die ich versuche zu vervollständigen.

Ich habe eine WordPress-Website erstellt, die ein Mitgliederbereich sein wird, in dem nur registrierte Benutzer sich auf der Seite einloggen können, um ihren Inhalt zu sehen. Diese Funktionalität wird über WordPress erledigt, aber ich habe eine Seite in WordPress mit dem Titel "Mitgliedsstatus", für die ich eine eigene Seitenvorlage erstellt habe, um Informationen zu erhalten, die benutzerspezifisch für ein Formular auf dieser Seite sind. Die benutzerspezifischen Informationen werden von einer sekundären externen Datenbank in die WP-Datenbank übertragen.

Hier ist der Code für die benutzerdefinierte Seite Vorlage für eine bessere Sicht auf das, was ich versuche zu tun. Grundsätzlich würden alle Formularfelder von der spezifischen Zeile des angegebenen Benutzers ausgefüllt werden. Allerdings scheint die Abfrage jedes Mal fehlzuschlagen und ich frage mich, ob ich diese Tabelle zu meiner WP-Datenbank hinzufügen sollte, wenn das das Problem behebt oder es einen Fehler in meinem Code gibt, den ich gerade nicht sehe.

<?php 
 
$servername = "localhost"; 
 
$username = "DBusername"; 
 
$password = "DBpassword"; 
 
$database = "DBname"; 
 

 
// Create connection 
 
$conn = new mysqli($servername, $username, $password); 
 

 
$db_selected = mysqli_select_db($conn, $database); 
 
       
 
$userid = $current_user->user_login; 
 
$sql = "SELECT * FROM 'member-status' WHERE 'Card' = '$userid'"; 
 
$result = mysqli_query($conn, $sql); 
 
if ($result) { 
 
    list($userid) = mysqli_fetch_array(mysqli_query($result)); 
 
} else { 
 
    echo "query failed"; 
 
} 
 
       
 
if (mysqli_connect_errno($conn)) 
 
{ 
 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
 
} 
 

 
?> 
 
<?php 
 
\t while ($row = mysqli_fetch_assoc("$sql")) 
 
?> 
 
<div class="Disclaimer_webpage"> 
 
<?php echo $row["Disclaimer_WebPage"]; ?> 
 
</div> 
 

 
<div class="OuterBlock"> 
 
    
 
    <div class="oneblock"> 
 
    <ul> 
 
     <li>LAST</li> 
 
     <li><?php echo $row["Last"]; ?></li> 
 
    </ul> 
 
    <ul> 
 
     <li>FIRST</li> 
 
     <li><?php echo $row["First"]; ?></li> 
 
    </ul> 
 
    <ul> 
 
     <li>CARD</li> 
 
     <li><?php echo $row["Card"]; ?></li> 
 
    </ul> 
 
    <ul> 
 
     <li>CLASS</li> 
 
     <li><?php echo $row["Class"]; ?></li> 
 
    </ul> 
 
    </div> 
 
    
 
    
 
    
 
    <div class="secblock"> 
 
    <ul> 
 
     <li>DATE SIGNED BOOK</li> 
 
     <li> 
 
\t <?php \t if ($row['StartDate']!=""){ \t \t echo date('m/d/y', strtotime($row["StartDate"])); \t } ?> 
 
     </li> 
 
    </ul> 
 
    <ul> 
 
     <li>OUT OF WORK DATE</li> 
 
     <li> 
 
\t <?php if($row['CURROOWD']!=""){ \t echo date('m/d/y', strtotime($row["CURROOWD"])); \t } ?> 
 
     </li> 
 
    </ul> 
 
    <ul> 
 
     <li>DISPATCH UNIT</li> 
 
     <li><?php echo $row["OriginalUnit"]; ?></li> 
 
    </ul> 
 
\t <ul> 
 
     <li>DAYS DISPATCHED (OF 140)</li> 
 
     <li><?php echo $row["DAYS140"]; ?></li> 
 
    </ul> 
 
    </div> 
 
    
 
    <div class="over_all_list_position"> 
 
    <ul> 
 
     <li><b>OVER ALL LIST POSITION</b><span class="information_Icon"><img src="http://redsealcreative.com/clients/353-members/wp-content/plugins/IBEWJOBLISTS/Info.png" > <p class="imgDescription">Your position on the Out of Work List.</p></span><span class="see_below"> (*see below)</span></li> 
 
     <li><?php echo $row["ListPosition"]; ?></li> 
 
\t \t \t \t \t \t 
 
\t \t </ul> 
 
\t \t <ul> 
 
\t \t \t <li><b>UNIT LIST POSITION</b><span class="information_Icon1"><img src="http://redsealcreative.com/clients/353-members/wp-content/plugins/IBEWJOBLISTS/Info.png" > <p class="imgDescription1">Your list position relative only to members in your Dispatch Unit.</p><span></li> 
 
\t \t \t \t \t \t \t <li><?php echo $row["LISTPOS_UNIT"]; ?></li> 
 
\t \t \t \t \t </ul> 
 
\t \t <ul> 
 
\t \t \t <li><b>OPG LIST POSITION</b><span class="information_Icon2"><img src="http://redsealcreative.com/clients/353-members/wp-content/plugins/IBEWJOBLISTS/Info.png" > <p class="imgDescription2">Your list position relative only to those with current OPG Security Clearance.</p><span></li> 
 
\t \t \t \t \t \t \t <li><?php echo $row["LISTPOS_OPG"]; ?></li> 
 
\t \t \t \t \t </ul> 
 
\t </div> 
 
\t 
 
\t <div class="fothblock"> 
 
\t <ul> 
 
\t \t <li>PASSES</li> 
 
\t \t <li>NORTH UNIT</li> 
 
\t \t <li>SOUTH UNIT</li> 
 
\t \t <li>EAST UNIT</li> 
 
\t </ul> 
 
\t <ul> 
 
\t \t <li>ACCUMULATED</li> 
 
\t \t <li><?php echo $row["PassNorthAcc"]; ?></li> 
 
\t \t <li><?php echo $row["PassSouthAcc"]; ?></li> 
 
\t \t <li><?php echo $row["PassEastAcc"]; ?></li> 
 
\t </ul> 
 
\t <ul> 
 
\t \t <li>MAXIMUM</li> 
 
\t \t <li><?php echo $row["PassNorthMax"]; ?></li> 
 
\t \t <li><?php echo $row["PassSouthMax"]; ?></li> 
 
\t \t <li><?php echo $row["PassEastMax"]; ?></li> 
 
\t </ul> 
 
\t \t \t 
 
\t </div> 
 
\t 
 
\t <div class="sixblock"> 
 
\t <ul> 
 
\t \t <li>LAST OUT WORK DATES DISPATCHED</li> 
 
\t \t <li>NORTH</li> 
 
\t \t <li>SOUTH</li> 
 
\t \t <li>EAST</li> 
 
\t \t <li>OUT OF TOWN</li> 
 
\t </ul> 
 
\t <ul> 
 
\t \t <li class="padding-top"></li> 
 
\t \t <li class="padding-top"><?php if($row['LOOWDN']!=""){echo date('m/d/y', strtotime($row["LOOWDN"])); }?></li> 
 
\t \t <li><?php if($row['LOOWDS']!=""){ echo date('m/d/y', strtotime($row["LOOWDS"])); } ?></li> 
 
\t \t <li class="padding-top"><?php if($row['LOOWDE']!=""){echo date('m/d/y', strtotime($row["LOOWDE"]));} ?></li> 
 
\t \t <li><?php if($row['OOTOOWD']!=""){echo date('m/d/y', strtotime($row["OOTOOWD"]));} ?></li> 
 
\t </ul> 
 
\t </div> 
 
\t 
 
\t <div class="seven"> 
 
\t <ul> 
 
\t \t <li>LAST UPDATED</li> 
 
\t </ul> 
 
\t <ul> 
 
\t \t <li class="padding-top"><?php echo $row["TIME_STAMP"]; ?></li> 
 
\t </ul> 
 
\t </div> 
 
\t 
 
</div> 
 

 
<div class="Disclaimer_POL"> 
 
<?php echo $row["Disclaimer_POL"]; ?> 
 
</div>

Alle Einsicht dankbar geschätzt wird. Vielen Dank im Voraus für die Unterstützung der Gemeinden für ein neues Mitglied. :)


UPDATE # 2 AUSGABE RESOLVED

Ich bin glücklich, zu verkünden, dass ich das Problem herausgefunden. Für alle anderen, die diese Aufgabe erfüllen wollen, ist der Arbeitscode, den ich verwendet habe.

<?php global $current_user; 
wp_get_current_user(); ?> 

<?php 
// $mydb = new wpdb('username','password','database','localhost'); 
//$mydb->show_errors(); 
$userid = $current_user->user_login; 
$result = $wpdb->get_results("SELECT * FROM member_status WHERE CARD = $userid"); 
// $query = "SELECT * FROM member_status WHERE CARD = $userid"; 
// $result = $mydb->get_results($query); 

?> 
<?php foreach ($result as $query) {?> 
Then to call the individual fields/column data add this code where you want it located 

<?php echo $query->ColumnName; ?> //Change ColumnName to the column you want to call from. 

Ich hoffe, dass dies für Sie praktisch ist, alle :)

Antwort

0

Ich bin glücklich, zu verkünden, dass ich das Problem herausgefunden. Für alle anderen, die diese Aufgabe erfüllen wollen, ist der Arbeitscode, den ich verwendet habe.

<?php global $current_user; 
wp_get_current_user(); ?> 

<?php 
// $mydb = new wpdb('username','password','database','localhost'); 
//$mydb->show_errors(); 
$userid = $current_user->user_login; 
$result = $wpdb->get_results("SELECT * FROM custom_table WHERE Column = $userid"); 
// $query = "SELECT * FROM custom_table WHERE Column = $userid"; 
// $result = $mydb->get_results($query); 

?> 
<?php foreach ($result as $query) {?> 

Dann werden die einzelnen Felder nennen/Spaltendaten fügen Sie diesen Code, wo Sie es

<?php echo $query->ColumnName; ?> //Change ColumnName to the column you want to call from. 

gelegen Ich möchte hoffen, dass dies für Sie praktisch ist, alle :)

Verwandte Themen