简体   繁体   English

我不知道如何解决这个问题(php、javascript、mysql)

[英]i have no idea how to fix this (php, javascript, mysql)

I have 3 spaces in a web page and through javascript I have to show the result of a query in each of them, the problem is that each result appears only in the last table and the other 2 remain empty.我在 web 页面中有 3 个空格,通过 javascript 我必须在每个空格中显示查询结果,问题是每个结果仅出现在最后一个表中,而其他 2 个保持为空。

This is a php page's response when an action is performed:这是执行操作时 php 页面的响应:

{"result":"1","testresult:{"nome":"Marco,Matteo,Mattia","cognome":"Rossi,Leone,Piero","tipo":"3,14,44"}}

Then through javascript I would like to assign these values to 3 empty spaces, like thi example:然后通过 javascript 我想将这些值分配给 3 个空格,例如:

|----------1----------|  |----------1----------|  |----------1----------|
| name:   Marco       |  | name:   Matteo      |  | name:   Mattia      |
| cognome:   rossi    |  | cognome:   Leone    |  | cognome:   Piero    |
| tipo: 3             |  | tipo: 14            |  | tipo: 44            |
|-----------------------------------------------------------------------|

but the result is this:但结果是这样的:

|----------1----------|  |----------1----------|  |----------1-------------------------|
| name:   undefined   |  | name:   undefined   |  | name:   Marco, Matteo, Mattia      |
| cognome:   undefined|  | cognome:   undefined|  | cognome:   Rossi, Leone, Piero     |
| tipo: undefined     |  | tipo: undefined     |  | tipo: 3, 14, 44                    |
|--------------------------------------------------------------------------------------|

here I leave you all my work.我把我所有的工作都留给你了。 PHP PHP

$stmtcarte = $connection->prepare("SELECT GROUP_CONCAT(concat.nome) as nome, GROUP_CONCAT(concat.cognome) as cognome, GROUP_CONCAT(concat.tipo) as tipo FROM (SELECT nome, cognome, tipo FROM test WHERE categoria=? ORDER BY RAND() LIMIT 3 ) concat");

$categoria="test";
$stmtcarte->bind_param("s",$categoria);
$stmtcarte->execute();
$risultatocarte = $stmtcarte->get_result();
$numero_giocatori = $risultatocarte->num_rows;
$result=array("risultato"=>"1", "testresult"=>"");
while($rispostacarte=$risultatocarte->fetch_assoc()){
$result['risultato']="1";
$result['testresult']=$rispostacarte;

echo json_encode($result);

}
$stmtcarte->close();

JAVASCRIPT JAVASCRIPT

    $(document).on("click",".test-btn", function(){
    data = {'id':$(this).data('id')}
    $.post("op2.php", data, function(response){
    var Ogg = $.parseJSON(response);
        
        switch(Ogg.risultato){
            case "1":
                //
                //
                //
            $.each(Ogg,function(i,data){
                        
                   
            if(data.tipo == "0"){
                              //
            }else{
                              //
            }

            setTimeout(function () {
            $(".Response").append("<div class='card-cont'><div id='cobr' class='pcdisplay center-block'> <div class='top-overlay'></div><div style='color:;' class='pcdisplay-nome'>"+ data.nome +"</div><div style='color:;' class='pcdisplay-cognome'>"+ data.cognome +"</div><div style='color:;' class='pcdisplay-tipo'>"+data.tipo+"</div><div class='pcdisplay-chem-style-name'></div></div></div><span style='display:block; text-align: center; color: #FFFF66; font-weight: bold;'>" + data.tipo + "</span></div>").hide().fadeIn(100);
                       
            }, i*900);
            });
            break;
            case "2":
                alert("//");
            break;
            case "3":
                alert("//");
            break;
            case "4":
                alert("//");
            break;
        }

    });            
    
});

I hope someone can help me.我希望有一个人可以帮助我。 thank you all.谢谢你们。

//sample data response when ajax return 
const data = {"nome":"Marco,Matteo,Mattia","cognome":"Rossi,Leone,Piero","tipo":"3,14,44"};

//convert string into array list   
var nome = data.nome.split(',');    
var cognome = data.cognome.split(',');    
var tipo = data.tipo.split(',');

//array length 
let nLen = nome.length;
//for loop for print array list 
let text = "<ul>";
for (let i = 0; i < nLen; i++) {
  text += "<li>" + nome[i] +" - " + cognome[i] +" - "+ tipo[i] +"</li>";
}
text += "</ul>";
// append this with html 
console.log(text);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试修复Java Countdown。 我不知道我在做什么 - Trying to fix a Javascript Countdown. I have no idea what I'm doing 如何在JavaScript和php mysql中将表单操作修复为不同的页面问题, - how to fix form action to different page issue in javascript and php mysql, 我有 javascript 代码 getElementsByClassName 它将如何在 php 上? - I have the javascript code getElementsByClassName how it will be on php? 我正在用javascript做重力模拟器,而且我不知道如何进行碰撞工作 - I am making a gravity simulator in javascript, and I have no idea how to make a collision work 如何避免在MYSQL / PHP / Javascript中显示具有NULL值的列? - How to avoid displaying the columns that have NULL value in MYSQL/PHP/Javascript? 尝试编译我的反应项目时收到大量错误。 我完全不知道这意味着什么或如何开始修复它 - Recieving an influx of errors when trying to complie my react project. I quite literally have no idea what it means or how to begin to fix it 我不知道如何用Qunit测试这个? - I have no idea how to test this with Qunit? 我有一个JavaScript范围错误,我不知道如何解决此问题 - I have a javascript scope error, I don't know how to fix this 如何将我拥有的php变量($ total)传递给外部Javascript,如输入所示? - How to pass a php variable($total) i have, to an External Javascript as in input? Javascript 分配有问题:数组和 object 迭代但我不知道解决方案是什么,我已经尝试了一切 - Having a problem with a Javascript assignment: Array and object iteration but I have no idea what the solution is, I have tried everything
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM