Jump to content

checkbook balance scripting


phppup
 Share

Recommended Posts

Yes, MCONTE, both of those seem to work, but apparently mysqli_insert_id($link); works ONLY during an INSERT and not as a method to SELECT (independent of an INSERT in the same script).

Barand, I have a simple table being displayed row by row that is giving me results from other script efforts.  Didn't want to waste space by posting it.

            echo "</tr>";
        while($row = mysqli_fetch_array($result)){
            echo "<tr>";
                echo "<td>" . $row['id'] . "</td>";
                echo "<td>" . $row['first_name'] . "</td>";
                echo "<td>" . $row['last_name'] . "</td>";
                echo "<td>" . $row['email'] . "</td>";

 

Edited by phppup
Link to comment
Share on other sites

16 minutes ago, mconte said:

"explain persons;"

Do you mean "describe persons"?

NM - I see they do the same thing

mysql> describe pup;
+------------------+--------------+------+-----+---------+----------------+
| Field            | Type         | Null | Key | Default | Extra          |
+------------------+--------------+------+-----+---------+----------------+
| id               | int(11)      | NO   | PRI | NULL    | auto_increment |
| name             | varchar(20)  | YES  |     | NULL    |                |
| amount           | decimal(8,2) | YES  |     | NULL    |                |
| transaction_date | datetime     | YES  |     | NULL    |                |
+------------------+--------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)

mysql> explain pup;
+------------------+--------------+------+-----+---------+----------------+
| Field            | Type         | Null | Key | Default | Extra          |
+------------------+--------------+------+-----+---------+----------------+
| id               | int(11)      | NO   | PRI | NULL    | auto_increment |
| name             | varchar(20)  | YES  |     | NULL    |                |
| amount           | decimal(8,2) | YES  |     | NULL    |                |
| transaction_date | datetime     | YES  |     | NULL    |                |
+------------------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

I only ever used explain with queries, not tables.

Edited by Barand
Link to comment
Share on other sites

Field            Type    Null   Key  Default   Extra
id              int(11)    NO    PRI   NULL   auto_increment
first_name  varchar(30)    NO          NULL
last_name   varchar(24)    NO          NULL
email       varchar(70)    NO    UNI   NULL
sum             int(11)    NO          NULL

Persons is a simple table made up of some simple columns:  id, first_name, last_name, email, sum.

 

Edited by phppup
Link to comment
Share on other sites

Works fine for me

mysql> select * from pup;
+----+-------+--------+---------------------+
| id | name  | amount | transaction_date    |
+----+-------+--------+---------------------+
|  1 | Curly |  10.00 | 2020-01-01 10:00:00 |
|  2 | Larry |  20.00 | 2020-01-15 12:30:00 |
|  3 | Mo    |  15.00 | 2020-02-01 09:00:00 |
|  4 | Peter |  -5.00 | 2020-02-01 10:30:00 |
|  5 | Paul  |  10.00 | 2020-02-02 11:30:00 |
|  6 | Mary  |   5.00 | 2020-02-02 12:15:00 |
+----+-------+--------+---------------------+
6 rows in set (0.00 sec)

mysql> select MAX(id) as maxid FROM pup;
+-------+
| maxid |
+-------+
|     6 |
+-------+
1 row in set (0.01 sec)

or

<?php
    $res = $conn->query("SELECT MAX(id) as maxid FROM pup");
    $row = $res->fetch_assoc();
    echo $row['maxid'];               //--> 6
?>

 

Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.