Jump to content
New Reality: Ads For Members ×

Displaying mysqli_fetch_array on multiple lines


mangolinux

Recommended Posts

I am trying to get my query results to display each result separtlly on its own line.

Here is my code:

<?php
include("dbinfo.inc.php");
$query = "SELECT * FROM boc";
$result = mysqli_query($con, $query);

/* fetch associative array */
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
    //Assign variables
    $post_id = $row['post_id'];
    $date = $row['date'];
    $type = $row['type'];
    $title = $row['title'];
    $content = $row['content']; 

}
?>
 
 <?php

echo "$date - <a href=\"viewnotice.php?id={$post_id}\"'>{$title}</a>";
/* free result set */
    mysqli_free_result($result);

mysqli_close($con);
?>

 

 

This currently displays the results like this

09-04-2015 - Rescheduling Board of Commissioners Meeting 09-04-2015 - September Committee Meetings

 

I would like it to display like this

09-04-2015 - Rescheduling Board of Commissioners Meeting

09-04-2015 - September Committee Meetings

 

Thanks

Do within the while loop.

<?php
include("dbinfo.inc.php");
$query = "SELECT * FROM boc";
$result = mysqli_query($con, $query);

/* fetch associative array */
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
    //Assign variables
    $post_id = $row['post_id'];
    $date = $row['date'];
    $type = $row['type'];
    $title = $row['title'];
    $content = $row['content']; 

echo "$date - <a href='viewnotice.php?id=".$post_id."'>".$title."</a><br />";

}


/* free result set */
    mysqli_free_result($result);

mysqli_close($con);
?>

Archived

This topic is now archived and is closed to further replies.



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