0
I have the following listing:
How would I make it so that by clicking on the exclamation icon, I changed it to the check icon and vice versa and changed the status in the database as well? PHP/Mysql code I know how to do, but jquery I don’t get much. Since the status is coming from BD, the code is like this:
$sql = mysqli_query($this->conexao,"SELECT * FROM documentos");
while($peListar = mysqli_fetch_object($sql)){
$statusDoc = ($peListar->StatusDocumentos == "A")?"<span style='color: red'><i class=\"fas fa-exclamation-circle fa-lg\" id=\"inativo\"></i></span>":"<span style='color: green'><i class=\"fas fa-check-circle fa-lg\" id=\"ativo\"></i></span>";
echo $statusDoc;
}
With which id or class the icons are coming from the bank?
– Jorge.M
I’m sorry Jorge. I couldn’t understand your question. You mean the bank id?
– user24136
The icons have
classe
? Or some other attribute to be identified?– Jorge.M
No. Only the fountain itself
– user24136
In fact you don’t even need Jquery in this case, just call the action that is updating the button that has the icon
– Jorge.M
If you want I’ll write an answer showing the logic.
– Jorge.M
Right. But I wouldn’t want you to refresh the page.
– user24136
You attentive me to a detail that may have seemed vague. I changed my title.
– user24136
To do with ajax, you will need to turn the return of your database showing the status in json to be able to catch the return with jquery and change the icon
– Jorge.M
Right. I just don’t get a lot of jquery and Ajax. Could you show me an example?
– user24136
You are already encondando the bank result in a
json
in hisphp
? If yes, post the code of youraction
and how the result is being shown on the page.– Jorge.M
It’s in pure PHP, using the traditional mode. I’m not using json.
– user24136
To perform the ajax you will need to turn the return into json, because the method needs to fetch the status in your file
php
to make the validation, understands?– Jorge.M
I understand.. but I don’t know how to do that. Could you show me an example that changes my code? I altered my post and put an excerpt of how he is.
– user24136
Post the code of your
action
. Basically you will need the function json_encode– Jorge.M
I’m not actually using forms to search for this result. It’s a listing method in the document view.
– user24136
Put the listing code in the question to make it easier for those who want to help you!
– user60252