mysql update mit hilfe einer zweiten tabelle



  • hi,

    habe folgenden sql befehl:

    habe auf meinem lokalen rechner mysql 4.1.8 laufen.

    update products_data set status = '1' where products_id in (select products_id from products)

    fehlermeldung sagt aus, dass es kein supplied argument ist.

    ab mysql 4.0 sollten solche abfragen doch gehen?

    ich will halt alle datensätze in products_data mit status = 1 setzen, wo products_data eine products_id hat, die auch in products vorkommt.

    kann jemand nen fehler finden?



  • update products_data pd, products p set pd.status = 1 where pd.products_id = p.products_id



  • hi,

    es gibt immer noch probleme, aber ehr mit mysql_row_affected:

    <?
    include "config.inc.php";
    
    $res = mysql_db_query($db_name, "update products_data pd, products p set pd.status = '1' where pd.products_id = p.products_id");
    
    if ($res == FALSE)
    {
      echo "error";
      exit;
    }
    else
    {
      echo mysql_affected_rows($res);
      exit;
    }
    ?>
    

    Die Fehlermeldung:

    Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\update\finishing.php on line 13

    Kommt die mysql_affected_rows Funktion damit oder bin ich nur blind?

    phil



  • mach es mal ohne $res

    Es fehlt aber auch der Part wo du die verbindung aufbaust.
    http://de.php.net/manual/de/function.mysql-affected-rows.php
    Da siehst du was der Befehl erwartet.



  • Falls der Fehler immer noch bestehen sollte: Lass dir mal mysql_error() ausgeben - normalerweise bekommst du dann einen hilfreichen Hinweis 😉


Anmelden zum Antworten