0
I have a database where in the table users I have the columns:
+----------+------------+----------+------------+----------+------------+
| imp_cod1 | imp_local1 | imp_cod2 | imp_local2 | imp_cod3 | imp_local3 |
+----------+------------+----------+------------+----------+------------+
| 13 | RECEPÇÃO | | | 18 | CEO |
+----------+------------+----------+------------+----------+------------+
Note that the values of imp2
are all empty, for in this case only imp1
has data.
In my html code I use the following format to display the information of imp1:
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Impressora</th>
<th>Modelo</th>
<th>Contagem</th>
<th>Situação</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><?php echo $imp_cod1; ?></th>
<td><b><?php echo $imp_local1; ?></b></td>
<td><?php echo $imp_modelo1; ?></td>
<td><?php echo $imp_contador1; ?></td>
<td><button type="button" class="btn btn-round btn-success"><?php echo $imp_situacao1; ?></button></td>
</tr>
</tbody>
</table>
</div>
Today, when I have a second die on imp2
, imp3
... i will manually and create a new field of results as the above mentioned example <tr>
I wonder if there’s any way I can make it automatic so I don’t have to keep editing PHP every time I insert or delete new data in the table.
Connection code with db (every page that requires the user to be logged in has a include for this page): http://pastebin.com/02WJFzEp
Code of my page where I am having difficulties to include new lines automatically: http://pastebin.com/GcTbPn3H (in line 251 has the first data fill, it ends in 257. Just below there are 7 more fills where I have already left ready.)
Now suppose the user only has the imp1
and all the others are empty, yet my system will search all the others and leave blank, and because the html code is already created, it leaves the created lines but blank as well. I would like to know if I can make this become automatic, in theory: if the imp field is empty do not create line, otherwise create line and fill in data...
If I am going the wrong way in logic I am able to change, I am beginner and was urgently at the end of this.
Follow photo of how the system gets even with blank data:
You want to be able to have imp_cod4, imp_cod5, imp_cod6, etc or you want to put more lines, type line1: |imp_cod1|imp_local1|imp_cod2|imp_local2|imp_cod3|imp_local3| Linha2: |imp_cod1|imp_local1|imp_cod2|imp_local2|imp_cod3|imp_local3| and so on?
– Rene Freak
In fact I have already created the imp_ until the 8 because this is as much as I need. What I need is some "check" script if it has any value within imp and if there is it create a new line in html.
– willian
Come on : 1-"Note that the values of imp2 and imp3 are all empty", in my view
imp_local3
it’s not empty, but it’s just a detail. 2- Can you put the code that searches for this data, the code above the table ? 3-"When I have a second given in imp2, imp3... I will manually and create a new field" you refer to creating a new row of table html ?– MagicHat
1 - I’m sorry for my remark, imp3 really has data. 2 - Should I post the complete code right here or outside? 3 - exactly that, I always go there and create a new line in the html where I manually insert an echo $imp_cod2 database "extract".
– willian
is using Pdo?
– Felipe Duarte
Has not
while
orforeach
in that code?– rray
2-You can edit your question and place the missing...
– MagicHat
The point is that this is not a database, at most, an array... The correct one was to have a table with fields: code, location, model, counter and each row of the table would represent a printer. In this way, it could have 8, 80 or 8000 printers, one per line, as a spreadsheet. In the logic that it appears to use, just by fiddling with the code every time. Dai doesn’t need php code, it does it in html even if it comes cheaper.
– Rene Freak
Good morning guys, I edited the question with the codes I use. Thanks for the return
– willian