I have a single mysql table with 3 fields id, num, diff. There multiple entries for each num from 1 to 56, and each entry showing a different number for the diff column. I am wanting to count the number of times a number appears in the diff column for each number. I created a script to count how many entries for each number 1=56 there are. Example Ball1 appeared, skipped 1 drawing and reappeared on 5 different occasions( 1 would appear 5 different times in the num column and 1 would appear 5 different times in the diff column),it appeared, skipped 2 drawing and reappeared on 6 different occasions( Attached image). I can't get the chart to show 0 when it should. On my attachment you will see Ball 6 on top and 1 on left intersect with 1 in the box; that should be 0. Ball 6 never skipped 1 time and rertuned. How can I make 0 appear there. Here is the code I am using:
Print "<table border=1 height=75 width=400 cellpadding=0 valign=center bgcolor= #999999 >";
Print "<tr align=center valign=middle style=font-size:14px;color:blue; >";
Print "<th></th><th>01</th><th>02</th><th>03</th><th>04</th><th>05</th><th>06</th><th>07</th><th>08</th><th>09</th><th>10</th><th>11</th><th>12</th><th>13</th><th>14</th><th>15</th><th>16</th><th>17</th><th>18</th><th>19</th><th>20</th><th>21</th><th>22</th><th>23</th><th>24</th><th>25</th><th>26</th><th>27</th><th>28</th><th>29</th><th>30</th><th>31</th><th>32</th><th>33</th><th>34</th><th>35</th><th>36</th><th>37</th><th>38</th><th>39</th><th>40</th><th>41</th><th>42</th><th>43</th><th>44</th><th>45</th><th>46</th><th>47</th><th>48</th><th>49</th><th>50</th><th>51</th><th>52</th><th>53</th><th>54</th><th>55</th><th>56</th><br><br>";
Print "</tr>\n";
Print "<tr align=center valign=middle style=font-size:14px;>";
for($b=1;$b<=56;$b++){
Print "<th><font color=#FFFFFF>$b</font></th>";
$rs2 = mysql_query("select num,diff,count(diff) as mycount from ccc where ( diff = $b ) group by num,diff order by id");
while ($row2 = mysql_fetch_array($rs2)) {
$mycount2 = $row2['mycount'];
Print "<td> <font color=#000000>$mycount2</font></td>";
}
Print "</tr>\n";
}
Print "</table>";
Return 0 when no count not found
Moderator: General Moderators
Re: Return 0 when no count not found
Not sure what results you are getting, but I am assuming that for some results, the value returned for mycount is NULL, so you are probably getting the following in the source:
(no actual value).
Change the last line of your code in the while loop to be:
Which will force the $mycount2 to be cast as an integer, so if it is blank, it will cast as 0
-Greg
Code: Select all
<td><font color=#000000></font></td>Change the last line of your code in the while loop to be:
Code: Select all
Print "<td> <font color=#000000>" . (int)$mycount2 . "</font></td>";-Greg
Re: Return 0 when no count not found
Thanks Greg, I tried your suggestion and did the following:Print "<td> <font color=#000000>".(int)$mycount2."</font></td>"; ,but the result is still the same; it shows 1 where there should be 0.
Re: Return 0 when no count not found
Can you put a copy of the VIEW SOURCE (from browser) you get from the generated table (before and now)?