msaz87 Posted May 2, 2009 Share Posted May 2, 2009 Hi all, I'm new to PHP and was hoping to do the following: I wanted to set up a page with a few different variables. One of the variables would specify the number of identical HTML tables are shown on the page -- and number them sequentially. In other words, it would be something like this: <? $number_of_tables = 4; $table = "<table id="xx">xxx</table"; echo $tables ?> So the $number_of_tables would specify how many of $table are shown and the table's ID would be numbered according to how many there are... IE: if there's 8 tables, it would go <table id="1">, <table id="2"> ... <table id="8"> Hopefully that makes sense.. and if anyone can help or point me in the right direction, I'd really appreciate it! Thanks so much! Link to comment https://forums.phpfreaks.com/topic/156490-using-variables-to-create-and-name-html-tables/ Share on other sites More sharing options...
hchsk Posted May 2, 2009 Share Posted May 2, 2009 do you mean rows of the table? or the actual entire table, or are you using it as a div. and you are missing a closing > Link to comment https://forums.phpfreaks.com/topic/156490-using-variables-to-create-and-name-html-tables/#findComment-824056 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Without further information, this is the best I can do: <?php $number_of_tables = 4; $tables = ''; for ($e = 1; $e <= $number_of_tables; $e++) { $tables .= '<table id="' . $e . '"></table>'; } echo $tables; Link to comment https://forums.phpfreaks.com/topic/156490-using-variables-to-create-and-name-html-tables/#findComment-824064 Share on other sites More sharing options...
msaz87 Posted May 2, 2009 Author Share Posted May 2, 2009 Without further information, this is the best I can do: <?php $number_of_tables = 4; $tables = ''; for ($e = 1; $e <= $number_of_tables; $e++) { $tables .= '<table id="' . $e . '"></table>'; } echo $tables; That's exactly what I need! Thanks! The only additional question I was going to ask is how I can configure variable text for these tables... What I'd like is to have a bunch of variables that are configured to present when the number table ID exists... so: <? $1 = "show for table ID 1"; $2 = "show for table ID 2"; ?> But I'm not quite sure how to make that happen here: $tables .= '<table id="' . $e . '"></table>'; I assume it would be echo $variable and tied to the $e -- I just don't know how. Thanks again! Link to comment https://forums.phpfreaks.com/topic/156490-using-variables-to-create-and-name-html-tables/#findComment-824068 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Where do you want the to appear? Inside the table? <?php $number_of_tables = 4; $content = array( 'content for table 1', 'content for table 2' ); $tables = ''; for ($e = 1; $e <= $number_of_tables; $e++) { $tables .= '<table id="' . $e . '">' . $content[$e] . '</table>'; } echo $tables; Link to comment https://forums.phpfreaks.com/topic/156490-using-variables-to-create-and-name-html-tables/#findComment-824071 Share on other sites More sharing options...
msaz87 Posted May 2, 2009 Author Share Posted May 2, 2009 Where do you want the to appear? Inside the table? <?php $number_of_tables = 4; $content = array( 'content for table 1', 'content for table 2' ); $tables = ''; for ($e = 1; $e <= $number_of_tables; $e++) { $tables .= '<table id="' . $e . '">' . $content[$e] . '</table>'; } echo $tables; Yes, I want the content to be in the tables, but it'll be a little more complicated than that, because the table will be a little more complicated -- there will be four parts to each table. So, in other words, it'll be like: <table> <tr> <td> content1a </td> <td> content1b </td> </tr> <tr> <td> content1c </td> <td> content1d </td> </tr> </table> Hopefully that makes sense... thanks! Link to comment https://forums.phpfreaks.com/topic/156490-using-variables-to-create-and-name-html-tables/#findComment-824075 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Do you know any PHP? I'm sorry, but that is ridiculous. You should read up on PHP 101. Link to comment https://forums.phpfreaks.com/topic/156490-using-variables-to-create-and-name-html-tables/#findComment-824375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.