Page 1 of 1

dynamic table limiter

Posted: Tue Feb 01, 2005 6:11 am
by reiqwan
Hi all;

Can someone please help me in regards to a dynamic table;

I have a dynamic table which calls the info from a database and then lists all the columns in the specified table using an array.

What I need to do is the following: when it finds an specific column name it needs to perform a substr function on that columns information.

My code to output the dynamic table looks like this so far:

<?php
for($y=0; $y < $dbfield_num; $y++) {
$field_name = mysql_field_name($dbfields, $y);

echo('<td align="left"><span class="c2">'.$row_Recordset1[$field_name].'</span></td>');

}
echo('</tr>');
}
echo('</table></td></tr>');
?>

That works fine in displaying all the information in the specific field but for instance if I try something like this:


<?php
for($y=0; $y < $dbfield_num; $y++) {
$field_name = mysql_field_name($dbfields, $y);

echo('<td align="left"><span class="c2">');

if ($field_name = 'Article') {
substr($Recordset1['Article'],0,50);
}
else
{
echo $row[$field_name];
}
echo ("</span></td>");

}
echo('</tr>');
}
echo('</table></td></tr>');
?>

It doesnt show anything in the table; I'm confused 'cos my thinking is that if it finds the column called 'Article' it will then do the main part of the if statement but I seem to be wrong cos ts not doing this maybe my understanding of the array is incorrect.

Any help would be appreciated

Posted: Tue Feb 01, 2005 6:13 am
by JayBird
this line

Code: Select all

if ($field_name = 'Article') &#123;
should be...

Code: Select all

if ($field_name == 'Article') &#123;

thats better

Posted: Tue Feb 01, 2005 6:40 am
by reiqwan
Howzit going that seems to be better but the only problem now is that its not showing anything in the article field; would you know why so all the other colmns show info but the article column is empty even though there's data in the table for it.

this is the code for it

Code: Select all

if ($field_name == 'Article') &#123;
	substr($field_name&#1111;'Article'],0,50);
	&#125;
	else
	&#123;
	  echo $row&#1111;$field_name];
	  &#125;
Is there something I'm missing ?

Thanks again

Posted: Tue Feb 01, 2005 6:42 am
by JayBird
try

Code: Select all

echo substr($field_name&#1111;'Article'],0,50);

GREAT

Posted: Tue Feb 01, 2005 6:49 am
by reiqwan
Thanks man you're a star, I should've noticed that.