Thread Verfasser: Catzenjaeger
Thread ID: 898
Thread Info
Es gibt 7 Beiträge zu diesem Thema, und es wurde 2566 Mal angesehen.
 Thema drucken
Königsklasse Inner joins :)
Catzenjaeger
Will meine latest figures panel noch bisschen pimpen und noch die Ratings der entsprechenden Figur einbauen. Die Joins sind schon so umfangreich das ich hier echt am knobbeln bin wie ich das mache. Momentan habe ich das nur über einen variable mache aber noch nicht steuern kann das eindeutig erkannt wird welche Figur zu welchen Ratin gehört

Bis jetzt habe ich wie erwähnt nur geschafft das ein Voting angezeigt wird ... aber bei der falschen Figur. Ich will natürlich zu jeder das entsprechend haben. Ich weiss allerdings nicht wie das zuteile weil ich ja hier kein so Kritierium wie "WHERE rating_item_id='".$data['figure_id']."' AND rating_type='B'"));" habe.

Hier mal der Panelcode

Code
<?php
/***************************************************************************
 *   Cat Latest Figure Panel                                                   *
 *                                                                         *
 *   Copyright (C) 2016 Catzenjaeger                                       *
 *   www.aliencollectors.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
if(!defined('IN_FUSION')) {
   die;
}
if(file_exists(INFUSIONS."cat_latest_figures_panel/locale/".$settings['locale'].".php"))
{
   include(INFUSIONS."cat_latest_figures_panel/locale/".$settings['locale'].".php");
} else {
   include(INFUSIONS."cat_latest_figures_panel/locale/German.php");
}

include INFUSIONS."figurelib/infusion_db.php";

$result = dbquery(
"SELECT tb.figure_id, tb.figure_image, tb.figure_pubdate, tb.figure_title, tb.figure_manufacturer, tb.figure_brand, tb.figure_datestamp, tb.figure_cat, tbc.figure_cat_id, tbc.figure_cat_access, tbu.user_id, tbu.user_name, tbu.user_status, tbu.user_avatar, tbm.figure_manufacturer_name, tbb.figure_brand_name, tbs.figure_scale_name FROM ".DB_PREFIX."figure_items tb
LEFT JOIN ".DB_USERS." tbu ON tb.figure_name=tbu.user_id
INNER JOIN ".DB_PREFIX."figure_cats tbc ON tb.figure_cat=tbc.figure_cat_id
INNER JOIN ".DB_PREFIX."figure_manufacturers tbm ON tbm.figure_manufacturer_id = tb.figure_manufacturer
INNER JOIN ".DB_PREFIX."figure_brands tbb ON tbb.figure_brand_id = tb.figure_brand
INNER JOIN ".DB_PREFIX."figure_scales tbs ON tbs.figure_scale_id = tb.figure_scale
".(iSUPERADMIN ? "" : "WHERE ".groupaccess('figure_cat_access'))." ORDER BY figure_datestamp DESC LIMIT 0,10");
 
 opentable($locale['CLFP_000']);
 if (dbrows($result) != 0) {
 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
 echo "<colgroup><col width='8%'><col width='20%'><col width='20%'></colgroup><col width='2%'></colgroup><col width='10%'></colgroup><col width='10%'></colgroup><col width='10%'></colgroup>\n";
 echo "<tr>";
 echo "<td class='side-small'><strong>Image</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_002']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_003']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_004']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_005']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_006']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_010']."</strong></td>";
 echo "</tr>";
 while($data = dbarray($result)){

 echo "<tr>";
   if ($data['figure_image'] == "") {
      echo "<td class='side-small'><a href='".INFUSIONS."figurelib/figure.php?figure_id=".$data['figure_id']."' class=''>\n<img src='".INFUSIONS."figurelib/images/default.png"."' alt='".trimlink($data['figure_title'],100)."' title='".trimlink($data['figure_title'],100)."' style='border:0px;max-height:40px;max-width:40px' /></td>";

         } else {   
      echo "<td class='side-small'><a href='".INFUSIONS."figurelib/figure.php?figure_id=".$data['figure_id']."' class=''>\n<img src='".($data['figure_image'] ? IMAGES_FIGURE.$data['figure_image'] : INFUSIONS."figurelib/images/default.png")."' alt='".trimlink($data['figure_title'],100)."' title='".trimlink($data['figure_title'],100)."' style='border:0px;max-height:40px;max-width:40px' /></td>";
          }
 echo "<td class='side-small'><a href='".INFUSIONS."figurelib/figure.php?figure_id=".$data['figure_id']."'>".trimlink($data['figure_title'], 15)."</a></td>";
 echo "<td class='side-small'>".trimlink($data['figure_manufacturer_name'],15)."</td>";
 echo "<td>".trimlink($data['figure_brand_name'],15)."</td>";
 echo "<td>".trimlink($data['figure_scale_name'],15)."</td>";
 //WENN KEIN WERT IN DB DANN ZEIGE HINWEIS "NO DATA"
   if ($data['figure_pubdate'] == "") {
         echo "<td>".$locale['CLFP_008']."</td>";
         } else {
         echo "<td>".$data['figure_pubdate']."</td>";
         }         
 

 }
 echo "</td>";
 
 $drating = dbarray(dbquery("SELECT SUM(rating_vote) sum_rating, COUNT(rating_item_id) count_votes FROM ".DB_RATINGS." WHERE rating_type='B'"));
                     $num_votes = $drating['count_votes'];
                     $rating = ($num_votes > 0 ? str_repeat("<img src='".INFUSIONS.$inf_folder."/images/star.png'>",ceil($drating['sum_rating']/$num_votes)) : "-");
                     $cell_color = ($i % 2 == 0 ? "tbl1" : "tbl2"); $i++;
echo "<td>".$rating."</td>";

 echo "</tr>";
 echo "</table>";
 } else {
 echo "<div style='text-align: center;'>".$locale['CLFP_001']."</div>";
 }
 closetable();
 
 ?>


-----------------------------------------------

Zusammengefügt am 24. Mai 2016 um 10:23:04:
habe frustriert aufgegeben.

habe es so probiert:

Datenbankabfrage/Inner join

Zitat: $result = dbquery(
"SELECT tb.figure_id, tb.figure_image, tb.figure_pubdate, tb.figure_title, tb.figure_manufacturer, tb.figure_brand, tb.figure_datestamp, tb.figure_cat, tbc.figure_cat_id, tbc.figure_cat_access, tbu.user_id, tbu.user_name, tbu.user_status, tbu.user_avatar, tbm.figure_manufacturer_name, tbb.figure_brand_name, tbs.figure_scale_name, tbr.rating_votes FROM ".DB_PREFIX."figure_items tb
LEFT JOIN ".DB_USERS." tbu ON tb.figure_name=tbu.user_id
INNER JOIN ".DB_PREFIX."figure_cats tbc ON tb.figure_cat=tbc.figure_cat_id
INNER JOIN ".DB_PREFIX."figure_manufacturers tbm ON tbm.figure_manufacturer_id = tb.figure_manufacturer
INNER JOIN ".DB_PREFIX."figure_brands tbb ON tbb.figure_brand_id = tb.figure_brand
INNER JOIN ".DB_PREFIX."figure_scales tbs ON tbs.figure_scale_id = tb.figure_scale
INNER JOIN ".DB_RATINGS." tbr ON tbr.rating_item_id = tb.figure_id WHERE rating_type='B'
".(iSUPERADMIN ? "" : "WHERE ".groupaccess('figure_cat_access'))." ORDER BY figure_datestamp DESC LIMIT 0,5");


UND UNTEN DANN

Zitat:  $num_votes = $data['count_votes'];
$rating = ($num_votes > 0 ? str_repeat("<img src='".INFUSIONS.$inf_folder."/images/star.png'>",ceil($data['sum_rating']/$num_votes)) : "-");
echo "<td class='side-small'>".$rating."</td>";


------------------------

ich verzweifle bald ... ich bekomme nicht mal das Ergebniss der Spalte $data['rating_vote'] angezeigt.

Die DB Abfrage schein fast richtig weil es werden nur 2 figuren angezeigt .. nämlich die wo votings vorhanden sind. Ich benötige aber alle und nur das Votingsergebnis.

Zitat: $result = dbquery(
"SELECT tb.figure_id, tb.figure_image, tb.figure_pubdate, tb.figure_title, tb.figure_manufacturer, tb.figure_brand, tb.figure_datestamp, tb.figure_cat, tbc.figure_cat_id, tbc.figure_cat_access, tbu.user_id, tbu.user_name, tbu.user_status, tbu.user_avatar, tbm.figure_manufacturer_name, tbb.figure_brand_name, tbs.figure_scale_name, tbr.rating_vote, tbr.rating_type, tbr.rating_item_id FROM ".DB_PREFIX."figure_items tb
LEFT JOIN ".DB_USERS." tbu ON tb.figure_name=tbu.user_id
INNER JOIN ".DB_PREFIX."figure_cats tbc ON tb.figure_cat=tbc.figure_cat_id
INNER JOIN ".DB_PREFIX."figure_manufacturers tbm ON tbm.figure_manufacturer_id = tb.figure_manufacturer
INNER JOIN ".DB_PREFIX."figure_brands tbb ON tbb.figure_brand_id = tb.figure_brand
INNER JOIN ".DB_PREFIX."figure_scales tbs ON tbs.figure_scale_id = tb.figure_scale
INNER JOIN ".DB_RATINGS." tbr ON tbr.rating_item_id = tb.figure_id AND tbr.rating_type='B'
".(iSUPERADMIN ? "" : "WHERE ".groupaccess('figure_cat_access'))." ORDER BY figure_datestamp DESC LIMIT 0,5");

Bearbeitet von Catzenjaeger am 24.05.2016 um 18:39
 
David
Warum lässt du nicht innerhalb der While-Schleife die Voting Ergebnisse auslesen und zeigst diese an?
Liebe Grüße, David Smile

PHP-Fusion Österreich
 
Catzenjaeger
??? da es kommt ja nicht mal ein ergebnis zurück.. ich will einfach sofern ein voting zur figur vorhanden dieses erstmal angezeigt bekommen (das ist in der DB Ratings ja nur einen Zahl. Die muss dann entsprechend in Sterne umgerechnet werden Smile

Ich habe es auch mit LEFT Join probiert .. ging auch nicht. Ich versteh halt nicht warum ich nicht mal ein wert bekommen. Ich sehe kein fehler mehr in der Abfrage
 
David
Wieso nicht einfach so?

Code
<?php
/***************************************************************************
 *   Cat Latest Figure Panel                                                   *
 *                                                                         *
 *   Copyright (C) 2016 Catzenjaeger                                       *
 *   www.aliencollectors.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
if(!defined('IN_FUSION')) {
   die;
}
if(file_exists(INFUSIONS."cat_latest_figures_panel/locale/".$settings['locale'].".php"))
{
   include(INFUSIONS."cat_latest_figures_panel/locale/".$settings['locale'].".php");
} else {
   include(INFUSIONS."cat_latest_figures_panel/locale/German.php");
}

include INFUSIONS."figurelib/infusion_db.php";

$result = dbquery(
"SELECT tb.figure_id, tb.figure_image, tb.figure_pubdate, tb.figure_title, tb.figure_manufacturer, tb.figure_brand, tb.figure_datestamp, tb.figure_cat, tbc.figure_cat_id, tbc.figure_cat_access, tbu.user_id, tbu.user_name, tbu.user_status, tbu.user_avatar, tbm.figure_manufacturer_name, tbb.figure_brand_name, tbs.figure_scale_name FROM ".DB_PREFIX."figure_items tb
LEFT JOIN ".DB_USERS." tbu ON tb.figure_name=tbu.user_id
INNER JOIN ".DB_PREFIX."figure_cats tbc ON tb.figure_cat=tbc.figure_cat_id
INNER JOIN ".DB_PREFIX."figure_manufacturers tbm ON tbm.figure_manufacturer_id = tb.figure_manufacturer
INNER JOIN ".DB_PREFIX."figure_brands tbb ON tbb.figure_brand_id = tb.figure_brand
INNER JOIN ".DB_PREFIX."figure_scales tbs ON tbs.figure_scale_id = tb.figure_scale
".(iSUPERADMIN ? "" : "WHERE ".groupaccess('figure_cat_access'))." ORDER BY figure_datestamp DESC LIMIT 0,10");
 
 opentable($locale['CLFP_000']);
 if (dbrows($result) != 0) {
 echo "<table cellpadding='0' cellspacing='0' width='100%'>";
 echo "<colgroup><col width='8%'><col width='20%'><col width='20%'></colgroup><col width='2%'></colgroup><col width='10%'></colgroup><col width='10%'></colgroup><col width='10%'></colgroup>\n";
 echo "<tr>";
 echo "<td class='side-small'><strong>Image</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_002']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_003']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_004']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_005']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_006']."</strong></td>";
 echo "<td class='side-small'><strong>".$locale['CLFP_010']."</strong></td>";
 echo "</tr>";
 while($data = dbarray($result)){

    echo "<tr>";
     if ($data['figure_image'] == "") {
        echo "<td class='side-small'><a href='".INFUSIONS."figurelib/figure.php?figure_id=".$data['figure_id']."' class=''>\n<img src='".INFUSIONS."figurelib/images/default.png"."' alt='".trimlink($data['figure_title'],100)."' title='".trimlink($data['figure_title'],100)."' style='border:0px;max-height:40px;max-width:40px' /></td>";
     } else {   
       echo "<td class='side-small'><a href='".INFUSIONS."figurelib/figure.php?figure_id=".$data['figure_id']."' class=''>\n<img src='".($data['figure_image'] ? IMAGES_FIGURE.$data['figure_image'] : INFUSIONS."figurelib/images/default.png")."' alt='".trimlink($data['figure_title'],100)."' title='".trimlink($data['figure_title'],100)."' style='border:0px;max-height:40px;max-width:40px' /></td>";
     }
    echo "<td class='side-small'><a href='".INFUSIONS."figurelib/figure.php?figure_id=".$data['figure_id']."'>".trimlink($data['figure_title'], 15)."</a></td>";
    echo "<td class='side-small'>".trimlink($data['figure_manufacturer_name'],15)."</td>";
    echo "<td>".trimlink($data['figure_brand_name'],15)."</td>";
   echo "<td>".trimlink($data['figure_scale_name'],15)."</td>";

   // WENN KEIN WERT IN DB DANN ZEIGE HINWEIS "NO DATA"
   if ($data['figure_pubdate'] == "") {
      echo "<td>".$locale['CLFP_008']."</td>";
   } else {
      echo "<td>".$data['figure_pubdate']."</td>";
   } 

   // Bewertung
   $drating = dbarray(dbquery("SELECT SUM(rating_vote) sum_rating, COUNT(rating_item_id) count_votes FROM ".DB_RATINGS." WHERE rating_type='B' AND  rating_item_id='".$data['figure_id']."'"));     
   $rating = ($drating['count_votes'] > 0 ? str_repeat("<img src='".INFUSIONS.$inf_folder."/images/star.png'>",ceil($drating['sum_rating']/$drating['count_votes'])) : "-");
   echo "<td>".$rating."</td>";

   echo "</tr>";
 }
 echo "</table>";
 } else {
 echo "<div style='text-align: center;'>".$locale['CLFP_001']."</div>";
 }
 closetable();
 
 ?>


Mache das selbst auch immer so ..
Liebe Grüße, David Smile

PHP-Fusion Österreich
 
Catzenjaeger
Geht leider nicht .. es werden gar keinen Figuren mehr angezeigt im Panel
 
David
Im Prinzip sollte dass eig garkeine Auswirkung darauf haben, da ich den Code nur in die While-Abfrage eingefügt habe. Würde mal sagen, deine Abfrage ist Fehlerhaft, hab die aus dem ersten Post genommen.
Liebe Grüße, David Smile

PHP-Fusion Österreich
 
Catzenjaeger
geht wieder danke .. vielen Dank
Bearbeitet von Catzenjaeger am 26.05.2016 um 17:32
 
Springe ins Forum: