Values plus each other

Is there any possible way to have the total of my sql row. I have made a table named: Info, in that table I have a row that is called: Bedragperperiode. I want sql to get every filled data in the row (Bedragperperiode), and show it on a wegpage(plus each other).

What you are calling a row is actually a column.

https://www.mysqltutorial.org/mysql-sum/

I have tried this, but it didn’t work.
<input type="text" value="<?php mysqli_query($db,"SELECT SUM('Bedragperperiode') FROM 'Info'"); ?>">

The single quotes are not right in SQL. They are only used for text values. Backticks (`) are used for table and column names but may be omitted (except if the name is a mysql keyword too).

SELECT SUM(Bedragperperiode) FROM Info

I have changed it to this now:
<input type="text" value="<?php mysqli_query($db, "SELECT SUM(Bedragperperiode) FROM Info") ?>">
But it is still not working…

But it is still not working…

What does that mean? What is happening or not happening? Do you get any errors? Do you have error reporting on?

I have made a new code, it is showing me the value 8 now. Because I have 8 id’s. But it doesn’t give me the total of the column.
I will paste it here:

<?php include ('betalingen.php'); $db = mysqli_connect(xxx); $resultaat = mysqli_query($db,"SELECT SUM('Bedragperperiode') as Bedragperperiode FROM Info"); $regel = $resultaat->fetch_array(MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Overzichtbetalingen</title>
    <link rel="stylesheet" type="text/css" href="overzichtbetalingen.css">
</head>
<body>
<div style="text-align: center">
    <button onclick="window.location.href='xxx'">Startpagina</button>
</div>
<table>
    <thead>
        <tr>
            <th>Naam</th>
            <th>Pand</th>
            <th>Datum betaling</th>
            <th>Hoe word er betaald</th>
            <th>Bankrekening</th>
            <th>Betalingsperiode</th>
            <th>Bedrag per periode</th>
        </tr>
    </thead>
    <tbody>
    <?php while ($row = mysqli_fetch_array($results)){?>
        <tr>
            <td><?php echo $row['Naam']?></td>
            <td><?php echo $row['Pand']?></td>
            <td><?php echo $row['Datum']?></td>
            <td><?php echo $row['Betaling']?></td>
            <td><?php echo $row['Bank']?></td>
            <td><?php echo $row['Betalingsperiode']?></td>
            <td><?php echo $row['Bedragperperiode']?></td>
            <?php } ?>
        </tr>
    </tbody>
</table>
<div>
<input type="text" value="<?php echo $regel['Bedragperperiode']; ?>">
</div>
<button class="knop" onclick="window.location = ('xxx') ">Betaling toevoegen</button>
</body>
</html>

Try:

<?php echo $regel[0]['Bedragperperiode']; ?>

Now it is showing nothing…

How about using the column you stated at the start of the thread?

Your column naming should either use under scores or camel case to separate the words making up the name so that they are easier to read and less likely to have typo errors.

Bedragpermaand needs to be: Bedragperperiode. I have edited it now.

In the last query you posted, you put single-quotes back in, around the column name. This is causing the SUM() to add up TRUE (1) values.

What do I need to change now?

Sponsor our Newsletter | Privacy Policy | Terms of Service