1
Good afternoon I’m trying to make a query Mysqli , ie , I want each line of the database enters a separate div , I searched and found nothing resembling what I think is in a difficult way to understand
HTML code
<div id="inicio" class="col-md-4 col-sm-4 col-xs-12 profile_details">
<div class="well profile_view">
<div class="col-sm-12">
<h4 class="brief"><i>Digital Strategist</i></h4>
<div class="left col-xs-7">
<h2 id="inicio"></h2>
<p><strong>About: </strong> Web Designer / UX / Graphic Artist / Coffee Lover </p>
<ul class="list-unstyled">
<li><i class="fa fa-building"></i> Address: </li>
<li><i class="fa fa-phone"></i> Phone #: </li>
</ul>
</div>
<div class="right col-xs-5 text-center">
<img src="../images/img.jpg" alt="" class="img-circle img-responsive">
</div>
</div>
<div class="col-xs-12 bottom text-center">
<div class="col-xs-12 col-sm-6 emphasis">
<p id="inicio" class="ratings">
<a>4.0</a>
<a href="#"><span class="fa fa-star"></span></a>
<a href="#"><span class="fa fa-star"></span></a>
<a href="#"><span class="fa fa-star"></span></a>
<a href="#"><span class="fa fa-star"></span></a>
<a href="#"><span class="fa fa-star-o"></span></a>
</p>
</div>
<div class="col-xs-12 col-sm-6 emphasis">
<button type="button" class="btn btn-success btn-xs"> <i class="fa fa-user">
</i> <i class="fa fa-comments-o"></i> </button>
<button type="button" class="btn btn-primary btn-xs">
<i class="fa fa-user"> </i> View Profile
</button>
</div>
</div>
</div>
</div>
Javascript
$("document").ready(function() {
//CarregarFuncionarios
$.getJSON("../include/carrFunc.php", function(data) {
var items = [];
i = 0;
$.each(data, function(i) {
items.push("<option value='" + data[i].idFuncionario + "'>" +
data[i].nomeFunc + "</option>");
});
$("#inicio").append(items);
});
});
PHP
<?php
include "conexao.php";
$sql = "SELECT idFuncionario,nomeFunc FROM tbfuncionario;";
$result = $conn->query($sql);
$data = array();
if ($result->num_rows > 0) {
// output data of each row
$data = $result->fetch_all( MYSQLI_ASSOC );
//print_r ($data);
} else {
echo "Nenhum resultado encontrado.";
}
$conn->close();
//echo "<br>";
echo json_encode( $data );
?>
What gives
console.log(data);
on the getJSON callback? This HTML you have on the page is what each row of the database should fill?– Sergio
I didn’t really understand the use of <option> there in javascript
– GeekSilva
@Sergio alias put more things there , I have this form ready in HTML but wanted to use the effects that it has
– Somdesp
@Geeksilva then I used the same code that I use to load the combobox .. I do not have much knowledge in web . but wanted each bank line to fill a div on the page
– Somdesp
Dude, Voce has more than one "id" with the same name "start" allocated in several Tags, so the browser will never put it in the right place :( Another point is that Voce is giving an append of a <option> without having any <select> on your page :(
– MarioAleo
Explaining better ...precise that appears the fields of each user ex:name , address and etc, ... and precise that appears in separate Ivs , according to each data
– Somdesp
What gives
console.log(data);
in the callback of getJSON?– Sergio
Uncaught Referenceerror: data is not defined at <Anonymous>:1:13 (Anonymous) @ VM5597:1
– Somdesp
@Sergio varios Object ) [Object, Object, Object, Object, Object, Object, Object, Object, Object]
– Somdesp
@Somdesp ok, and what gives
console.log(typeof data, JSON.stringify(data));
?– Sergio
@Sergio Appears all database data
– Somdesp
@Somdesp can you put an example of one of these objects here? so we can answer better?
– Sergio
@Sergio one of the lines {"idFuncnario":"7","nomeFunc":"Anderson Silva"} that I need to appear in each div or separated in html
– Somdesp
And in the HTML where this data should be inserted?
– Sergio
@Sergio in HTML when I use $("#start"). append(items[i]); in JS and <div name="start" id="start"> in html appears all within the same div
– Somdesp
But on what HTML? element that div or span? to give an example of how to mount it. And by the way, these objects only have 2 keys (idFunc and function)?
– Sergio
@Sergio I wanted to put in div .. at first would have these keys after I would add more ...I will put an image at the end to better understand
– Somdesp
@Sergio added the image of the example I want to do
– Somdesp