mikelmao Posted September 10, 2010 Share Posted September 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213091-next-value-in-the-database/ Share on other sites More sharing options...
mikosiko Posted September 10, 2010 Share Posted September 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213091-next-value-in-the-database/#findComment-1109775 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.