Split SQL data into two responsible columns

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 282
Location: Holland Rotterdam

Split SQL data into two responsible columns

I want to update my notice-board into two column, but i searching for day`s how to complete this...
How can i split this SQL code into two columns for DESC LIMIT off 15 rows.

Code: Select all

<?php
include('../connection.php');

$sql=mysqli_query($conn,"SELECT * FROM `notice_second` ORDER BY `notice_second`.`notice_id` DESC LIMIT 15");

$rehtm='';
// if the $sql contains at least one row
if(mysqli_num_rows($sql) >0){
  //get rows data
  while($row = mysqli_fetch_assoc($sql)){
    $rehtm .='
<img class="img-circle" src="'. $row['poster_picture'] .'"  width="50" height="50"/>'. $row['from_who'] .'
Title: '. $row['subject'] .'<br><br>'. $row['Description'] .'<br><br>
<b>My Mood:</b> '. $row['user_mood'] .''. $row['Date'] .'<br><br> ';
  }
}
else {
  $rehtm .='0 results';
}

echo $rehtm;?>

Admin Posts: 805
Try to put the each notice in Div:

Code: Select all

$sql=mysqli_query($conn,"SELECT * FROM `notice_second` ORDER BY `notice_second`.`notice_id` DESC LIMIT 16");

$rehtm='';
// if the $sql contains at least one row
if(mysqli_num_rows($sql)>0){
  while($row = mysqli_fetch_assoc($sql)){
    $rehtm .='<div class="d_cols">
<img class="img-circle" src="'. $row['poster_picture'] .'"  width="50" height="50"/>'. $row['from_who'] .'
Title: '. $row['subject'] .'<br><br>'. $row['Description'] .'<br><br>
<b>My Mood:</b> '. $row['user_mood'] .' '. $row['Date'] .'</div>';
  }
}
else $rehtm .='0 results';

echo '<div id="d_notice">'. $rehtm .'</div>';
Then, set the way to display in CSS:

Code: Select all

#d_notice {
margin:8px auto;
text-align:center;
width:100%;
}
#d_notice .d_cols {
display:inline-block;
text-align:left;
width:48%;
}
2. Or, in this way, each group of notice into a <span>, and a <br> after each second span:

Code: Select all

$sql=mysqli_query($conn,"SELECT * FROM `notice_second` ORDER BY `notice_second`.`notice_id` DESC LIMIT 16");

$rehtm='';
// if the $sql contains at least one row
if(mysqli_num_rows($sql)>0){
  $i =0;
  while($row = mysqli_fetch_assoc($sql)){
    $i++;
    $rehtm .='<span class="d_cols">
<img class="img-circle" src="'. $row['poster_picture'] .'"  width="50" height="50"/>'. $row['from_who'] .'
Title: '. $row['subject'] .'<br><br>'. $row['Description'] .'<br><br>
<b>My Mood:</b> '. $row['user_mood'] .' '. $row['Date'] .'</span>';
    if(($i%2)==0) $rehtm .='<br>';
  }
}
else $rehtm .='0 results';

echo '<div id="d_notice">'. $rehtm .'</div>';