2
I have an intranet system where the user creates a message for different sectors of the company, after creating the message, it can be edited and when it suffers a change, it puts an edited hyperlink at the end of the message, which when clicked, opens a modal with the original message.
So far so good, the problem is when a note suffers more than one change, man select
always take the first record, instead of taking all. I will try to describe how it works:
TABLE MESSAGES has (id, message, date, time) and etc. TABLE RECADOS_EDITADOS has (id, id_messages <- foreign key of messages.) etc
EXAMPLE:
Make a INSERT
on the table ERRANDS it receives id=31. If I modify this message, a UPDATE
on the table ERRANDS and a INSERT
on the table RECADOS_EDITY, which receives an id from him and the id=31, which would be the foreign key.
If I make another UPDATE
on the table ERRANDS, the table RECADOS_EDITY suffers another INSERT
with the same foreign key 31.
There when I make one select
for example SELECT * FROM RECADOS_EDITADOS WHERE id_recados = 31
, he picks up the first record with 31 and not all.
I tried to do it and it didn’t solve:
$select = mysql_query("SELECT * FROM recadosedit WHERE idRecados = '$id'");
$v = mysql_fetch_array($select);
$linhas = mysql_num_rows($select);
$recadoAnterior = array();
$dtAlterado = array();
$hrAlterado = array();
for($i = 0 ; $i <= $linhas ; $i++){
$recadoAnterior[$i] = $v['recado'];
$dtAlterado[$i] = $v['dtAlterado'];
$hrAlterado[$i] = $v['hrAlterado'];
}
At the time of showing I also do a go, but it always shows the same record.
for($i = 0 ; $i <= $linhas ; $i++){echo '
<div class="row">
<div class="small-12 medium-12 large-12 columns">
<label>'.$recadoAnterior[$i].'</label>
<label>Data alterado:</label>'.$dtAlterado[$i].' <label>Hora alterado:</label>'.$hrAlterado[$i].'
</div>
</div>';
}
Wesley, try to break your problem in pieces, first you have to identify if everything is ok in your database, goes into it and selects * from RECADOS_EDITADOS WHERE id_messages = 31 if it returns only one record Voce has to check why it is updating the same record, if it is respecting the Primary key if this id and autoincrement
– Gabriel Rodrigues
Okay, I did that and he brought four records and in my code I believe he’s taking these four records because in select if I put ORDER BY id DESC he brings a record, if I trade DESC for ASC, he brings another, then I believe he’s taking them all, I just can’t show all to the user
– Wesley Santos
this $v is taking all the records ? shouldn’t be with it the mysql_num_rows ?
– Gabriel Rodrigues