Link to home
Start Free TrialLog in
Avatar of Zeke Rich
Zeke RichFlag for United States of America

asked on

PHP assign array with if statement

Hello i need to loop this array but when 'CAL_6' => if($j==7){echo "</tr><tr>";$j=0;}      i need it to echo </tr> Im getting a error right now:

Parse error: syntax error, unexpected T_IF in /home/vinay/public_html/ims/plugins/reception/reception.leads.php on line 128


//////// Starting of the days//////////
for($i=1;$i<=$no_of_days;$i++){
$cal_4= $adj."<td valign=top><font size='2' face='Tahoma'><a href=''>$i</a><br>"; // This will display the date inside the calendar cell
$cal_5= " </font></td>";
$adj='';
$j ++;

				$t->assign(array(
				'CAL_4' => $cal_4,
				'CAL_5' => $cal_5,
				'CAL_6' => if($j==7){echo "</tr><tr>";$j=0;}	
				));
				$t->parse('MAIN.CAL_GROUP2');
				
				
}

Open in new window

Avatar of Zeke Rich
Zeke Rich
Flag of United States of America image

ASKER

Ok i got it working with this, but it is only counting to 7 and not resetting $j=0


//////// Starting of the days//////////
for($i=1;$i<=$no_of_days;$i++){
$cal_4= $adj."<td valign=top><font size='2' face='Tahoma'><a href=''>$i</a><br>"; // This will display the date inside the calendar cell
$cal_5= " </font></td>";
$adj='';
$j ++;

if($j==7){
$cal_end_tr = "</tr><tr>";
$j=0;}	
				$t->assign(array(
				'CAL_4' => $cal_4,
				'CAL_5' => $cal_5,
				'CAL_6' => $cal_end_tr
				));
				$t->parse('MAIN.CAL_GROUP2');
				
				
}

Open in new window

SOLUTION
Avatar of vr6r
vr6r

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$j is working, this is for a calendar, after it counted the first 7 days it gives a </tr> to go to the next line like this:

Sun      Mon      Tue      Wed      Thu      Fri      Sat
              1       2       3     4      5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

Problem is it is placing to many TR's here is the results of the code:


<b>Sun</b></font></td><td><font face="Tahoma" size="3"><b>Mon</b></font></td><td><font face="Tahoma" size="3"><b>Tue</b></font></td><td><font face="Tahoma" size="3"><b>Wed</b></font></td><td><font face="Tahoma" size="3"><b>Thu</b></font></td><td><font face="Tahoma" size="3"><b>Fri</b></font></td><td><font face="Tahoma" size="3"><b>Sat</b></font></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td valign="top"><font face="Tahoma" size="2"><a href="">1</a><br>
				 </font></td>

				<td valign="top"><font face="Tahoma" size="2"><a href="">2</a><br>
				 </font></td>
				<td valign="top"><font face="Tahoma" size="2"><a href="">3</a><br>
				 </font></td>
				<td valign="top"><font face="Tahoma" size="2"><a href="">4</a><br>
				 </font></td>
				<td valign="top"><font face="Tahoma" size="2"><a href="">5</a><br>

				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">6</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">7</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">8</a><br>
				 </font></td>

				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">9</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">10</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">11</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">12</a><br>

				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">13</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">14</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">15</a><br>
				 </font></td>

				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">16</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">17</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">18</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">19</a><br>

				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">20</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">21</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">22</a><br>
				 </font></td>

				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">23</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">24</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">25</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">26</a><br>

				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">27</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">28</a><br>
				 </font></td>
				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">29</a><br>
				 </font></td>

				</tr><tr><td valign="top"><font face="Tahoma" size="2"><a href="">30</a>

Open in new window

I found the problem i was not clearing $cal_end_tr

It should have been= $cal_end_tr = "";


Thank you for your help sir.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial