简体   繁体   中英

how select data from table and print

I looked but now nothing, there is some way to select something from a table.

For example:

two text boxes number1 and number2 and enter 10 and 20, then print all records in a table from register 10 to 20.

It is possible to do with

$query = "SELECT * FROM crm_vendas WHERE venda_id BETWEEN 'number1' and '$ number2'";

and also with

while ($ row =?

if someone can indicate something or help I would appreciate it

You need to use prepared statements. Also, you do not put backticks around the entire query line. The i's in the bind_param line indicated that the two variables you're using are integers.

    $number1 = 0;
    $number2 = 100;
    $query = "SELECT * FROM crm_vendas WHERE venda_id BETWEEN ? AND ?";
    $stmt = $db->prepare($query);
    $stmt->bind_param('ii', $number1, $number2);
    $stmt->execute();
    $result = $stmt->get_result();

    echo '<table>';
    while ($row = $result->fetch_row()) {
        echo '<tr>';
        foreach($row as $columnValue){
            echo '<td><p>'.$columnValue.'</p></td>';
        }
        echo '</tr>';
    }
    echo '</table>';

    $result->close();
    $stmt->close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM