There is some questions like this, but the problem is: why this doesn't work?
Well, I have a div and a php loop to get values from mysql and put it into a table. And each row of this table, I need a button that open more details about itself. Like, it is a users list and I need to open a second php page inside that div with more information about that person. So I put a AJAX script with jQuery inside the loop :D
And, as always, sorry for bad english u.u
Well... this is my main code:
<div id="equipecontent" class="card-content" style="padding:10px;">
<p class="center-align grey-text text-darken-1""><b>Código Sênior: <? echo $_SESSION['cod_revenda']-100000; ?></b></p>
<table class="striped centered highlight">
<thead>
<tr>
<th data-field="id">Name</th>
<th data-field="tel">Phone</th>
<th data-field="email">E-mail</th>
<th data-field="ven">Moth sell</th>
<th data-field="ir"></th>
</tr>
</thead>
<tbody>
<?
$sql = "select cli_nom, cli_cod, cli_log, cli_fon1, cli_ven_cod, cli_ven_mes";
$sql .= " from clientes where cli_tip_cod = 2 and cli_ven_cod = ".$_SESSION['cod_revenda']."-100000";
$query = mysql_query($sql) or die($sql ."<p>". mysql_error());
$i=0;
while ($r = mysql_fetch_array($query)) {
extract($r,EXTR_PREFIX_ALL,"c");
?>
<tr>
<td><? echo $c_cli_nom; ?></td>
<td><? echo $c_cli_fon1; ?></td>
<td><? echo $c_cli_log; ?></td>
<td>R$<? echo $c_cli_ven_mes; ?></td>
<td><a href="" onclick="id<? echo $c_cli_cod; ?>();"><i class="fa fa-user-plus fa-lg"></i></a></td>
<script>
function id<? echo $c_cli_cod; ?>(){
var id = <? echo $c_cli_cod; ?>;
$('#equipecontent').html('Downloading...'); // Show "Downloading..."
// Do an ajax request
$.ajax({
url: "equipece.php?id="+id
}).done(function(data) { // data what is sent back by the php page
$('#equipecontent').html(data); // display data
});
}
</script>
</tr>
<? $i++;} if($i==0){ ?>
<tr>
<td colspan="2"></td>
<td><h4 class="grey-text text-darken-1">Nothing here =(</h4></td>
<td colspan="1"></td>
</tr>
<? } ?>
</tbody>
</table>
</div>
And this is my second target page (equipece.php) content:
<?
include_once "comum.php"; // Things that previous page already had, but without this, doesn't work.
dbAbreConexao(); // Opening connection with database
ini_set('default_charset','UTF-8');
mysql_set_charset('utf8');
if(isset($_GET["id"])) {
$id = $_GET["id"];
} else {
$id = 0;
}
$sql = "select cli_nom, cli_cod, cli_log, cli_fon1, cli_ven_cod, cli_ven_mes";
$sql .= " from clientes where cli_tip_cod = 2 and cli_ven_cod = $id";
$query = mysql_query($sql) or die($sql ."<p>". mysql_error());
$i=0;
while ($r = mysql_fetch_array($query)) {
extract($r,EXTR_PREFIX_ALL,"c");}
?>
<? echo $c_cli_nom; ?>
Well, when I lick the button, a lot of things happens, actually... Sometimes something loads and the first bage returns; other times the entire page turns to white and stuck... Well, I think that my code is a mess.
Help D=
Ps.: I think this information is useless, but I'm using Materializecss framework.