I am trying to create a carousel with button "Read More" in every slide, it should be redirect to an image however it is not fetching the data instead it shows an error when im trying to put the button Illegal string offset (image2) -"image2 is the row in my sql table"
This is the carousel script.
<?php
include "db.php";
$query = "select * from carousel1 order by id desc limit 10";
$res = mysqli_query($con,$query);
$count = mysqli_num_rows($res);
while($c=mysqli_fetch_array($res)){
$titlee = $c['titlee'];
$konten = $c['konten'];
$gbr = $c['image'];
$gbr2 = $c['image2'];
if($counter==0)
{
echo"<div class='item active'>";
echo "<a href=''>";
echo "<img src='images/$gbr'>";
echo "</a>";
echo "<div class='container'>";
echo "<div class='carousel-caption left-caption style='background-color:#EE0930'>";
echo "<a href=''> <font color=#ffffffff style='font-family: Verdana,Arial,Helvetica,Georgia; font-size: 13px;'>";
echo "<h5 class='text-left'>".$titlee."</h5></font>";
echo "</a>";
echo "<a class=\"btn btn-primary btn-sm\" href=\"{$gbr2["image2"]}\">Read More</a>";
echo "</div>";
echo "</div>";
echo "</div>";
}
else
{
echo "<div class='item'>";
echo "<a href=''>";
echo "<img src='images/$gbr'>";
echo "</a>";
echo "<div class='container'>";
echo "<div class='carousel-caption left-caption style='background-color:#EE0930'>";
echo "<a href=''> <font color=#ffffffff style='font-family: Verdana,Arial,Helvetica,Georgia; font-size: 13px;'><h5 class='text-left'>".$titlee."</h5></font>
</a>";
echo "<a class=\"btn btn-primary btn-sm\" href=\"{$gbr2["image2"]}\">Read More</a>";
echo "</div>";
echo "</div>";
echo "</div>";
}
$counter++;
}
echo"</div>";
echo "<a class='left carousel-control' href='#myCarousel' data-slide='prev'>‹</a>";
echo "<a class='right carousel-control' href='#myCarousel' data-slide='next'>›</a>";
echo"</div>";
echo"<!-- End Slider Caraousel-->";
?>
The value of image2 is already being stored in $gbr2 ($gbr2 = $c['image2'];) . And then you're trying to use $gbr2["image2"] to get the value
Replace $gbr2["image2"] with $gbr2
Related
I am trying to print in the modal the information of the selected user but only the first row is printed in the modal.
I am using PHP with MySQL but it is not working. I don't understand why it prints only the first row.
Please help to resolve my issue.
This is the php code:
include ("conex.php");
$query = "SELECT * FROM empleado WHERE cargo='personal'";
$datos=mysqli_query($conex,$query);
echo "<div class='tables'>";
echo "<h3 class='title1'>Listado de Empleados :</h3>";
echo "<div class='panel-body widget-shadow'>";
echo "<table class='table'>";
echo "<button class='btn btn-success add-prod'>
<span class='fa fa-plus'></span>
Agregar Empleado
</button>";
echo "<thead><tr><th>Rut</th><th>Nombre</th><th>Apellido</th><th class='action'>Accion</th></thead>";
while($fila=mysqli_fetch_assoc($datos))
{
echo "<tbody>";
echo "<tr title='informacion detallada' class='selector-empleado' data-toggle='modal' data-target='#infodetallada'>";
echo "<td>".$fila["rut"]."</td>";
echo "<td>".$fila["nombre"]."</td>";
echo "<td>".$fila["apellido"]."</td>";
echo "<td class='buttons-admin'><button title='modificar empleado' class='btn btn-primary btn-admin1'><span class='fa fa-refresh'></span></button>
<button onClick='window.location=\"eliminarempleado.php?rut=".$fila["rut"]."\";'/ title='eliminar empleado' class='btn btn-danger btn-admin2'>
<span class='fa fa-times'></span></button></td>";
echo "</tr>";
echo "</tbody>";
echo "<div class='modal fade' id='infodetallada' role='dialog'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<button type='button' class='close' data-dismiss='modal'>×</button>";
echo "<h4 class='modal-title'>Informacion detallada :</h4>";
echo "</div>";
echo "<div class='modal-body'>";
echo "<b>Rut : </b>" .$fila["rut"]."<br>";
echo "<b>Nombre : </b>" .$fila["nombre"]."<br>";
echo "<b>Apellido : </b>" .$fila["apellido"]."<br>";
echo "<b>Cargo : </b>" .$fila["cargo"]."<br>";
echo "<b>Correo : </b>" .$fila["correo"]."<br>";
echo "<b>Contraseña : </b> ************";
echo "</div>";
echo "<div class='modal-footer'>";
echo "<button title='modificar empleado' class='btn btn-primary'><span class='fa fa-refresh'></span> Modificar</button>";
echo "<button onClick='window.location=\"eliminarempleado.php?rut=".$fila["rut"]."\";'/ title='eliminar' class='btn btn-danger'><span class='fa fa-times'></span> Eliminar </button>";
echo "<button type='button' class='btn btn-default' data-dismiss='modal'>Cerrar</button>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
echo "</table>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='clearfix'></div>";
echo "</div>";
echo "</div>";
mysqli_close($conex);
You just have to make couple of minor changes.
Append some unique id to the data-target attribute in the clickable element, so that it is unique for each record
<tr title='informacion detallada' class='selector-empleado' data-toggle='modal' data-target='#infodetallada".$fila['rut']."'>
Append same unique id to the id attribute of the modal, so that it is same to the respective clickable element.
<div class='modal fade' id='infodetallada".$fila['rut']."' role='dialog'>
I assumed that $fila['rut'] will be unique for each of the records. If it is not so, then you can use some other unique elements.
Issue: Each model box should be connected on its own unique ID. It should have unique 'data-target' in the clickable element & 'id' in the respective modal.
I'm trying to create a row with 3 thumbnails on it, the problem is it is not aligning in a single row, but instead every thumbnail goes in different row.
echo "<table>";
echo "<tr>";
echo "</tr>";
while($row=mysqli_fetch_array($result)){
echo "<div class=\"container\">";
echo "<div class=\"row-fluid\">";
echo "<div class=\"col-md-4\">";
echo "<div class=\"thumbnail\">";
echo "<img alt=\"News\" src=\"images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo "<h3>{$row["title"]}</h3>";
echo "<p>{$row["caption"]}</p>";
echo "<p align=\"right\">";
echo "<a class=\"btn btn-primary\" href=\"{$row["newsupdate"]}\">Read More</a>";
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
try this it might work
echo "<table>";
echo "<tr>";
while($row=mysqli_fetch_array($result)){
echo "<img alt=\"News\" src=\"images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo " <td> <h3>{$row["title"]}</h3> </td> ";
echo "<td><p>{$row["caption"]}</p></td>";
echo "<td> <a class=\"btn btn-primary\" href=\{$row["newsupdate"]}\">Read More</a>";
echo "</td>";
}
echo "</tr>";
echo "</table>";
I'm creating a thumbnail with a title, image and caption on it. I'm trying to select data from my table to show it into my homepage. Can someone help me to create a normal thumbnail in my php that contains the detail from my sql. I tried to search and can't find how to create a thumbnail using php and not html.
$sql = "SELECT * FROM news";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>first_name</th>";
echo "<th>last_name</th>";
echo "<th>email</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['image'] . "</td>";
echo "<td>" . $row['caption'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
In short, is there a way to create a php file from this?
<div class="col-md-4">
<div class="thumbnail">
<img alt="Memory" img src="../../images/a2.jpg">
<div class="caption">
<h3><b>
Title
</b></h3>
<p>
Caption Caption Caption Caption Caption
</p>
<p align="right">
<a class="btn btn-primary" href="news2.html">Read More</a>
</p>
</div>
</div>
</div>
Do you want to replace your table structure with that template structure? You'll need to adjust some of the data to fill the hyperlink (I don't know how you want to build that).
while($row=mysqli_fetch_array($result)){
echo "<div class=\"col-md-4\">";
echo "<div class=\"thumbnail\">";
echo "<img alt=\"Memory\" src=\"../../images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo "<h3>{$row["title"]}</h3>";
echo "<p>{$row["caption"]}</p>";
echo "<p align=\"right\">";
echo "<a class=\"btn btn-primary\" href=\"news2.html\">Read More</a>";
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
}
In my page many submit buttons are present these buttons are created based on the records in my table
what i need is when i cilck the buttons with value Apply Now i need to change it to applied each time i click the button it is submittiing the form
<form action="" method="POST">
<?php
include('conn.php');
$i=0;
$rs=mysqli_query($con,"select * from post_job");
while($arr=mysqli_fetch_row($rs))
{
$i++;
${'job_id' . $i} = $arr[0];
${'company_id' . $i} = $arr[1];
echo '<div class="tab_grid">';
echo '<div class="jobs-item with-thumb">';
echo "<div class='thumb'><a href='#'><img src='company/$arr[9].jpg' class='img-responsive' alt=''/></a></div>";
echo '<div class="jobs_right">';
echo "<div class='date'><span>$arr[10]</span></div>";
echo "<div class='date_desc'><h6 class='title'><a href='#'>$arr[2]</a></h6>";
echo "<span class='meta'>$arr[7]</span>";
echo "</div>";
echo "<div class='clearfix'> </div>";
echo "<ul class='top-btns'>";
echo "<li><a href='#' class='fa fa-plus toggle'></a></li>";
echo "<li><a href='#' class='fa fa-star'></a></li>";
echo "<li><a href='#' class='fa fa-link'></a></li>";
echo "</ul>";
echo "<p class='description'>$arr[3]</a></p>";
echo '<input type="button" name="submit'.$i.'" id="sbtid'.$i.'" value="Apply Now" required="required" class="btn btn-default pull-left" onclick="return changeText("sbtn");" >';
echo "</div>";
echo "<div class='clearfix'> </div>";
echo "</div>";
echo "</div>";
}
?>
</form>
<?php
for($j=1;$j<=$i;$j++)
{
if(isset($_POST['submit'.$j]))
{
include('conn.php');
mysqli_query($con,"insert into job_applied values(DEFAULT,'${'job_id'.$j}','${'company_id'.$j}','$id')");
}
}
?>
I try to fetch all image from database but only one image is shown.
this is my code:
<?php
$query = "SELECT id, name, image, price FROM products ORDER BY name";
$stmt = $con-> prepare ( $query );
$stmt->execute();
$num = $stmt->rowCount();
if($num>0){
//some html code
this is my while loop:
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
echo "<div class='inner'>";
//creating new table row per record
echo "<ul>";
echo "<li>";
echo "<a class='thumb' href='images/{$image}'>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<span class='hoodnamecarousel'>{$name}</span>";
echo"</a>";
echo "</li>";
echo "</ul>";
echo "</div>";
echo "</div>";
This is second part of displaying image after click on any image:
echo "<div id='thumbs2' style='display:none;'>";
echo "<div class='inner'>";
echo "<ul>";
echo "<li>";
echo "<a class='thumb' href='images/{$image}'></a>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<span class='hoodnamecarousel'>{$name}</span>";
echo "<br />";
echo "<span class='price'>{$price}</span>";
echo "<br />";
echo "<a href='add_to_cart.php?id={$id}&name={$name}' class='button btn btn-primary'>";
echo "افزودن به سبد <span class='glyphicon glyphicon-shopping-cart'></span>";
echo "</a>";
echo "</li>";
echo"</ul>";
echo "</div>";
echo "<div id='closeBtn'>بستن</div>";
}
echo "</div>";
echo "</div>";
}
else {
echo "محصولات در حال بروزرسانی می باشند.";
}
?>
this code only display 1 image and doesn't show other images from database
please help me!