how can i call datas in a row on html from database - php

i call datas from database but there are not in a row.
how can i do that.
codes;
<?php
$test=mysql_query("SELECT * FROM siteler");
$sayi=mysql_num_rows($test);
$deneme=mysql_fetch_row($test);
while ($deneme=mysql_fetch_assoc($test)) {
extract($deneme);
echo "<div class='container'>
<div class='row'>
<div class='col-md-3 col-sm-6 col-xs-12 back-colour'>
<p>$site_name </p>
<p>$site_info </p>
<p>$site_ref </p>
<p>$bet_turu </p>
</div>
</div>
</div>";}
?>
thats what happened
http://imgur.com/a/Hg2W6
thats what i want
http://imgur.com/CpE8RB8

Try this,
<?php
$test=mysql_query("SELECT * FROM siteler");
$sayi=mysql_num_rows($test);
$deneme=mysql_fetch_row($test);
?>
<div class='container'>
<div class='row'>
<?php
while ($deneme=mysql_fetch_assoc($test)) {
extract($deneme);
echo "<div class='col-md-3 col-sm-6 col-xs-12 back-colour'>
<p>$site_name </p>
<p>$site_info </p>
<p>$site_ref </p>
<p>$bet_turu </p>
</div>";
}
?>
</div>
</div>
Hope this will fix the issue

Related

I have an error in my code that does not allow me to show the results and/or show an error message in php

I have a little problem that might be syntax (since I'm not that good at php). Basically, I'm de-wrapping a code where there will be records where there will be a date (in this case, a foundation date, for example; 20-08-2027). So I created an "if". If there are records with the date, for example, 2027, the records appear. If there is not, then an error message will be displayed saying that there is still no record made with that date. I've tried a few things, but nothing worked. At this point, an error appears. Below will be the error. Please try to help me. It's no use saying more technical things, because I'm not that good at php. Thank you.
Error: "Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/host/public_html/template/year/2027.php on line 300"
2027.php
<section class="content products">
<div class="container">
<h1 class="hidden">Eventos</h1>
<div class="row">
<div class="col-sm-10">
<div class="row grid" id="products">
<div class="releated-products">
<div class="row grid" id="products">
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0) {
while($regi=mysqli_fetch_array($resu)){
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php
} else{
?>
<p>Nada!</p>
<?php
}
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
The reason you are getting the error because you have while loop in your if block that you are not closing.
Check the code below for this fixed version.
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0):
while($regi=mysqli_fetch_array($resu)):
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php endwhile; else: ?>
<p>Nada!</p>
<?php
endif;
?>
Move the last } bracket above }else{
<section class="content products">
<div class="container">
<h1 class="hidden">Eventos</h1>
<div class="row">
<div class="col-sm-10">
<div class="row grid" id="products">
<div class="releated-products">
<div class="row grid" id="products">
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0) {
while($regi=mysqli_fetch_array($resu)){
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php
} // while()
} else{
?>
<p>Nada!</p>
<?php
}
// } //wrong bracket
?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
For your own sanity it is a good idea leave a comment after closing bracket of a long code, so you know which block it belongs to.
Compiler can't be wrong, if it says there's syntax error then there is. The bracket before the else is closing the while loop - hence else cannot be used there, close the if condition. Here's the corrected code:
<section class="content products">
<div class="container">
<h1 class="hidden">Eventos</h1>
<div class="row">
<div class="col-sm-10">
<div class="row grid" id="products">
<div class="releated-products">
<div class="row grid" id="products">
<?php
$sqli=sprintf("SELECT * FROM eventos WHERE YEAR(data) = 2027");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
if (mysqli_num_rows($resu)>0) {
while($regi=mysqli_fetch_array($resu)) {
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='../eventoindividual.php?id='.$regi_consulta['id'];
/* 2 brackets { */
?>
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<div class="product-overlay">
<div class="product-mask"></div>
<img src="<?php echo '../admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<br>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<div class="buttons buttons-simple">
<i class="fa fa-shopping-cart"></i>Comprar bilhetes
</div>
</div>
</div>
</div>
</article>
</div>
<?php
} // while loop
} // if condition
else {
?>
<p>Nada!</p>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
hope this helps. 👍

Edit option from Radio Buttons in PHP

I am VERY new to PHP and editing some code
Currently it has two radio buttons. Selecting either will bring up some options.
I am wanting to get rid of one option (pick up) and have the page just show the delivery option.
Any help would be ace, I have tried playing with the code but no luck!
<div class="top10 row">
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>'pickup',
'required'=>true
));
?>
<span><?php echo Driver::t("Pickup")?></span>
</div>
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>"delivery"
));
?>
<span><?php echo Driver::t("Delivery")?></span>
</div> <!--col-->
</div> <!--row-->
<div class="delivery-info top20">
<div class="row">
<div class="col-sm-6">
<?php echo CHtml::textField('contact_number','',array(
'class'=>"mobile_inputs",
'placeholder'=>Driver::t("Contact nunber"),
'maxlength'=>15
))?>
</div> <!--col-->
<div class="col-sm-6 ">
<?php
echo CHtml::textField('email_address','',array(
'placeholder'=>Driver::t("Email address")
))
?>
</div> <!--col-->
</div> <!--row-->
<div class="row top10">
<div class="col-sm-6 ">
<?php echo CHtml::textField('customer_name','',array(
'placeholder'=>Driver::t("Name"),
'required'=>true
))?>
</div>
<div class="col-sm-6 "><?php echo CHtml::textField('delivery_date','',array(
'placeholder'=>Driver::t("Delivery before"),
'required'=>true,
'class'=>"datetimepicker"
))?></div>
</div> <!--row-->
<div class="row top10">
<div class="col-sm-12 ">
<?php
$map_provider = Driver::getMapProvider();
?>
<?php if ($map_provider =="mapbox"):?>
<div id="mapbox_delivery_address" class="mapbox_geocoder_wrap"></div>
<?php elseif ( $map_provider=="google.maps"):?>
<?php
echo CHtml::textField('delivery_address','',array(
'class'=>'delivery_address geocomplete delivery_address_task',
'placeholder'=>Driver::t("Delivery Address"),
'required'=>true
));
?>
<?php endif;?>
Remove the lines of code below (or comment them out while you try it). Make a copy of the file before you make any changes in case you need to back out the attempt.
<div class="col-xs-6 ">
<?php echo CHtml::radioButton('trans_type',false,array(
'class'=>"trans_type",
'value'=>'pickup',
'required'=>true
));
?>
<span><?php echo Driver::t("Pickup")?></span>
</div>

Dynamic div close in php while loop

code i have written below is working fine but at the end of the looping the div is not closed its still opening a loop
<div class="carousel-inner">
<div class="item active">
<div class="row">
<?php
$recent_projects_sql="SELECT * from recent_projects where service_type='upholstery'";
$recent_projects_conn=mysql_query($recent_projects_sql) or die(mysql_error());
$i=0; $split=0;
while($projects=mysql_fetch_array($recent_projects_conn)) {
$i++;
?>
<div class="col-sm-3">
<div class="col-item" style="">
<div class="photo-shadow"></div>
<div class="photo">
<img src="admin/assets/images/uploads/projects/<?php echo $projects['attachment1']; ?>" alt="User one">
</div>
<div class="info">
<div class="name">
<?php echo $projects['service_name']; ?>
</div>
<div class="degination">
<?php echo $projects['sub_title']; ?>
</div>
<div class="buttons">
<a class="btn btn-theme ripple-effect" href="#">View More</a>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<?php
$split++;
if ($split % 4 == 0){
echo '</div></div><div class="item"><div class="row">';
}
}
?>
</div>
</div>
The Div has splited very well but in end of the loop div has not been closed. Thats only the problem please provide me the help to sort out the problem
When I inspect the element the last loop will show at the given result as follows:
<div class="col-sm-3">
<div class="col-item">
<div class="photo-shadow"></div>
<div class="photo">
<img src="admin/assets/images/uploads/projects/1557301934.jpg" alt="User one">
</div>
<div class="info">
<div class="name">UPHOLSTERY</div>
<div class="degination">UPHOLSTERY</div>
<div class="buttons">
<a class="btn btn-theme ripple-effect" href="#">View More</a>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div></div><div class="item"><div class="row">
I want to remove the two opening div's as dynamically. How can i set this to remove opened div's at then end of the looping
I just took a quick look and it looks like you are not closing the "carousel-inner" div
<div class="carousel-inner">
<div class="item active">
<div class="row">
<?php
$recent_projects_sql = "SELECT * from recent_projects where service_type='upholstery'";
$recent_projects_conn = mysql_query( $recent_projects_sql ) or die( mysql_error() );
$i = 0;
$split = 0;
while ( $projects = mysql_fetch_array( $recent_projects_conn ) ) {
$i ++;
?>
<div class="col-sm-3">
<div class="col-item" style="">
<div class="photo-shadow"></div>
<div class="photo">
<img src="admin/assets/images/uploads/projects/<?php echo $projects['attachment1']; ?>"
alt="User one">
</div>
<div class="info">
<div class="name">
<?php echo $projects['service_name']; ?>
</div>
<div class="degination">
<?php echo $projects['sub_title']; ?>
</div>
<div class="buttons">
<a class="btn btn-theme ripple-effect" href="#">View More</a>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<?php $split ++;
if ( $split % 4 == 0 ) {
echo '</div></div><div class="item"><div class="row">';
}
}
?>
</div>
</div>
Add a Boolean check for the execution of loop, such as $check = true;, add this within the loop.
after the loop add this
if($check){
echo " </div></div>";
}
That's because at the end of iteration (in case of mod 4 and even without it), you keep 2 divs opened
echo '</div></div><div class="item"><div class="row">';

Error when displaying webpage in columns

I am doing a dynamic site in php. I have divided the page into 2 columns. The first section shows a person's profile and the second section shows the article written by him/her. The problem is when i am adding more than one article. The second article is coming below the profile. I have tried using class clearfix. Its not working. Can someone please help me?
This is my page
<div class="container">
<?php
session_start();
$q = $_SESSION['id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("demo_db",$con);
$sql="select * from personal_details where id=$q";
$res=mysql_query($sql);
while($ar=mysql_fetch_array($res))
{
?>
<div>
<div class="row">
<div style="background-color:rgba(125, 178, 194, 0.43); margin-bottom:10px;" class="col-sm-8 col-md-8 col-lg-8">
<div class="row">
<div class="col-sm-4 col-md-4 col-lg-4">
<img style="margin:20px;" src="uploads/<?php echo $ar[17]; ?>">
</div>
<div class="col-sm-8 col-md-8 col-lg-8">
<h3><b>Dr. <?php echo $ar[1];?></b></h3>
<h5><?php echo $ar[8];?>, <?php echo $ar[12];?></h5>
<h5><?php echo $ar[2];?>, <?php echo $ar[7];?> years of experience</h5>
<p><?php echo $ar[16];?></p>
</div>
</div>
<div style="margin:20px;">
<h4><b>Services</b></h4>
<hr>
<ul>
<li>
<h5><?php echo $ar[18]; ?></h5>
</li>
</ul>
<h4><b>Specialisations</b></h4>
<hr>
<ul>
<li>
<h5><?php echo $ar[2]; ?></h5>
</li>
</ul>
<h4><b>Education</b></h4>
<hr>
<ul>
<li>
<h5><?php echo $ar[8]; ?> - <?php echo $ar[9]; ?> , <?php echo $ar[10]; ?> , <?php echo $ar[11];?></h5>
</li>
</ul>
<ul>
<li>
<h5><?php echo $ar[12]; ?> - <?php echo $ar[13]; ?> , <?php echo $ar[14]; ?> , <?php echo $ar[15];?></h5>
</li>
</ul>
</div>
</div>
<div class="col-sm-4 col-md-4 col-lg-4">
<h3>Articles by <?php echo $ar[1];?></h3><?php } ?>
<hr>
<?php
$sql1="select * from article_tb where id=$q";
$res1=mysql_query($sql1);
while($ar=mysql_fetch_array($res1))
{
$_SESSION['id'] = $q;
?>
<h4><b><?php echo $ar[1]; ?></b></h4>
<div class="row">
<div class="col-sm-7 col-lg-7 col-md-7">
<img src="uploads/<?php echo $ar[3]; ?>" width="170px" height="88">
</div>
<div class="col-sm-5 col-md-5 col-lg-5">
<form action="blog.php">
<input type="submit" class="btn btn-info" name="read" value="read" />
</form>
</div>
</div>
<hr>
</div>
<?php } ?>
</div>
</div>

How do i echo a chunk of html with php

Basically what I want to do is this...
If column (seperate_sitting_yes) in row ($rows1) in table = 'yes' echo this chunk of html. Else echo this other chunk of hmtl (I have used an echo statement "nothing" for ease.
if ($rows1['seperate_sitting_yes'] == "No";){
echo
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_monday_from']; echo $rows1['opening_monday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Tuesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_tuesday_from']; echo $rows1['opening_tuesday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Wednesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_wednesday_from']; echo $rows1['opening_wednesday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Thursday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_thursday_from']; echo $rows1['opening_thursday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Friday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_friday_from']; echo $rows1['opening_friday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Saturday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_saturday_from']; echo $rows1['opening_saturday_to'];/p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Sunday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_sunday_from']; echo $rows1['opening_monday_to'];/p></div>;
}
else {echo "nothing";}
But i'm not sure how to address this correctly. Can anyone shed any light on the matter. Please and thank you.
Here is your answer bellow. Basically you need to echo the entire html as a string via php. So you have to put the entire code in a '' quotes and plus you are attaching php variables in it so you can concatinate it via '.'
if ($rows1['seperate_sitting_yes'] == "No")
{
echo '<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_monday_from'].''.$rows1['opening_monday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_tuesday_from'].''.$rows1['opening_tuesday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_wednesday_from'].''.$rows1['opening_wednesday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_thursday_from'].''.$rows1['opening_thursday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_friday_from'].''.$rows1['opening_firday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_saturday_from'].''.$rows1['opening_saturday_to'];'</p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p>'.$rows1['opening_sunday_from'].''.$rows1['opening_sunday_to'];'</p></div>
</div>';
}
else {echo "nothing";}
Try letting HTML do most of the heavy lifting and insert PHP echos where needed.
<?php if ($rows1['seperate_sitting_yes'] == "No";){ ?> //Close off PHP here
<!-- This is all HTML here -->
<!-- Below is HTML code injected with PHP variable -->
<div><?php echo $variableThatNeedsToBeInserted ?></div>
<?php }else {echo "nothing";} ?> //Closing PHP tag for end } bracket, and else case.
Hope this gives you an idea!
In your first line there is an ";" that doesn't need to be there...
Instead of
if ($rows1['seperate_sitting_yes'] == "No";){
Try
if ($rows1['seperate_sitting_yes'] == "No"){
The ";" denotes the end of a line of code in PHP. When you are trying to evaluate something in an if statement, that is not the end of the line. So remove it, and be sure that $rows1['seperate_sitting_yes'] is producing expected results.
And as said in other comments, seperate out the PHP and the HTML see the modified code below
<?php
$rows1['seperate_sitting_yes'] = "No";
if ($rows1['seperate_sitting_yes'] == "No"){
?>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Monday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_monday_from']; echo $rows1['opening_monday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Tuesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_tuesday_from']; echo $rows1['opening_tuesday_to'];?><p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Wednesday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_wednesday_from']; echo $rows1['opening_wednesday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Thursday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_thursday_from']; echo $rows1['opening_thursday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Friday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_friday_from']; echo $rows1['opening_friday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Saturday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_saturday_from']; echo $rows1['opening_saturday_to'];?></p></div>
</div>
<div id="complete_info_wrapper">
<div id="complete_info_title"><p>Sunday</p></div>
<div id="complete_info_details"><p><? echo $rows1['opening_sunday_from']; echo $rows1['opening_monday_to'];?></p></div>;
<?php }
else {echo "nothing";}
?>

Categories