I'm trying to get my code to display multiple divs. But seems to only display one div correctly.
<?php
// database connection
//$result = mysqli_query($con,"SELECT * FROM test WHERE field5='Cohen'");
echo " <div id='1'>";
while($row = mysqli_fetch_array($result))
{
echo "<div class='tutorName'>" . $row['field1'] . "</div>";
echo "<div class='tutorPrice'>" . $row['field2'] . "</div>";
echo "<div class='tutorInstitution'>" . $row['field3'] . "</div>";
echo "<div class='tutorLocale'>" . $row['field4'] . "</div>";
echo "<div class='tutorPhone'>" . $row['field5'] . "</div>";
}
echo "</div>";
mysqli_close($con);
?>
I want the following to loop and over using the fields above (field1, feild2, etc):
<div id='' name='' class="column threecol">
<div class="course-preview premium-course">
<div class="course-image">
<img src="img.png" />
<div class="course-price">
<div class="corner-wrap">
<div class="corner"></div>
<div class="corner-background"></div>
</div>
<div class="price-text"><span class="amount">PerHour</span></div>
</div>
</div>
<div class="course-meta">
<header class="course-header">
<h5 class="nomargin">TutorName </h5>
<div class='gender'>Gender: </div>
<div class='price-range'>Price Range: </div>
<div class='institute'> Institute: </div>
</header>
</div>
</div>
</div>
Is your $result line really commented out in the real code? Or did you just add that comment for the example? If it's commented-out in the code you're testing, then that's probably the issue.
you want this? , 1 div wrap all content like table tr
$i=1;
while($row = mysqli_fetch_array($result))
{
echo " <div id='{$i}'>";
echo "<div class='tutorName'>" . $row['field1'] . "</div>";
echo "<div class='tutorPrice'>" . $row['field2'] . "</div>";
echo "<div class='tutorInstitution'>" . $row['field3'] . "</div>";
echo "<div class='tutorLocale'>" . $row['field4'] . "</div>";
echo "<div class='tutorPhone'>" . $row['field5'] . "</div>";
echo "</div>";
$i++;
}
Related
When I click page number in DataTable, it is not moving to next page instead it loads the whole page again.
But if I click the DataTable sorting button and again I click the pagination page number, the DataTable is working fine. Can anyone help me to solve this. Thanks in advance.
<?php include 'header.php'; ?>
</style>
<!-- Breadcrumbs -->
<section class="bg-gray-7">
<div class="breadcrumbs-custom box-transform-wrap context-dark">
<div class="container">
<h3 class="breadcrumbs-custom-title">Sailing Schedules</h3>
<div class="breadcrumbs-custom-decor"></div>
</div>
<div class="box-transform" style="background-image: url(images/bg-typography.jpg);"></div>
</div>
<div class="container">
<ul class="breadcrumbs-custom-path">
<li>Home</li>
<li class="active">Sailing Schedule</li>
</ul>
</div>
</section>
<br>
<br>
<div class="container">
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Include config file
require 'config.php';
$sql = "SELECT * FROM long_sched";
if($result = mysqli_query($con, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table-custom table-custom-primary' id ='long_schd_table'>";
echo "<thead>";
echo "<tr>";
echo "<th>Service Name</th>";
echo "<th>Description</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td><a href=http://localhost/permatest/". $row['long_filepath'] . " target='_self' download>".$row['long_service']."</a></td>";
echo "<td>" . $row['long_desc'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else {
echo "<p class='lead'><em>No records were found.</em></p>";
} else {
echo "ERROR: Could not able to execute ".$sql." " . mysqli_error($con);
}
// Close connection
mysqli_close($con);
?>
</div>
</section>
<br>
<br>
<?php include 'off_footer.php'; ?>
<script>
$('#long_schd_table').DataTable({});
</script>
The above code is giving this error but in my console I didn't get any error information.
Here is the problem that while looping the php in while loop in w3-row-padding of w3 responsive layout . The layout breaks
Here is the source code
<?php
$r=0;
while($r<ceil($fetch_row_count/4))
{ ?>
<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">
<?php
while($row=mysqli_fetch_array($res))
{
?>
<div class="w3-quarter">
<img src="admin/uploads/<?php echo $row['image']; ?>" alt="noodles" style="width:50%">
<h3><?php echo $row['title']; ?></h3>
<p><?php echo $row['description']; ?> </p>
</div>
<?php
}
$r++;
}
?>
</div>
Thanks for reply and comments in advance
That bottom div was not being added for each of your padded containers.
The way the code is written you are adding a padded container and then adding your w3-quarter div for each of your result sets and then repeating that a bunch of times with what looks like to me the same set of data in each one.
What you are probably trying to accomplish is just making one padded div and then echo out your result set with the w3-quarter divs inside of it.
Here is your original way with the bottom div corrected:
<?php
$r=0;
while($r<ceil($fetch_row_count/4)) {
echo
'<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">';
while($row=mysqli_fetch_array($res)){
echo
'<div class="w3-quarter">' .
'<img src="admin/uploads/' . $row['image'] . '" alt="noodles" style="width:50%">' .
'<h3>' . $row['title'] . '</h3>' .
'<p>' . $row['description'] . '</p>' .
'</div>';
}
$r++;
echo
'</div>';
}
?>
Here is the way I think you are trying to do it: (Just guessing)
<?php
echo
'<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">';
$r = 0;
while($row=mysqli_fetch_array($res)){
echo
'<div class="w3-quarter">' .
'<img src="admin/uploads/' . $row['image'] . '" alt="noodles" style="width:50%">' .
'<h3>' . $row['title'] . '</h3>' .
'<p>' . $row['description'] . '</p>' .
'</div>';
$r++;
//I would not actually try to control how many results you add like this.
//I would get the results from a better formatted query.
if($r < ceil($fetch_row_count/4)){
break;
}
}
echo
'</div>';
?>
what can i change in this code to make the output from This to make it look like This
The two 'This' links are screenshots of the layouts
I want all the boxes to be in-line / next to each other just like the second screenshot.
i programmed the layout in html and it worked when trying php the layout just messed up.
function getTest(){
global $con;
$get_pro = "select * from drinks";
$run_pro = mysqli_query($con, $get_pro);
while($row=mysqli_fetch_array($run_pro)){
$id = $row['id'];
$title = $row['title'];
$cat = $row['cat'];
$image = $row['image'];
$desc = $row['desc'];
$qty = $row['qty'];
$price =$row['price'];
$status= $row['status'];
echo "<!--==========================\n";
echo " Price Menu\n";
echo "============================-->\n";
echo " <!-- Page Content -->\n";
echo " <main class=\"entry-content\">\n";
echo " <section class=\"page-section\">\n";
echo " <div class=\"container\">\n";
echo " \n";
echo " <div class=\"row\">\n";
echo " <div class=\"col-md-12\">\n";
echo " <div class=\"isotope-filters\" role=\"group\">\n";
echo " <div class=\"btn-group\">\n";
// the categories go here
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " <br><br>\n";
echo " <div class=\"row isotope-wrapper isotope-beers-wrapper\">\n";
echo " <div class=\"isotope isotope-beers gutter\">\n";
echo " <div class=\"grid-item col-lg-3 col-md-3 col-sm-6 col-ms-6 col-xs-12 $cat\">\n";
echo " <div class=\"grid-wrapper\">\n";
echo " <a href=\"javascript:void(0);\" data-remodal-target=\"bottle-$id\">\n";
echo " <figure style=\"background-image: url('admin/images/drinks/$image')\">\n";
if ($row['status'] === 'Yes'){
echo " <div class=\"offer\"></div>\n";
}
echo " <figcaption class=\"grid-content\">\n";
echo " <h5 class=\"grid-title\"><span>$title</span></h5>\n";
echo " </figcaption>\n";
echo " </figure>\n";
echo " </a>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo "\n";
echo " </div>\n";
echo " </section>\n";
echo " </main><!-- /.enry-content -->\n";
echo "\n";
echo " <!-- Off-Page Content -->\n";
echo " <!-- Mobile Navigation (Left Panel) -->\n";
echo " <!-- Preloader -->\n";
echo " <div class=\"introLoading\"></div>\n";
echo " <!-- Back to Top -->\n";
echo " <div>\n";
echo " <a class=\"back-to-top fa fa-chevron-up\" href=\"javacript:void(0);\"></a>\n";
echo " </div>\n";
echo " <!-- Modal Content -->\n";
echo " <div class=\"remodal-bg\">\n";
echo " <!-- Item One -->\n";
echo " <div class=\"remodal modal-beers\" data-remodal-id=\"bottle-$id\">\n";
echo " <button data-remodal-action=\"close\" class=\"remodal-close\"></button>\n";
echo " <div class=\"row\">\n";
echo " <div class=\"col-md-5 col-sm-12 col-xs-12\">\n";
echo " <div class=\"item-modal-image\">\n";
echo " <a class=\"image-lightbox\" href=\"admin/images/drinks/$image\"><img alt=\"\" src=\"admin/images/drinks/$image\" /></a>\n";
echo " </div>\n";
echo " </div>\n";
echo " <div class=\"col-md-7 col-sm-12 col-xs-12\">\n";
echo " <h3>$title</h3>\n";
echo " <p>$desc</p>\n";
echo " <table class=\"table\">\n";
echo " <tbody>\n";
echo " <tr>\n";
echo " <td>Price:</td>\n";
echo " <td>£$price</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Quantity:</td>\n";
echo " <td>$qty</td>\n";
echo " </tr>\n";
echo " </tbody>\n";
echo " </table>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div> \n";
echo "\n";
echo " <!--==========================\n";
echo " Price Menu end\n";
echo "============================-->\n";
}
}
I see you are using bootstrap, I suggest you to use this kind of structure
Take a look on this page
<div class="container">
<div class="row">
<span class="col-lg-3 col-sm-12 picture">
<img class="img-thumbnail" src="//placehold.it/200x200">
</span>
<span class="col-lg-3 col-sm-12">
<img class="img-thumbnail" src="//placehold.it/200x200">
</span>
<span class="col-lg-3 col-sm-12">
<img class="img-thumbnail" src="//placehold.it/200x200">
</span>
<span class="col-lg-3 col-sm-12">
<img class="img-thumbnail" src="//placehold.it/200x200">
</span>
</div></div>
Take all of your html out of the echos and instead insert PHP into your html. First you need to identify the areas of your html which need to loop, for example if my original html was this:
<div class="row">
<div class="col-xs-12 col-sm-4">
Box 1
</div>
<div class="col-xs-12 col-sm-4">
Box 2
</div>
<div class="col-xs-12 col-sm-4">
Box 3
</div>
</div>
But I wanted to generate the 3 boxes dynamically instead, my PHP would be something like this, which you can wrap in a function:
<?php
function outputStuff(){
$contents = array("Box 1","Box 2","Box3");
?>
<div class="row">
<?php foreach($contents as $value):?>
<div class="col-xs-12 col-sm-4">
<?php echo $value; ?>
</div>
<?php endforeach;?>
</div>
<?php
} // end the function
?>
The row has to be outside the loop otherwise it will be created for each item and clear the floats on the columns. Use these basic principles and you will achieve what you want.
I am trying to figure out how to remove the comma from, say the
['address_2'] field if this is left empty and also not show the icons for say the ['tel'] phone number if this is not inputted, It seems hard working within the echo.
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query)) {
echo "<div class='result-container'>
<div class='result-wrap'>
<div class='leftbox'>
<div class='titlebox'>
<h2>" . $row['company_name'] . "</h2>
<p><strong>" . $row['company_services'] . "</strong></p>
</div>
<div class='box'><strong> Address: </strong>" . $row['address_1'] . ", " . $row['address_2'] . ", " . $row['town'] . ", " . $row['county'] . ", " . $row['postcode'] . "</div>
<div class='box'><strong> Telephone: </strong>" . $row['tel'] ."<strong> Mobile: </strong>". $row['mob'] . "</div>
<div class='iconbox'>
<a href='" . $row['tel'] . "'><img src='img/icons/phone.png' class='hvr-push'></a>
<a href='" . $row['mob'] . "'><img src='img/icons/mobile.png' class='hvr-push'></a>
<a href='mailto:" . $row['email'] . "'><img src='img/icons/email.png' class='hvr-push'></a>
<a href='" . $row['web_url'] . "'><img src='img/icons/web.png' class='hvr-push'></a>
</div>
<div class='buttonwrap'><div class='buttonbox'><p>View Profile</p></div></div>
</div>
<div class='rightbox'>
<div class='service-pic'>
<img src='img/image1.png'>
</div>
<div class='mapbox'>
" . $row['gmap_url'] . "
</div>
</div>
</div>
<br/>";
}
}
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query)) {
?>
<div class='result-container'>
<div class='result-wrap'>
<div class='leftbox'>
<div class='titlebox'>
<h2><?=$row['company_name']?></h2>
<p><strong><?=$row['company_services']?></strong></p>
</div>
<div class='box'><strong> Address: </strong><?=$row['address_1']?>,
<?php
if(!empty($row['address_2'])){
?>
  <?=$row['address_2']?>,
<?php
}
?>
  <?=$row['town']?>,  <?=$row['county']?>,  <?=$row['post code']?></div>
<div class='box'><strong> Telephone: </strong><?=$row['tel']?><strong> Mobile: </strong><?=$row['mob']?></div><div class='iconbox'>
<a href='
<?=$row['tel']?>'><img src='img/icons/phone.png' class='hvr-push'></a>
<a href='
<?=$row['mob']?>'><img src='img/icons/mobile.png' class='hvr-push'></a>
<a href='mailto:"
<?=$row['email']?>'><img src='img/icons/email.png' class='hvr-push'></a>
<a href='"
<?=$row['web_url']?>'><img src='img/icons/web.png' class='hvr-push'></a>
</div>
<div class='buttonwrap'><div class='buttonbox'><p>View Profile</p></div></div>
</div>
<div class='rightbox'>
<div class='service-pic'>
<img src='img/image1.png'>
</div>
<div class='mapbox'>
<?=$row['map_url']?>
</div>
</div>
You can use Mysql, see it here: http://php.net/manual/es/book.mysqli.php
And a final tip: 'Do not enter HTML into a echo'
I have that code included to the main.php and received syntax error “unexpected $end” at last line of this code even I put the } for the while loop. Please help
<?php
while($row=mysql_fetch_array($rs))
{
?>
<div class="center_title_bar"><?php echo $row['ProName']?></div>
<div class="prod_box_big">
<div class="top_prod_box_big"></div>
<div class="center_prod_box_big">
<?php
echo"<div class='product_img_big'>";
echo"<a href='javascript:popImage('".$row['ProPicture']."','".$row['ProName']."') title='".$row['ProName']."'><img src='".$row['ProPicture']."' alt='' border='0' /></a>";
echo"</div>";
echo"<div class='details_big_box'>";
echo"<div class='product_title_big'>'".$row['ProName']."'</div>";
echo"<div class='specifications'>'".$row['ProInfo']."'<br />";
echo"Trạng thái: <span class='blue'>";
if($row['ProQuantity'])
{
echo"Còn hàng";
}
else {
echo"Hết hàng";
}
echo"</span><br />";
echo"Bảo hành: <span class='blue'>".$row[ProWarranty]." tháng</span><br />";
echo"</div>";
echo"<div class='prod_price_big'><span class='price'>".number_format($row['ProPrice'],0,',','.')." VND</span></div>";
echo'Thêm vào giỏ';
?>
<a href="location:history.back()" class='compare'>Quay lại</a>
</div>
</div>
</div>
<div class="bottom_prod_box_big"></div>
}
Parse error: syntax error, unexpected $end in
If this is the whole script, you forgot to close the while loop from the begining, at the end of the file.
You need to add:
<?php } ?>
at the end of the file.
this is the script without error
while ($row = mysql_fetch_array($rs)) {
?>
<div class="center_title_bar"><?php echo $row['ProName'] ?></div>
<div class="prod_box_big">
<div class="top_prod_box_big"></div>
<div class="center_prod_box_big">
<?php
echo"<div class='product_img_big'>";
echo"<a href='javascript:popImage('" . $row['ProPicture'] . "','" . $row['ProName'] . "') title='" . $row['ProName'] . "'><img src='" . $row['ProPicture'] . "' alt='' border='0' /></a>";
echo"</div>";
echo"<div class='details_big_box'>";
echo"<div class='product_title_big'>'" . $row['ProName'] . "'</div>";
echo"<div class='specifications'>'" . $row['ProInfo'] . "'<br />";
echo"Trạng thái: <span class='blue'>";
if ($row['ProQuantity']) {
echo"Còn hàng";
} else {
echo"Hết hàng";
}
echo"</span><br />";
echo"Bảo hành: <span class='blue'>" . $row[ProWarranty] . " tháng</span><br />";
echo"</div>";
echo"<div class='prod_price_big'><span class='price'>" . number_format($row['ProPrice'], 0, ',', '.') . " VND</span></div>";
echo'Thêm vào giỏ';
?>
<a href="location:history.back()" class='compare'>Quay lại</a>
</div>
</div>
</div>
<div class="bottom_prod_box_big"></div>
<?php
}