dropfaith Posted March 11, 2017 Share Posted March 11, 2017 so i know this is an easy one i just cant recall how or what to search to make it work been a bit since ive coded php right now it does everything needed but im trying to clean up the display a bit the echo line just loops the tr and tds endlessly to the left and right What im going for would be more like this Current Result <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> Result i need <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> and so on Code below $sql = "SELECT * FROM hashtag"; if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_array($result)){ echo "<td><h1>" . $row['text'] . "</h1><img src=" . $row['link'] . "></td>"; } // Free result set mysqli_free_result($result); } else{ echo "No records matching your query were found."; } } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } right now Quote Link to comment Share on other sites More sharing options...
gizmola Posted March 11, 2017 Share Posted March 11, 2017 I'm not clear on the criteria for emitting a new . With that said, if it's simply a fixed number of rows per table row, then you want to add a simple counter and then the modulus. For example: $i = 0; echo '<tr>'; while($row = mysqli_fetch_array($result)){ $i++; if ($i % 4 == 0) { // End/Start new Table Row echo '</tr>'; echo '<tr>'; } echo "<td><h1>" . $row['text'] . "</h1><img src=" . $row['link'] . "></td>" } // Close final TR echo '</tr>'; Quote Link to comment 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.