SQL Abfrage mit gleichen Werten

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • SQL Abfrage mit gleichen Werten

    Hallo,

    Ich steh gerade vor einem Problem.

    Quellcode

    1. $DB->set_sql('SELECT p.*, w.* FROM
    2. ' . COW . ' AS p,
    3. ' . VOW . ' AS w
    4. WHERE p.v_product_id = w.id
    5. AND p.customer_id =:1');
    6. $DB->execute($customer_id);
    7. while ($row = $DB->fetch_assoc()) {
    8. $row['created_at'] = $Core->userdate($row['created_at']);
    9. if ( $row['activ'] == 2 ) {
    10. $row['activ'] = '<a href="customer.php?page=show&id={$CUSTOMER_ID}&reaktiv_id={$list.vid}" title=""><img src="./theme/img/control.png"></a>';
    11. }
    12. else
    13. {
    14. $row['activ'] = '<a href="customer.php?page=show&id={$CUSTOMER_ID}&deaktiv_id={$list.vid}" title=""><img src="./theme/img/control-pause.png"></a> <a href="customer.php?page=show&id={$CUSTOMER_ID}&del_id={$list.vid}" title=""><img src="./theme/img/cross.png"></a>';
    15. }
    16. $vcontracts[] = $row;
    17. }
    Alles anzeigen


    Je nach VOW Status (activ 2 oder eine andere zahl) sol er ein Entsprechendes Bild ausgeben. Problem ist nun allerding, in beiden Tabellen kommt activ vor. Wie kann ich dies in der IF Abfrage unterscheiden bzw. angeben das er dies aus VOW Werten soll?
  • Moin!

    Die einfachste Lösung wäre meines Erachtens nach, wenn du das activ Feld aus der gewünschten Tabelle als alias sperat selectest. Also z.B:

    Quellcode

    1. $DB->set_sql('SELECT p.*, w.*, w.activ as w_activ FROM
    2. ' . COW . ' AS p,
    3. ' . VOW . ' AS w
    4. WHERE p.v_product_id = w.id
    5. AND p.customer_id =:1');
    6. if ($row['w_activ'] == 2) {
    7. ...
    8. }



    Hope that helps. Viele Grüße!
    Bodo06