Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Bild in Wordpress mit PHP-Code anzeigen

Ich bevorzuge wirklich die folgende Codestruktur. Übrigens haben Sie in Ihrem Code nicht angegeben, was die Spalte für die URL des Bildes ist, also gehe ich in meinem folgenden Code-Stück davon aus, dass es ist:Image_URL

Bitte achten Sie auf die Verwendung der Methode $wpdb->prepare zur Bereinigung der Abfrageparameter. Und achten Sie auf die Methode esc_attr im Image-Tag.

[insert_php]
global $wpdb;
$pr = get_the_title();
$results = $wpdb->get_results($wpdb->prepare("SELECT * from print_drug where Product_Name = %s", $pr));
foreach ($results as $obj) {
    echo "<em><strong>Product Name:</strong></em> {$obj->Product_Name}<br>
        <em><strong>Active Substance:</strong></em> {$obj->Active_Substance}<br>
        <em><strong>Substance Sorting Identification Number:</strong></em> {$obj->Substance_Sorting_Identification_Number}<br>
        <em><strong>Production Form of Use:</strong></em> {$obj->Production_Form_of_Use}<br>
        <em><strong>Chemical Formation:</strong></em> {$obj->Chemical_Formation}<br>
        <em><strong>Dosages of Use:</strong></em> {$obj->Dosages_of_Use}<br>
        <em><strong>Approval Agency:</strong></em> {$obj->Approval_Agency}<br>
        <em><strong>Year of Approval:</strong></em> {$obj->Year_of_Approval}<br>
        <em><strong>Approval Assigned Company:</strong></em> {$obj->Approval_Assigned_Company}<br>
        <em><strong>Approval Country:</strong></em> {$obj->Approval_Country}<br>
        <em><strong>Prohibited Cases:</strong></em> {$obj->Prohibited_Cases}<br>
        <image src='".esc_attr($obj->Image_URL)."'>";
}
[/insert_php]