Home > Software engineering >  Echo new result in Bootstrap Row
Echo new result in Bootstrap Row

Time:07-26

I have 3 items in the the DB, and I am trying to echo each item out in to its own bootstrap column. However, when I run the code it gets all but puts them in to the same column. I want each item to be echo'ed in to its own col-md-2 so that I can have them listed across the page, rather than in one column.

 $sql = "SELECT advertiser_URL, advertiser_logo  FROM advertisers";
if ($result = mysqli_query($link, $sql))
{
    if (mysqli_num_rows($result) > 0)
    {

        while ($row = mysqli_fetch_array($result))
        {
            echo "<div class=row>";
            echo "<div class=col-md-2><a href= " . $row['advertiser_URL'] . "><img src='data:image/jpeg;base64," . base64_encode($row['advertiser_logo']) . "'/></div>";
            echo "</div>";

        }

    }
    else
    {
        echo "No records matching your query were found.";
    }
}
else
{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

CodePudding user response:

if ($result = mysqli_query($link, $sql))
{
    if (mysqli_num_rows($result) > 0)
    {
        echo "<div class=row>";
        while ($row = mysqli_fetch_array($result))
        {
            echo "<div class=col-md-2><a href= " . $row['advertiser_URL'] . "><img src='data:image/jpeg;base64," . base64_encode($row['advertiser_logo']) . "'/></div>";
        }
        echo "</div>";

    }
    else
    {
        echo "No records matching your query were found.";
    }
}
else
{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

CodePudding user response:

I saw that "" is missing in the classes

you can try this way:

echo '<div >';
while ($row = mysqli_fetch_array($result)){
   echo '<div >
           <a href= " '. $row['advertiser_URL'] . '">
              <img src="data:image/jpeg;base64,"' . base64_encode($row['advertiser_logo']) .' "/>
           </a>
        </div>';
}
 echo "</div>";

or using bootstrap example:

echo '<table >
         <tr>';
while ($row = mysqli_fetch_array($result)){
   echo '  
         <td scope="col">
            <a href= " '. $row['advertiser_URL'] . '">
               <img src="data:image/jpeg;base64,"' . base64_encode($row['advertiser_logo']) .' "/>
            </a>
         </td>';
}
   echo "  </tr>
   </table>";
  • Related