PHP - Code only giving one value from Mysql database, while it should give more -


i have piece of code executes calendar. on calendar names have appear. however, on each date appears 1 name, while in database dates hold 20 names.

this image should clarify things: http://imgur.com/a31pj0s

in image can see each date, on of them 1 name. stated before, of these contain many more names.

now, understand why not work, executes once, how can work? please me out :)

here link same piece of code, except easier read: http://codepad.org/tvszhdtx

<?php     $j = 2;     $i = 1;     //query database      $query = mysql_query("select * months");      //fetch results / convert results array     echo '<div class="accordion" id="calendar">';     while($rows = mysql_fetch_array($query)) {         $month = $rows['month'];         $id = $rows['id'];          echo '         <div class="accordion-group">             <div class="accordion-heading" id="month_'.$id.'">                 <a class="accordion-toggle" data-toggle="collapse" data-parent="#calendar" href="#monthsid'.$id.'">                 '.$month.'                 </a>             </div>             <div id="monthsid'.$id.'" class="accordion-body collapse">                 <div class="accordion-inner">';          $n = $rows['num_of_days'];         echo '<ul class="list-group" id="'.$id.'" style="margin-bottom: 0;">';          ($i = 1; $i <= $n; $i++) {             if ($j == 7) {                 echo '<li class="list-group-item" id="'.$i.'" style="margin-bottom: 5px;">';             } else {                 echo '<li class="list-group-item" id="'.$i.'">';             }                 echo '<a data-toggle="modal" href="#mymodal" class="add_member" id="'.$month.' '.$i.'">+</a>                     <span class="badge">'.$i.'</span>';              if ($i == date("j")) {                 echo '<div class="day_segment current_day">';             } else {                 echo '<div class="day_segment">';             }              if ($j == 1) {                 echo '<i style="color: #aaa;">'.$i.' |</i> monday';                 $j++;             } else if ($j == 2) {                 echo '<i style="color: #aaa;">'.$i.' |</i> tuesday';                 $j++;             } else if ($j == 3) {                 echo '<i style="color: #aaa;">'.$i.' |</i> wednesday';                 $j++;             } else if ($j == 4) {                 echo '<i style="color: #aaa;">'.$i.' |</i> thursday';                 $j++;             } else if ($j == 5) {                 echo '<i style="color: #aaa;">'.$i.' |</i> friday';                 $j++;             } else if ($j == 6) {                 echo '<i style="color: #aaa;">'.$i.' |</i> saturday';                 $j++;             } else if ($j == 7) {                 echo '<i style="color: #aaa;">'.$i.' |</i> sunday';                 $j = 1;             }             echo '</div>';               $posts_query = mysql_query("select * posts day=$i ");              while ($rows_items = mysql_fetch_array($posts_query)) {                 $entry_player = $rows_items['author'];                 $entry_comment = $rows_items['comment'];                 $entry_day = $rows_items['day'];                 $entry_month = $rows_items['month'];             }             ($k = 1; $k <= 1; $k++) { /* tried using loop, did not work */                 if ($id == $entry_month && $i == $entry_day) {                     echo '<span class="label label-success" data-toggle="tooltip" rel="tooltip" title="'.$entry_comment.'">'.$entry_player.'</span>';                 } else {                     echo '<span class="label"></span>';                 }             }             echo '</li>';         }           echo '                     </ul>                 </div>             </div>         </div>          ';     } /* end while loop */     echo '</div></div>';  ?> 

as mentioned in comments, should not use mysql_ functions deprecated , not secure. use mysqli or pdo instead.

to answer question, code block below reason why displays 1 entry per day. in while loop, overwrite 4 variables each time, last 1 displayed in loop. loop not necessary.

while ($rows_items = mysql_fetch_array($posts_query)) {     $entry_player = $rows_items['author'];     $entry_comment = $rows_items['comment'];     $entry_day = $rows_items['day'];     $entry_month = $rows_items['month']; } ($k = 1; $k <= 1; $k++) { /* tried using loop, did not work */     if ($id == $entry_month && $i == $entry_day) {         echo '<span class="label label-success" data-toggle="tooltip" rel="tooltip" title="'.$entry_comment.'">'.$entry_player.'</span>';     } else {         echo '<span class="label"></span>';     } } 

try changing code this:

while ($rows_items = mysql_fetch_array($posts_query)) {     $entry_player = $rows_items['author'];     $entry_comment = $rows_items['comment'];     $entry_day = $rows_items['day'];     $entry_month = $rows_items['month'];      if ($id == $entry_month && $i == $entry_day) {         echo '<span class="label label-success" data-toggle="tooltip" rel="tooltip" title="'.$entry_comment.'">'.$entry_player.'</span>';     } else {         echo '<span class="label"></span>';     } } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -