2

This is the code I am using to display certain data from mysql database in a template like panel. I want to know how can i display a button with href using html5 for every template.

while($result = mysqli_fetch_assoc($results)){
 echo '<div class="fetch">';
 echo "<p>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</p>";
 echo "<p>".$result['QUALIFICATION']."</p>";
 echo "<p>".$result['Specialization']."</p>";
 echo "<p>".$result['Adress1']." ".$result['Adress2']."</p>";
 echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."  
 </p>";
 echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"."</p>";

 echo '</div>';
6
  • 1
    <button> doesn't do anything without either being in a <form> or having a script attached. If you're trying to make a button that goes to a page ('with an href'), then just add another line that starts with echo and has an <a> tag in it. You can use CSS to make the <a> look just like a button. Commented Dec 23, 2015 at 7:03
  • Does this work? <a href="abc.php" class="slider-btn">Book Appointment</a> Commented Dec 23, 2015 at 7:05
  • I don't see why not. Just make it look like the other lines up there where it is being echoed and wrapped in quotes. Should be fine. Commented Dec 23, 2015 at 7:06
  • <a href="abc.php" class="slider-btn">Book Appointment</a> does not work..... echo "<a href=login.php class=btn>Book Appointment</a>"; this will work... Commented Dec 23, 2015 at 7:14
  • You need quotes around you attribute values (login.php and btn). They can be single quotes so they don't get mixed up with the double quotes around the whole string. Commented Dec 23, 2015 at 7:15

2 Answers 2

1

You can try it like this:

.btn {
            background: #3498db;
            background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
            background-image: -moz-linear-gradient(top, #3498db, #2980b9);
            background-image: -ms-linear-gradient(top, #3498db, #2980b9);
            background-image: -o-linear-gradient(top, #3498db, #2980b9);
            background-image: linear-gradient(to bottom, #3498db, #2980b9);
            -webkit-border-radius: 28;
            -moz-border-radius: 28;
            border-radius: 28px;
            font-family: Arial;
            color: #ffffff;
            font-size: 20px;
            padding: 10px 20px 10px 20px;
            text-decoration: none;
  }
<a href='your-link' class='btn'>Button</a>

Sign up to request clarification or add additional context in comments.

Comments

1

HTML

The plain HTML way is to put it in a <form> wherein you specify the desired target URL in the action attribute.

<form action="http://google.com">
    <input type="submit" value="Go to Google">
</form>

If necessary, set CSS display: inline; on the form to keep it in the flow with the surrounding text.

CSS

If CSS is allowed, simply use an <a> which you style to look like a button using among others the [appearance][1] property ([only Internet Explorer support is currently (July 2015) still poor][2]).

a.button {
  -webkit-appearance: button;
  -moz-appearance: button;
  appearance: button;

  text-decoration: none;
  color: initial;
}
<a href="http://google.com" class="button">Go to Google</a>

Or pick one of those many CSS libraries like [Bootstrap][3].

JavaScript

If JavaScript is allowed, set the window.location.href.

<input type="button" onclick="location.href='http://google.com';" value="Go to Google" />

2 Comments

Thank you for your answer. Well I knew how to create button in a form but not between php tags which I have answered in the comments.
you wamnt php tags just put the php tag in values of button it will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.