php mysql html显示,使用php在html表中显示mysql行内容

I'm new here and I have a question, I looked for the solution everywhere and I still cant manage to solve this.

I want to show the results of the SELECT statement (in php) in a table (html) using JS. Here is the code of these 3 files:

main.HTML file

Mostrar

select.PHP file

$link=mysqli_connect("xxxxxxx", "user_tienda","%%%%%%%%","pool_tiendas");

if (mysqli_connect_errno() )

echo "Fallo en la conexion con mysql" .mysqli_connect_error();

$action=$_POST["action"];

if ($action=="showroom") {

$query = "SELECT cod, nmbre, drccn from tienda";

$show = mysqli_query($link, $query) or die ("error");

echo "

codnmbredrccn

while ($row = mysqli_fetch_array($show)) {

echo "

" .$row['cod']."".$row['nmbre']."".$row['drccn']."";

}

echo "

";

}

?>

select.JS file

$(document).ready(function(){

$("#button").click(function () {

function show_all() {

$.ajax({

type: "POST",

url: "select.php",

data:{action:"showroom"},

success: function (data) {

$("#id").hide();

$("#content").html(data);

}

});

}

show_all();

});

});

The problem is when I click the button to show the content nothing happens.

The Select statemnt is correct, in Mysql font I can see the results of the SELECT statement.

This is what I'm getting if I directly run select.php:

codnmbredrccn"; while ($row = mysqli_fetch_array($show)) { echo "" .$row['cod']."".$row['nmbre']."".$row['drccn'].""; } echo ""; } ?>

Now in mozilla console I can see 2 errors: no se encuentra elemento select.php:18 and no se encuentra elemento main.html:18 (no se encuentra elemento -> can't find element

The button is supposed to hide when clicked, but nothing happens. Seems like it never executes the js file.

解决方案

I removed jquery.js and inserted another script at head. It worked for me.

I connected it to localhost. check it.

main.html

Mostrar

select.js

$(document).ready(function(){

$("#button").click(function () {

function show_all() {

$.ajax({

type: "POST",

url: "select.php",

data:{action:"showroom"},

success: function (data) {

$("#id").hide();

$("#content").html(data);

}

});

}

show_all();

});

});

select.php

$link=mysqli_connect("localhost", "root","","manishYii");

if (mysqli_connect_errno() )

echo "Fallo en la conexion con mysql" .mysqli_connect_error();

$action=$_POST["action"];

if ($action=="showroom") {

$query = "SELECT FirstName, LastName, EmailID from members";

$show = mysqli_query($link, $query) or die ("error");

echo "

codnmbredrccn

while ($row = mysqli_fetch_array($show)) {

echo "

" .$row['FirstName']."".$row['LastName']."".$row['EmailID']."";

}

echo "

";

}

?>

Output

0gkGR.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值