Example #1
0
function print_deck_select_table($table, $attributes, $constraints)
{
    array_push($attributes, "id");
    #array_push($attributes, "delete");
    #var_dump($constraints);
    $attr_list_str = implode(', ', $attributes);
    $query = "SELECT {$attr_list_str} FROM {$table}";
    if (!empty($constraints)) {
        $cons_str = mysql_where_str($constraints);
        $query .= " WHERE {$cons_str}";
    }
    #$query .= ";";
    $query .= " ORDER BY name;";
    #print_msg($query);
    $result = mysql_query($query);
    $num = @mysql_numrows($result);
    print_msg("total = {$num}");
    if ($num == 0) {
        return;
    }
    echo "<table>";
    echo "<tr>";
    array_push($attributes, "delete");
    foreach ($attributes as $attr) {
        if ($attr != "id") {
            echo "<th>";
            echo $attr;
            echo "</th>";
        }
    }
    echo "</tr>";
    $i = 0;
    while ($i < $num) {
        $id = mysql_result($result, $i, "id");
        echo "<tr id=\"{$id}\">";
        foreach ($attributes as $attr) {
            if ($attr == "delete") {
                echo "<td>";
                echo "<button name=\"{$id}\">delete</button>";
                echo "</td>";
            } else {
                if ($attr != "id") {
                    $value = mysql_result($result, $i, $attr);
                    echo "<td>";
                    if ($attr == "link") {
                        echo "<a href=\"{$value}\">";
                        echo $value;
                        echo "</a>";
                    } else {
                        echo mysql_result($result, $i, $attr);
                    }
                    echo "</td>";
                }
            }
        }
        echo "</tr>";
        $i++;
    }
    echo "</table>";
}
Example #2
0
function print_card_select_table($table, $attributes, $constraints)
{
    #var_dump($constraints);
    $attr_list_str = implode(', ', $attributes);
    $query = "SELECT {$attr_list_str} FROM {$table}";
    if (!empty($constraints)) {
        $cons_str = mysql_where_str($constraints);
        $query .= " WHERE {$cons_str}";
    }
    $query .= ";";
    #print_msg($query);
    $result = mysql_query($query);
    $num = @mysql_numrows($result);
    print_msg("total = {$num}");
    if ($num == 0) {
        return;
    }
    echo "<table>";
    echo "<tr>";
    foreach ($attributes as $attr) {
        echo "<th>";
        echo $attr;
        echo "</th>";
    }
    echo "</tr>";
    $i = 0;
    while ($i < $num) {
        echo "<tr>";
        foreach ($attributes as $attr) {
            echo "<td>";
            echo mysql_result($result, $i, $attr);
            echo "</td>";
        }
        echo "</tr>";
        $i++;
    }
    echo "</table>";
}