New user with some questions
Permalink
Hello community! Concrete is an awesome product first off.
Most of the php development work I have done is very basic database transaction adds, deletes, updates and that data getting dumped out using something like echo '<tr><td>'.tblfield1.'</td><td>'.tblfield2.'</td></tr>', while looping the all the records.
So I would end up with a formatted list of data like so.
tblfield1 tblfield2
John Smith
Bob Jones
Joseph Doe
So if I understand blocks correctly this example in that format would go as follows. I know there are other files just posting the db.xml and view.php in its simplest form. This was created using the Designer Content btw.
db.xml
<table name="btDCTestBlock">
<field name="bID" type="I"><key /><unsigned /></field>
<field name="field_1_textbox_text" type="X"></field>
<field name="field_2_textbox_text" type="X"></field>
</table>
view.php
<?php echo htmlentities($field_1_textbox_text, ENT_QUOTES, APP_CHARSET); ?>
<?php endif; ?>
<?php if (!empty($field_2_textbox_text)): ?>
<?php echo htmlentities($field_2_textbox_text, ENT_QUOTES, APP_CHARSET); ?>
<?php endif; ?>
So now to my questions.
If there are 10 records in this table there would be 10 blocks displayed?
If that is the case what if I want to format that group of blocks into specific columns lengths so all the records line up proper for viewing?
I apologize in advance if I am not making any sense....
Most of the php development work I have done is very basic database transaction adds, deletes, updates and that data getting dumped out using something like echo '<tr><td>'.tblfield1.'</td><td>'.tblfield2.'</td></tr>', while looping the all the records.
So I would end up with a formatted list of data like so.
tblfield1 tblfield2
John Smith
Bob Jones
Joseph Doe
So if I understand blocks correctly this example in that format would go as follows. I know there are other files just posting the db.xml and view.php in its simplest form. This was created using the Designer Content btw.
db.xml
<table name="btDCTestBlock">
<field name="bID" type="I"><key /><unsigned /></field>
<field name="field_1_textbox_text" type="X"></field>
<field name="field_2_textbox_text" type="X"></field>
</table>
view.php
<?php echo htmlentities($field_1_textbox_text, ENT_QUOTES, APP_CHARSET); ?>
<?php endif; ?>
<?php if (!empty($field_2_textbox_text)): ?>
<?php echo htmlentities($field_2_textbox_text, ENT_QUOTES, APP_CHARSET); ?>
<?php endif; ?>
So now to my questions.
If there are 10 records in this table there would be 10 blocks displayed?
If that is the case what if I want to format that group of blocks into specific columns lengths so all the records line up proper for viewing?
I apologize in advance if I am not making any sense....
You would have to use 2 tables.
One table who contain the bID (or block ID) which is always needed so the system knows to what block the data belongs to. It would also usually contain settings data (anything unique to that block and that is needed only once like a size)
The second table would contain your data (tblFiled1 and 2) that needs to appear several times with different values within the same block. It would also need to contain the same bID as in the firs table to allow a 1 to many relationship between the 2 tables
So let's say the first table has only one column
The second table would have 3 columns
You notice in the second table the bID is not key anymore as the same bID will appear several times.
So let's say your block has a bID of 145, the second table will contain:
145 tblfield1 tblfield2
145 John Smith
145 Bob Jones
145 Joseph Doe
Now it's just a matter of retrieving the bID for your block and then using a sql statement, retrieving all the data from the second table with that bID.
I see from your code that you are using the Designer content add-on. It's a great add-on especially for learning but it doesn't deal with multi table blocks so you can't use it to do what you are trying to achieve.
Good luck