vendredi 21 août 2020

If....elseif works but how can I make this neater or do it better?

I've been working on a membership system for a cycle club, not being conversant with PHP and MySql this has taken me around 6 months but it works. One important job is to generate lists from the data to send to the printer showing who gets newsletters, membership cards, reminders etc so i've used if....elseif statements for all the conditions. Here's one example, it seems to me that the inner conditions re the number of membership cards, which are used four times and are always the same, could be done better. I've tried (without success so far) to turn that into a function that I could call. Constructive criticism and/or advice welcomed

// New member had card in membership pack in D list - send printed card with this journal. COMMENT OUT if hand written card is ok for year
elseif ($firstchar == 'D' && $row[joined] >= $joinPeriodBeginD && $row[source] != 'Renewal') {
    $row[journal] = 'Yes';
    $row[action] = $action;

    *//if-elseif to count HH members and adjust number of cards sent
    $row[card] == $card
    if (empty($row[h_name1])) {
        $row[card] == $card;
    } elseif ($row[h_name1] !== "" && empty($row[h_name2]) && empty($row[h_name3])) {
        $row[card] = $card1HH;
    } elseif ($row[h_name1] !== "" && $row[h_name2] !== "" && empty($row[h_name3])) {
        $row[card] = $card2HH;
    } elseif ($row[h_name1] !== "" && $row[h_name2] !== "" && $row[h_name3] !== "") {
        $row[card] = $card3HH;
    } //end if elseif*

    $table_output .= "<td>" . $row[action] . "</td>";
    $table_output .= "<td class=\"card\">" . $row[card] . "</td>";
    $table_output .= "<td>" . $row[journal] . "</td>";
}enter code here

Aucun commentaire:

Enregistrer un commentaire