Jump to content

Recommended Posts

Hey,

  How do i (If this is even possible) get the next value in the database using mysql fetch assoc?

i use the MySQLi extension... There are 2 colums in the that table. Date and Name.. I need it to display the next date and next name the mysql fetch assoc will get.. this is my script:

<?php
$today = date("dmY");
$con = new mysqli('******', '****', '*****', '*****');
$getDates = $con->query('SELECT * FROM `trabalho` ORDER BY `data` DESC');
$total = 0;
while($trabalho = $getDates->fetch_assoc()) {
    $thisDate = date("dmY", strtotime($trabalho['data']));
    $thisShowDate = date("d/m/Y", strtotime($trabalho['data']));
    if($lastDate != $thisDate) {
        echo '<table border=1 style="border-collapse: collapse; border-style: solid; border-width: 1px;">';
        echo '<tr><th>Data</th><th>Name</th><th>test</th></tr>';
    }
    echo '<tr><td>'. $thisShowDate .'</td><td>'. $trabalho['name'] .'</td></tr>';
    $total = $total + $trabalho['horas'];
    if($lastDate != $thisDate) {
        echo '<tr><td>Total</td><td colspan=2 style="text-align: right">'. $total .'</td></tr>';
        echo '</table>';
        $total = 0;
    }
    $lastDate = date("dmY", strtotime($trabalho['data']));
}

 

But in the last

    if($lastDate != $thisDate) {

the $thisDate variable should be $nextDate, $nextDate is the date of the next column its going to fetch.

 

If you dont know thanks anyways for reading.

Link to comment
https://forums.phpfreaks.com/topic/213091-next-value-in-the-database/
Share on other sites

I know that mysql extension have the mysql_data_seek() function that possible could solve the issue...

 

the mysqli equivalent is mysqli_stmt_data_seek ... never used/tested it myself... you can look the manual and see if will work for you

 

http://www.php.net/manual/en/mysqli-stmt.data-seek.php

 

other option could be load the data in an array using your while loop and process the array after that

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.