Jump to content

Sysadmin20

New Members
  • Posts

    5
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Sysadmin20's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks. This is exactly what I found online, and it was working but only when I did a search using that search option i.e. within that buttons POST request code. <thead> <tr> <th>Date</th> <th>Number of clicks</th> </tr> </thead> <?php //new record $cont = 0; if ($result = $conn->query($sql)) { while ($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td>".$row['created_at']."</td>"; echo "<td>".$row['total']."</td>"; echo "</tr>"; //new record $cont += $row['total']; } } ?> <tfoot> <tr> <th style="text-align:right">Total number of clicks:</th> <!-- <th></th> --> <th><?php echo $cont; ?></th> </tr> </tfoot> </table> </div> This worked great. But as you can see above, the variable is within the PHP tags starting like this - <?php if(isset($_POST['search'])){ That means when I hit the search button, the total is working just fine. But when I first visit that page there are no post requests and by default I have an "else" query to show some default records like this - else{ $query=mysqli_query($conn, "SELECT created_at, count(*) AS total, number_click, DATE_ADD(LAST_DAY(created_at),INTERVAL 1 DAY) as 'first_date_of_month' FROM `records` WHERE DATE_FORMAT(created_at, '%Y-%m-%d') BETWEEN 'first_date_of_month' AND NOW() GROUP BY created_at ORDER BY created_at ASC") or die(mysqli_error()); while($fetch=mysqli_fetch_array($query)){ ?> <tr> <td><?php echo $fetch['created_at']?></td> <td><?php echo $fetch['total']?></td> </tr> This is where I'm having the problem. When I first load the site, it's throwing an "undefined variable" error because I'm not doing any button press. So I removed this variable from my code file for now. If it's not a trouble, can you take a look at https://pastebin.com/75FusdLJ and let me know how exactly I should define this variable so that the total number will be displayed even without a POST request?
  2. Hi @Barand Thanks for the reply. I know it's not formatted properly because I'm just using notepad for now until I get the functionalities right.. You;re right. I didn't check the query properly. Modified to - SELECT created_at, count(*) AS total, number_click, last_day( curdate() - interval 1 month ) + interval 1 day as 'first_date_of_month' FROM `records` WHERE DATE_FORMAT(created_at, '%Y-%m-%d') BETWEEN 'first_date_of_month' AND NOW() GROUP BY created_at ORDER BY created_at ASC and it's showing properly now - But in any case, SQL is not an issue here. I just need to create a new footer section to show the SUM of the total column. Any ideas?
  3. Hi guys So I have a table script and I'm fetching the records from a table. 1st column is a date 2nd column is an int There is a date search selection on top. So if I select a date range and list the records, it will filter and display the records. If I never do a date selection means it will show that months records by default - else{ $query=mysqli_query($conn, "SELECT created_at, count(*) AS total, number_click, DATE_ADD(LAST_DAY(created_at),INTERVAL 1 DAY) as 'first_date_of_month' FROM `records` WHERE DATE_FORMAT(created_at, '%Y-%m-%d') BETWEEN 'first_date_of_month' AND NOW() GROUP BY created_at ORDER BY created_at ASC") or die(mysqli_error()); while($fetch=mysqli_fetch_array($query)){ ?> <tr> <td><?php echo $fetch['created_at']?></td> <td><?php echo $fetch['total']?></td> </tr> and it's working great. Now what I want to do is, at the bottom, I want to show the SUM of 1 column.. For example - Over here, I want to show a text Total number of records : XX Need to replace the XX with the SUM of that 2nd column.. My coding is a little confusing and it's not a standard format because I'm still learning. I did some online research and I tried using this after the closing PHP tags defining a variable named $cont - <tfoot> <tr> <th style="text-align:right">Total number of clicks:</th> <!-- <th></th> --> <th><?php echo $cont; ?></th> </tr> </tfoot> It's working great but it's working only when I do a search using the search button because $cont; variable is defined within the PHP form code. So I if refresh the page I'm getting an error "undefined variable" and I'm not sure how to make it available outside the PHP code. If it makes it any easier, I've uploaded the code here - https://pastebin.com/75FusdLJ What I wanted to do now is, add a text after that table and show the total SUM of that 2nd column regardless of the Search button press. If anyone could share the modified version of the code or at least let me know which portion I should replace with which code I'd really appreciate that. Thanks.
  4. Thanks for the reply. I'm not sure if I can write that code but at least now I know what to research online. I'll give it a try. Thank you
  5. Hello friends, My name is Jay and I'm a sys admin and have very little experience with PHP and stuff. We have an internal system developed by a dev and I'm trying to make some changes to it and hoping if someone could help. So we have a simple results page which will fetch records from a MySQL table and display in table format. This is the code file - https://pastebin.com/VwxAVY9y I'm trying to add a delete button next to each records and delete those records dynamically. I don't need a warning or any prompt/confirmation etc. So I added a 3rd column as "<th>Action</th>" but I'm having a hard time incorporating the AJAX delete function within the echo "<td> </td>" section. I did quite a lot of google search and couldn't figure this out. What I want is a colum with a delete button like this attached screenshot. Any help is appreciated Cheers Jay
×
×
  • 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.