Hi
I'm so confused about use of php loop inside body in CC.
if I use loop (eg for) outside of <tr> tag it double repeats everything.if i use loop inside <td> tag in table it repeats all fields in each row instead of assign each value to corresponded row.
what's the solution?
do lot nhap khau, annie, do boi nu, thoi trang tre em, thoi trang be trai, do dung cho me sau sinh, thoi trang cong so, vay lien cong so, ban buon quan ao, do lot[/url]
this is my code.
I'm so confused about use of php loop inside body in CC.
if I use loop (eg for) outside of <tr> tag it double repeats everything.if i use loop inside <td> tag in table it repeats all fields in each row instead of assign each value to corresponded row.
what's the solution?
do lot nhap khau, annie, do boi nu, thoi trang tre em, thoi trang be trai, do dung cho me sau sinh, thoi trang cong so, vay lien cong so, ban buon quan ao, do lot[/url]
this is my code.
<?php
$db = mysql_connect("localhost", "joomla", "123456");
mysql_select_db('joomla');
$query="select distinct(cf_id),tip,HG from jos_chronoforms_betslip ";
$result = mysql_query($query);
$num = mysql_num_rows($result);
?>
<tr dir='ltr'>
<td>{cat}</td>
<td>{recordtime}</td>
<td>{game}</td>
<td>
<?php
for($i = 0; $i < $num; $i ++)
{
$t_rows = mysql_fetch_row($result);
if ( $t_rows[2]=='1')
{
echo "{host}";
} else {
echo "{guest}";
}
}
?>
</td>
<td>{tip}</td>
<td>{win}</td>
<td>{loss}</td>
<td>{ex1}</td>
<td>{odd}</td>
<td>
<?php
echo $t_rows[10];
/*
if ( $t_rows[10]=='full' || $t_rows[10]=='Over/Under')
{
echo "{ftga}-{ftgb}";
} else {
echo "{htga}-{htgb}";
}
*/
?>
</td>
<td>{stats}</td>
</tr>
Hi
I appreciate a simple example of how to use loop(for,foreach,...) inside chronoconnectivity body area
I appreciate a simple example of how to use loop(for,foreach,...) inside chronoconnectivity body area
Hi mja1356,
I think that the loop code is repeated for each record identified by the WHERE clause.
By adding your own database query inside the loop it will be repeated for each record.
So, basically - don't use a for each inside the loop!
Bob
I think that the loop code is repeated for each record identified by the WHERE clause.
By adding your own database query inside the loop it will be repeated for each record.
So, basically - don't use a for each inside the loop!
Bob
thanks Bob
But if i don't use any loop inside the code my variables repeat in all records.
look at this code:
$t_rows[0] and [1] repeat in all records with value of first record.
But if i don't use any loop inside the code my variables repeat in all records.
look at this code:
<?php
$db = mysql_connect("localhost", "joomla", "123456");
mysql_select_db('joomla');
$query="select HG,tip from jos_chronoforms_betslip ";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$t_rows = mysql_fetch_row($result);
?>
<tr dir='ltr'>
<td>{cat}</td>
<td>{recordtime}</td>
<td>{game}</td>
<td>
<?php
if ( $t_rows[0]=='1')
{
echo "{host}";
} else {
echo "{guest}";
}
?>
</td>
<td>{tip}</td>
<td>{win}</td>
<td>{loss}</td>
<td>{ex1}</td>
<td>{odd}</td>
<td>
<?php
echo $t_rows[1];
/*
if ( $t_rows[1]=='ft' || $t_rows[1]=='Over/Under')
{
echo "{ftga}-{ftgb}";
} else {
echo "{htga}-{htgb}";
}
*/
?>
</td>
<td>{stats}</td>
</tr>
$t_rows[0] and [1] repeat in all records with value of first record.
Hi mja1356,
As I said "By adding your own database query inside the loop it will be repeated for each record."
That's exactly what is happening. You need to do your databse lookup using the WHERE box outside the loop. Or if you need to check a second database table (I don't think that you do) then do that in the header.
Bob
PS For security please use Joomla database code.
As I said "By adding your own database query inside the loop it will be repeated for each record."
That's exactly what is happening. You need to do your databse lookup using the WHERE box outside the loop. Or if you need to check a second database table (I don't think that you do) then do that in the header.
Bob
PS For security please use Joomla database code.
Hi
I didn't understand your post reply , yes CC use a loop.and that problem solved.
but another problem.
I use this code in body area
the $host variable change in every record and works fine but the if condition doesn't work.
I mean in record that $host=2 the elseif statement doesn't work and write 'hi' in output.
I didn't understand your post reply , yes CC use a loop.and that problem solved.
but another problem.
I use this code in body area
<?php
$host='{HG}';
echo $host;
if ($host=1)
echo 'hi';
elseif ($host=2)
echo 'bye';
?>
the $host variable change in every record and works fine but the if condition doesn't work.
I mean in record that $host=2 the elseif statement doesn't work and write 'hi' in output.
Hi
sorry for repeating my problem๐ ๐ ๐ but probably i must declare it clearer.
this is my code in body area
my problem is that if statement doesn't work .I mean when I echo $host variable it changes in every record in output but it doesn't execute php code inside if statement.
I can do this with CF very easily but because i have many records in DB i need CC pagination to limit output.
anyway can i use some kind of pagination in CF?๐คจ
sorry for repeating my problem๐ ๐ ๐ but probably i must declare it clearer.
this is my code in body area
<tr dir='ltr'>
<td>{cat}</td>
<td>{recordtime}</td>
<td>{game}</td>
<td>
<?php
$host="{HG}";
echo $host;
if ($host=2)
echo 'hi';
elseif ($hoost=1)
echo 'bye';
?>
</td>
<td>{tip}</td>
<td>{win}</td>
<td>{loss}</td>
<td>{ex1}</td>
<td>{odd}</td>
<td>
<?php
$tip='{tip}';
echo $tip;
if ( $tip=='ft' || $tip=='Over/Under')
{
echo '{ftga}-{ftgb}';
} else {
echo '{htga}-{htgb}';
}
?>
</td>
<td>{stats}</td>
</tr>
my problem is that if statement doesn't work .I mean when I echo $host variable it changes in every record in output but it doesn't execute php code inside if statement.
I can do this with CF very easily but because i have many records in DB i need CC pagination to limit output.
anyway can i use some kind of pagination in CF?๐คจ
This topic is locked and no more replies can be posted.
