I have a database with titles and I want to display them inside of a tag.
<?php
require 'mainphp.php';
if (isset($_GET['val'])) {
$id=$_GET['val'];
if ($id==1) {
echo "<br>";
echo '<div class="row" >';
for ($i=1; $i < 20; $i++) {
echo '<div class="col-xs-4 col-sm-3 col-md-2" >';
echo ('<a href="kwdikoi.php?id='.$i.'" type="button" class="btn btn-warning btn-lg" >'.displayData("kwdikoi",$i, "title").'</a>');
echo '</div>';
}
echo '</div>';
}elseif ($id==28) {
# code...
}elseif ($id==33) {
# code...
}
}elseif (isset($_GET['id'])) {
$id=$_GET['id'];
displayData('kwdikoi',$id,'essence');
}
?>
mainphp.php
function displayData($table,$line,$column){
//open SQL CONNECTION
$conn = mysqli_connect('localhost','root','alex','labels');
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
mysqli_query($conn,'set character set UTF8');
mysqli_query($conn,"SET NAMES 'utf8'");
mysqli_set_charset($conn,"utf8");
//SELECT the row from our table
$query = "SELECT * FROM ".$table." WHERE id ='".$line."'";
$result = mysqli_query($conn,$query);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row[$column];
}
}else{
echo "There is no ".$column." in our database.".mysqli_error($conn);
}
//."<br>".$row['title']."<br>".$row['smallindex']."<br>".$row['mainindex']."<br>";
// close SQL connection
mysqli_close($conn);
}
The displayData()
is a function that echoes the title . The results that I get is the title outside of the button e.g title[empty button]
, and I want the title inside the button e.g [title]
.