PHP syntax error “unexpected $end” at last line - php

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
}

Related

php loop repetitive execution

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.

PHP - How to remove comma or image if database field is empty

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'] . ",&nbsp" . $row['address_2'] . ",&nbsp" . $row['town'] . ",&nbsp" . $row['county'] . ",&nbsp" . $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'])){
?>
&nbsp <?=$row['address_2']?>,
<?php
}
?>
&nbsp <?=$row['town']?>,&nbsp <?=$row['county']?>,&nbsp <?=$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'

PHP get array value and save it to be displayed in another page

I have a page displaying data from an array. When the user click on one of the picture displayed, I would need to save the value $row["Rif"] as I'd need to display the item details in another page.
I was looking around but it seems that Jquery, Ajax are the only available solutions but I don't know these.
Is there any way to implement it using just PHP?
Thank you!
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<div class='col-md-3 col-sm-6 col-xs-12'>
<div class='property-container'>
<div class='property-image'>
<img src='img/img02.jpg' alt='test theme'>
<div class='property-price'>
" . $row["DescCom"] . "<br>
<span>" . "€ ". $row["Pre"] . " </span>
</div>
<div class='property-status'>
<span>" . $row["Rif"] . "</span>
</div>
</div>
<div class='property-features'>
<span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
<span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
<span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
</div>
<div class='property-content'>
<h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
<button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
</div>
</div>
</div>";
}
} else {
echo '0 results';
}
$conn->close();
?>
Assuming the data is stored in $row["Rif"]
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<div class='col-md-3 col-sm-6 col-xs-12'>
<div class='property-container'>
<div class='property-image'>
// if this is the image you can hyper-link it to next page that will carry the id as well.
<img src='img/img02.jpg' alt='test theme'>
<div class='property-price'>
" . $row["DescCom"] . "<br>
<span>" . "€ ". $row["Pre"] . " </span>
</div>
<div class='property-status'>
<span>" . $row["Rif"] . "</span>
</div>
</div>
<div class='property-features'>
<span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
<span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
<span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
</div>
<div class='property-content'>
<h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
<button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
</div>
</div>
</div>";
}
} else {
echo '0 results';
}
$conn->close();
?>
if this is the image you can hyper-link it to next page that will carry the id as well.
<img src='img/img02.jpg' alt='test theme'>

Getting a link to show only when logged in with html tag at quotation

I'm having difficulty getting this to work, I keep getting errors on having a link show when the user is authenticated. I have this similar code on other parts of my site and it works, but not here.
The code
<div class=\"avatar\">
<?php if (isset($_SESSION['access_token']))
{ echo "<a href='userfeed.php?uid={$uid}&{$username}'><img src=\"{$avatar}\">; }
else
{ echo "<img src=\"{$avatar}\">; } ?>
</div>
The Error:
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE
Edit: I've tried all the answers and no luck.. what I'm thinking is the place in the code might effect this.. so below is the whole main div:
// display all user likes
foreach ($result->data as $media) {
$content = "<div id=box>";
// output media
if ($media->type === 'video') {
// video
$content .= "<div class=mainimg><video class=\"video-js vjs-default-skin\" controls preload=\"none\" width=\"170\" height=\"170\" poster=\"{$poster}\"
data-setup='{}'>
<source src=\"{$source}\" type=\"video/mp4\" />
</video></div><div class=midsection>{$comment}</div>";
} else {
// image
$content .= "<div class=mainimg><a class=\"fancybox\" rel=\"group\" href=\"{$fullimage}\" title=\"<b>{$username}</b> - {$comment}\"><img src=\"{$image}\"></a></div><div class=midsection>{$comment}</div>";
}
// create lower section
$content .= "<div class=\"pfooter\">
<div class=\"avatar\">
if (isset($_SESSION['access_token']))
{ <a href='userfeed.php?uid={$uid}&{$username}'><img src=\"{$avatar}\">; }
else
{ <img src=\"{$avatar}\">; }
</div>
<p>$username</p>
<p><img class=\"heart{$id2}\" style=\"cursor:pointer\" src=\"img/heart.png\" onclick=\"likePic('{$id2}','\'{$username}\'')\">{$numlikes} <img src=\"img/comment.png\">{$comcount}</p>
</div>";
// output media
echo $content . "</div>";
}
This still gives me the same error. I take this statement out, works fine.
{ echo "<a href='userfeed.php?uid={$uid}&{$username}'><img src=\"{$avatar}\">; }
You hae a syntax error here, you open a " at the start of the anchor, then re-open another pair for the img tag.
You also have the same problem on this line { echo "<img src=\"{$avatar}\">; } ?>
Copy and paste the following code
<div class="avatar">
<?php if (isset($_SESSION['access_token']))
{ echo "<a href='userfeed.php?uid={$uid}&{$username}'><img src=\"{$avatar}\">"; }
else
{ echo "<img src=\"{$avatar}\">"; }
?>
</div>
Your problem is in two echo you forget the last "
See this part of your code:
$content .= "<div class=\"pfooter\">
<div class=\"avatar\">
if (isset($_SESSION['access_token']))
{ <a href='userfeed.php?uid={$uid}&{$username}'><img src=\"{$avatar}\">; }
else
{ <img src=\"{$avatar}\">; }
</div>
<p>$username</p>
<p><img class=\"heart{$id2}\" style=\"cursor:pointer\" src=\"img/heart.png\" onclick=\"likePic('{$id2}','\'{$username}\'')\">{$numlikes} <img src=\"img/commen
t.png\">{$comcount}</p>
</div>";
Replace with this:
$content .= "<div class=\"pfooter\">"
."<div class=\"avatar\">"
if (isset($_SESSION['access_token'])) {
$content .= "<a href='userfeed.php?uid={$uid}&{$username}'><img src=\"{$avatar}\">";
}
else {
$content .= "<img src=\"{$avatar}\">;"
}
$content .= "</div>"
."<p>$username</p>"
."<p><img class=\"heart{$id2}\" style=\"cursor:pointer\" src=\"img/heart.png\" onclick=\"likePic('{$id2}','\'{$username}\'')\">{$numlikes} <img src=\"img/comm
ent.png\">{$comcount}</p>"
."</div>";
Error is here:
echo "<a href='userfeed.php?uid={$uid}&{$username}'><img src=\"{$avatar}\">;
You can use ' "" ' or " '' ".But " "" " or ' '' ' are not accepted. And here you make error in the formatting of quotation. You didn't end the first double quotation of echo "
Replace that php code with this code.
if (isset($_SESSION['access_token']))
{
echo' <img src="'.$avatar.'">';
}
else { echo '<img src="'.$avatar.'"\>'; }

Div not looping correctly

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++;
}

Categories