I have a problem whith my " Bootstrap Collapse" . My query display only the fist $ID_Producto of all my rows.
<?php
$Consulta_Productos = $Conexion ->query( "SELECT * FROM productos ORDER BY Producto_Categoria");
while($Fila_Productos = $Consulta_Productos->fetch_assoc())
{
$ID_Producto = $Fila_Productos['ID_Producto'];
?>
<span data-toggle="collapse" data-target="#demo">Show ID <?php echo $ID_Producto ?></span>
<div id="demo" class="collapse">
<?php echo $ID_Producto; ?>
</div>
<br>
<?php
}
?>
your data-target="#demo" and id="demo" are the same for all the products.
try this
<?php
$Consulta_Productos = $Conexion ->query( "SELECT * FROM productos ORDER BY Producto_Categoria");
while($Fila_Productos = $Consulta_Productos->fetch_assoc())
{
$ID_Producto = $Fila_Productos['ID_Producto'];
?>
<span data-toggle="collapse" data-target="#demo<?php echo $ID_Producto; ?>">Show ID <?php echo $ID_Producto ?></span>
<div id="demo<?php echo $ID_Producto; ?>" class="collapse">
<?php echo $ID_Producto; ?>
</div>
<br>
<?php
}
?>
Related
I want to give a little style for my comment section, here is the code without any css, but i want to give it some style
<div id="comments">
<?php
$sql = "SELECT * FROM comments ORDER BY id LIMIT 2";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<p>";
echo $row['author'];
echo "<br>";
echo $row['message'];
echo "<br>";
echo $row['time'];
echo "</p>";
}
} else {
echo "there are no comments!";
}
?>
</div>
<button>More comments</button>
and down here is my html section of which i want to appear while handling my php comments where USER, COMMENT and TIME are are stored in my database, here is the html, how can i echo the above variables into the below html tags ?
<div class="media response-info">
<div class="media-left response-text-left">
<a href="#">
<img class="media-object" src="images/c1.jpg" alt="">
</a>
<h5>USER</h5>
</div>
<div class="media-body response-text-right">
<p>COMMENT</p>
<ul>
<li>TIME</li>
<li>Reply</li>
</ul>
</div>
</div>
You can do like this:
<div id="comments">
<?php
$sql = "SELECT * FROM comments ORDER BY id LIMIT 2";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) { ?>
<div class="media response-info">
<div class="media-left response-text-left">
<a href="#">
<img class="media-object" src="images/c1.jpg" alt="">
</a>
<h5><?php echo $row['author']; ?></h5>
</div>
<div class="media-body response-text-right">
<p><?php echo $row['message']; ?></p>
<ul>
<li><?php echo $row['time']; ?> </li>
<li>Reply</li>
</ul>
</div>
</div>
<?php }
} else {
echo "there are no comments!";
}
?>
</div>
hope it will help you.
I am trying with php 7.0 as everyone recommend me here to start with it as 5.6 has been depreveted . But after writing its code i am unable to fetch the values from database. what wrong i am doing here. thank you
//This is my aboutus page//
<div class="col-lg-10">
<?php include('config.php');
$query = mysqli_query('select * from about ');
while($row = mysqli_fetch_array($query)){
?>
<h5>
<?php echo $row['about_desc'] ;?>
<br>
<br>
<?php echo $row['about_desc1']; ?>
<br>
<br>
<?php echo $row['about_desc2'] ;?>
<br>
<br>
<?php echo $row['about_desc3'] ;?>
<br>
<br>
<?php echo $row['about_desc4']; ?>
</h5>
<hr class="featurrate-divider">
<?php
}
?>
</div>
</div>
<div id="tab-1">
<?php include('config.php ');
$query = mysqli_query('select * from news LIMIT 0,2');
while($row = mysqli_fetch_array($query)){
?>
<div class="news">
<h4><u><?php echo $row['news_name']; ?></u></h4>
<h5><font color="black"><?php echo $row['dat']; ?></font></h5>
<p><?php echo $row['news_desc']; ?></p>
se mer >>
</div>
<hr class="featurrate-divider">
<?php
}
?>
</div>
//This is my config.php file//
<?php
$connection = mysqli_connect('localhost','root','','dandelion') or die(mysqli_error($connection));
?>
Looking for good suggestion as a learner. thank you
Your About us page should be like this:
<body>
<div class="col-lg-10">
<?php include('config.php');
$query = mysqli_query($connection, 'select * from about ');
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
?>
<h5>
<?php echo $row['about_desc'] ;?>
<br>
<br>
<?php echo $row['about_desc1']; ?>
<br>
<br>
<?php echo $row['about_desc2'] ;?>
<br>
<br>
<?php echo $row['about_desc3'] ;?>
<br>
<br>
<?php echo $row['about_desc4']; ?>
</h5>
<hr class="featurrate-divider">
<?php
}
?>
</div>
</div>
<div id="tab-1">
<?php include('config.php ');
$query = mysqli_query($connection, 'select * from news LIMIT 0,2');
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
?>
<div class="news">
<h4><u><?php echo $row['news_name']; ?></u></h4>
<h5><font color="black"><?php echo $row['dat']; ?></font></h5>
<p><?php echo $row['news_desc']; ?></p>
se mer >>
</div>
<hr class="featurrate-divider">
<?php
}
?>
</div>
</body>
if your database connection is sucessfully work and problem with fetching data than use number.it may be useful to fetch the data.
<?php echo $row[o]; ?>
<?php echo $row[1]; ?>
instead of
<?php echo $row['about_desc1']; ?>
I'm making a php tag script for my website.
I have completed the code, but I'm afraid my code is too long.
Can my code be more simple and short?
<?php
include("admin/apps/site-settings.php"); // database connection
$albumq = mysql_query("select * from albums order by rand() limit 20");
while($album = mysql_fetch_array($albumq)){
$name_a = str_replace("'s","",$album['name']);
$name_b = str_replace(""","",$name_a);
$name_c = str_word_count($name_b, 1);
?>
<?php if(!empty($name_c[0])){?>
<a href="search-<?php echo $name_c[0];?>.html">
<div class="tag">
<?php echo $name_c[0];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[1])){?>
<a href="search-<?php echo $name_c[1];?>.html">
<div class="tag">
<?php echo $name_c[1];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[2])){?>
<a href="search-<?php echo $name_c[2];?>.html">
<div class="tag">
<?php echo $name_c[2];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[3])){?>
<a href="search-<?php echo $name_c[3];?>.html">
<div class="tag">
<?php echo $name_c[3];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[4])){?>
<a href="search-<?php echo $name_c[4];?>.html">
<div class="tag">
<?php echo $name_c[4];?>
</div>
</a>
<?php }?>
<?php if(!empty($name_c[5])){?>
<a href="search-<?php echo $name_c[5];?>.html">
<div class="tag">
<?php echo $name_c[5];?>
</div>
</a>
<?php }?>
Output in the website:
I'm running it on localhost so I can't provide a link at the moment.
<?php
include("admin/apps/site-settings.php"); // database connection
$albumq = mysql_query("select * from albums order by rand() limit 20");
while($album = mysql_fetch_array($albumq)){
$name_a = str_replace("'s","",$album['name']);
$name_b = str_replace(""","",$name_a);
$name_c = str_word_count($name_b, 1);
foreach ($name_c as $value)
{
if (!empty($value))
{
echo "
<a href='search-{$value}.html'>
<div class='tag'>
{$value}
</div>
</a>";
}
}
}
?>
Use foreach loop for same , use like
if(count($name_c) > 0)
{
foreach($name_c as $name)
{
?>
<a href="search-<?php echo $name; ?>.html">
<div class="tag">
<?php echo $name; ?>
</div>
</a>
<?php
}
}
My selector when selected all is updating only 1 row? however if i select a row, it cannot be updated? please see my code if something's wrong, needed help.
This is the form:
<form action="read_message.php" method="post">
<div class="pull-right">
<button class="btn btn-info" name="read"><i class="icon-check"></i> Read</button>
Check All <input type="checkbox" name="selectAll" id="checkAll" />
<script>
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
</script>
</div>
<ul class="nav nav-pills">
<li class="active"><i class="icon-envelope-alt"></i>inbox</li>
<li class=""><i class="icon-envelope-alt"></i>Send messages</li>
</ul>
<?php
$query_announcement = mysql_query("select * from message_received
LEFT JOIN user ON user.user_id = message_received.user_id
where message_received.receiver_id = '$session_id' order by date_sent DESC
")or die(mysql_error());
$count_my_message = mysql_num_rows($query_announcement);
if ($count_my_message != '0'){
while($row = mysql_fetch_array($query_announcement)){
$id = $row['message_id'];
$id_2 = $row['message_id'];
$fn = $row['firstname'];
$ln = $row['lastname'];
$status = $row['message_status'];
$sender = $row['user_id'];
$sender_name = $fn.' '.$ln;
$receiver = $row['receiver_id'];
?><div class="alert alert-info">
<div class="post" id="del<?php echo $id; ?>">
<div class="message_content">
<?php echo $row['content']; ?>
</div>
<div class="pull-right">
<?php if ($status == 'read'){
}else{ ?>
<input id="" class="" name="selector[]" type="checkbox" value="<?php echo $id; ?>">
<?php } ?>
</div>
<hr>
Send by: <strong><?php echo $fn.' '.$ln; ?></strong>
<i class="icon-calendar"></i> <?php echo $row['date_sent']; ?>
<div class="pull-right">
<a class="btn btn-link" href="#reply<?php echo $id; ?>" data-toggle="modal" ><i class="icon-reply"></i> Reply </a>
</div>
<div class="pull-right">
<a class="btn btn-link" href="#<?php echo $id; ?>" data-toggle="modal" ><i class="icon-remove"></i> Remove </a>
<?php include("remove_inbox_message_modal.php"); ?>
<?php include("reply_inbox_message_modal_user.php"); ?>
</div>
</div>
</div>
<?php }}else{ ?>
<div class="alert alert-info"><i class="icon-info-sign"></i> No Message Inbox</div>
<?php } ?>
</form>
However, nevermind the isset for reply, the problem is the first function for isset read, what's wrong with the query? this is the function for the selector, read_message.php,
<?php include('connect.php'); ?>
<?php
include('session.php');
if (isset($_POST['read'])){
$id=$_POST['selector'];
$N = count($id);
for($i=0; $i < $N; $i++)
{
$result = mysql_query("update message_received set message_status = 'read' where message_id='$id[$i]'");
}
echo "<script> alert('Successfully Updated') </script>";
echo " <script>location.replace('messages.php')</script>";
}
?>
<?php
if (isset($_POST['reply'])){
$sender = $_POST['sender'];
$receiver = $_POST['receiver'];
$id2=$_POST['id2'];
$qwe = $_POST['qwe'];
mysql_query("update message_received set message_status = 'read' where message_id='$id2'");
mysql_query("insert into message_received (user_id,receiver_id,content,date_sent) values('$receiver','$sender','$qwe',NOW())")or die(mysql_error());
mysql_query("insert into message_sent (receiver_id,user_id,content,date_sent) values('$sender','$receiver','$qwe',NOW())")or die(mysql_error());
echo "<script> alert('Your message has been sent') </script>";
echo " <script>location.replace('messages.php')</script>";
?>
<script>
alert('Message Sent');
window.location ="messages.php";
</script>
<?php
}
?>
I am trying to create a horizontal div from while loop but the result is that i am getting the same products in both the column div. here is my code.
<div class="ui-grid-a">
<?php $query = mysql_query("select * from table");
while($sdeals = mysql_fetch_array($query){ ?>
<div class="ui-block-a">
<a href="">
<div style="height:120px; text-align: center;">
<div style="font-size:60%;margin-top:5px;"><?php echo $sdeals['productname']; ?></div>
<img style="margin-top:5px;" height="67" width=50" src="../thumbnails/<?php echo $sdeals['imageg1']; ?>" >
<?php if(!empty($sdeals['coupon_code'])) { ?>
<div style="font-size:60%;margin-top:5px;"> Use Coupon: <?php echo $sdeals['coupon_code']; ?></div>
<?php } ?>
<div style="font-size:60%;margin-top:5px;">Rs.<?php echo $sdeals['price']; ?></div>
</div>
</a>
<div class="ui-block-b">
<a href="">
<div style="height:120px; text-align: center;">
<div style="font-size:60%;margin-top:5px;"><?php echo $sdeals['productname']; ?></div>
<img style="margin-top:5px;" height="67" width=50" src="../thumbnails/<?php echo $sdeals['imageg1']; ?>" >
<?php if(!empty($sdeals['coupon_code'])) { ?>
<div style="font-size:60%;margin-top:5px;"> Use Coupon: <?php echo $sdeals['coupon_code']; ?></div>
<?php } ?>
<div style="font-size:60%;margin-top:5px;">Rs.<?php echo $sdeals['price']; ?></div>
</div>
</a>
</div>
<?php } ?>
</div>
the output i am getting is that
block-a block-b
pro1 pro1
pro2 pro2
pro3 pro3
pro4 pro4
the correct output should be
block-a block-b
pro1 pro2
pro3 pro4
pro5 pro6
pro7 pro8
pro9 pro10
<div class="ui-grid-a">
<?php
$num=0;
$class1 = "";
$query = mysql_query("select * from table");
while($sdeals = mysql_fetch_array($query)
{
if($num%2==0)
{ $class1 = 'class="ui-block-a"';}
else
{ $class1 = 'class="ui-block-b"';}
?>
<div <?php echo $class1;?>>
<a href="">
<div style="height:120px; text-align: center;">
<div style="font-size:60%;margin-top:5px;"><?php echo $sdeals['productname']; ?></div>
<img style="margin-top:5px;" height="67" width=50" src="../thumbnails/<?php echo $sdeals['imageg1']; ?>" >
<?php if(!empty($sdeals['coupon_code'])) { ?>
<div style="font-size:60%;margin-top:5px;"> Use Coupon: <?php echo $sdeals['coupon_code']; ?></div>
<?php } ?>
<div style="font-size:60%;margin-top:5px;">Rs.<?php echo $sdeals['price']; ?></div>
</div>
</a>
</div>
<?php
$num++;
} //while loop closing
?>
</div>
You have not moved the row pointer onto the next row between the 2 DIV's so $sdeals contains the same result in both DIV's.
<div class="ui-grid-a">
<?
php $query = mysql_query("select * from table");
$blockA = true;
while($sdeals = mysql_fetch_array($query){
if ( $blockA ) {
echo '<div class="ui-block-a">';
} else {
echo '<div class="ui-block-b">';
}
$blockA = ! $blockA;
?>
<a href="">
<div style="height:120px;text-align:center;">
<div style="font-size:60%;margin-top:5px;"><?php echo $sdeals['productname']; ?></div>
<img style="margin-top:5px;" height="67" width=50" src="../thumbnails/<?php echo $sdeals['imageg1']; ?>" >
<?php
if(!empty($sdeals['coupon_code'])) { ?>
<div style="font-size:60%;margin-top:5px;"> Use Coupon: <?php echo $sdeals['coupon_code']; ?></div>
<?php } ?>
<div style="font-size:60%;margin-top:5px;">Rs.<?php echo $sdeals['price']; ?></div>
</div>
</a>
</div>
<?php
}
?>
</div>