Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2009
    Thanked 1 Time in 1 Post

    Create new table for each unique id

    Hi guys, have a problem I am struggling with. I have a database table which contains the fields

    id - PK
    alert_id - FK
    letter - Char
    number - int(11)
    last_updated - Timestamp

    Sql query to select the data is just a basic select
    $sql = "SELECT * FROM `alert_availability`;
    The problem is, for each unique alert_id, I need the data displayed in a new html table. Each table should take the form of
    table 1 <---alert_id
                                        A       B        C      <----letter
    01:00am  <--last_updated            3       2        5      <----number
    02:00am                             5       4        0
    table 2 <---alert_id
                                        F       T       R      <----letter
    01:00<--last_updated                2       5       6      <----number
    How can something like this be achieved? My other script is running on a cron job, so each alert will be updated basically every hour. The letter will always stay the same, but the numbers can change. I need to show this change, which is why I give it a new row. I can get information displaying in one table, but not to sure how to do a new table for each unique alert_id, and how to display the data as I need it.

    Any advice appreciated as always.


  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    You simply keep track of the last alert id and break the table whenever it changes. You need to ensure the query is sorted by the alert_id as well.
    PHP Code:
    $lastid null;
    while (
    $row $qry->fetch_assoc())
        if (
    $lastid != $row['alert_id'])
            if (
    $lastid != null)
    $lastid $row['alert_id'];
    //. . .
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts