dynamic table limiter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

dynamic table limiter

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

this line

Code: Select all

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

Code: Select all

if ($field_name == 'Article') &#123;
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

thats better

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

try

Code: Select all

echo substr($field_name&#1111;'Article'],0,50);
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

GREAT

Post by reiqwan »

Thanks man you're a star, I should've noticed that.
Post Reply