Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL subquery returning more than one result
    primarykey
    data
    text
    <p>Does someone figures out a way to make this code works even when <strong>MySQL subquery</strong> returns more than one result? It is working fine when the user has no event related to him, or when the user has one event related to him, but when a <strong>user is related to more than one event</strong>, the subquery returns more than one result and than the code gets nothing to work with.</p> <pre><code>$stmt = $db-&gt;prepare("SELECT * FROM events WHERE id_events = ( SELECT id_events FROM relationship_events WHERE id_user = ?)"); $stmt-&gt;bindParam(1, $idUser); $stmt-&gt;execute(); $rawTimeStamps = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC); $cleanDateArray = array(); foreach ($rawTimeStamps as $t) { $rawDate = $t['start']; $rawDate = getdate($rawDate); $cleanDate = mktime(0,0,0,$rawDate['mon'],$rawDate['mday'],$rawDate['year']); $cleanDateArray[] = $cleanDate; } for($list_day = 1; $list_day &lt;= $days_in_month; $list_day++): $calendar.= '&lt;td class="calendar-day"&gt;'; $timestamp = mktime(0,0,0,$month,$list_day,$year); if (!empty($cleanDateArray) &amp;&amp; in_array($timestamp, $cleanDateArray)) { $date = getdate($timestamp); $time_start = mktime(0,0,0,$date['mon'],$date['mday'],$date['year']); $time_end = mktime(23,59,59,$date['mon'],$date['mday'],$date['year']); $stmt = $db-&gt;prepare('SELECT title FROM events WHERE start BETWEEN ? AND ?'); $stmt-&gt;bindParam(1,$time_start,PDO::PARAM_INT); $stmt-&gt;bindParam(2,$time_end,PDO::PARAM_INT); $stmt-&gt;execute(); $events = $stmt-&gt;fetch(PDO::FETCH_ASSOC); $calendar.= '&lt;div class="day-number day-number-event"&gt;&lt;a href="#"&gt;'.$list_day.'&lt;/a&gt;&lt;/div&gt;&lt;p&gt;'.$events["title"].'&lt;/p&gt;'; } else { $calendar.= '&lt;div class="day-number day-number-noevent"&gt;'.$list_day.'&lt;/div&gt;&lt;div id="calendar-events"&gt;&lt;/div&gt;'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload