Jump to content

Displaying mysqli_fetch_array on multiple lines


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);
?>
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.