<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'
'<a target="_blank" class="mosaic-overlay">'
'<div class="details">'
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'
'<p class="font_us1">technische Umsetzung</p>'
'</div>'
'</a>'
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'
'</div>';
}
mysql_close();
?>
So I wanted to output the usernames of my database with some javascript effect, but it doesn't show. How do I have to echo this out?
echo 'foo
bar
baz';
No need to close the quote on each newline. Better though, simply go out of PHP mode:
<?php while ($row = mysql_fetch_array($result)) { ?>
<div>
...
<?php echo $row['user_name']; ?>
...
</div>
<?php } ?>
Even better yet for readability (IMO):
<?php while ($row = mysql_fetch_array($result)) : ?>
...
<?php endwhile; ?>
You should use pdo or mysqli.
You did not concat your string.
<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'.
'<a target="_blank" class="mosaic-overlay">'.
'<div class="details">'.
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'.
'<p class="font_us1">technische Umsetzung</p>'.
'</div>'.
'</a>'.
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'.
'</div>';
}
mysql_close();
?>
Related
Here is what I’m trying to achieve:
As you can see here, you can choose shoe size based on the region (EU, UK, US).
After lot of research, I found the solution from #Hambos22 there to be exactly the one I am trying to do. But impossible to put in place neither #Hambos22 or #mikejolley solution.
I think that I am missing some knowledge where to put these parts of code as I am trying to put everything inside 'function.php' but it's only displaying me
the switcher.
I’ve added 2 more custom fields in the Attribute size (UK, US).
My website link
My attribute slug: size
Variables added with ACF: uk-size, us-size
My attribute default value: EU
Code I would like to put in place (but don't know the location):
Here is a php snippet
$us_size = get_field('us_size', $term);
$uk_size = get_field('uk_size', $term);
$cm_size = get_field('cm_size', $term);
printf( '<div class="sizeRadio">
<input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s>
<label for="%3$s">
<span class="label_show" data-region="eu">%5$s</span>
<span data-region="us">%6$s</span>
<span data-region="uk">%7$s</span>
<span data-region="cm">%8$s</span>
</label>
</div>', $input_name, $esc_value, $id, $checked, $filtered_label, $us_size, $uk_size, $cm_size );
}
Here is a JS snippet
$('[data-chooseregion]').on('click', function(e) {
$(this).addClass('active--sizeSelect').siblings().removeClass('active--sizeSelect');
var $active = $('[data-region=' + $(this).data('chooseregion') + ']').addClass('label_show');
$('[data-region]').not($active).removeClass('label_show');
e.preventDefault();
});
Here is the markup for the switcher
<?php
echo '<a class="sizeSelect active--sizeSelect" data-chooseregion="eu" href="#">EU</a>';
echo '<a class="sizeSelect" data-chooseregion="us" href="#" >US</a>';
echo '<a class="sizeSelect" data-chooseregion="uk" href="#" >UK</a>';
echo '<a class="sizeSelect" data-chooseregion="cm" href="#" >CM</a>';
?>
Anyone could help me to sort it out?
By the way I would also love to apply that to my shop page as a filter in the left panel!
If any more information needed don't hesitate I would reply in less than 12 hours.
Cheers :)
For the single product page:
I finally sort it out and instead of creating a "dynamic" data's change, I chose to create a table from the 2 fields under my pa_size as follow:
if(!empty($terms)){
echo '<button class="accordion">Size Chart <i class="fa-sitemap"></i></button>
<div class="panel">
<table class="sf-table standard_bordered"><tbody><tr><td><strong>EU</strong></td>';
foreach ($terms as $term) {
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
echo '<td>'. $eu_s .'</td>';
}
echo '</tr><tr><td><strong>UK</strong></td>';
foreach ($terms as $term) {
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
echo '<td>'. $uk_s .'</td>';
}
echo '</tr><tr><td><strong>US</strong></td>';
foreach ($terms as $term) {
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
echo '<td>'. $us_s .'</td>';
}
echo '</tr></tbody></table></div>';
}
For the Filter on WC Shop page:
I've created a new "widget" going to my filter panel and also installed the handy plugin PHP Text Widget which Extends the default WordPress text widget making it able to execute PHP code.
Then put the following code in it:
<div class="filter-size">
<input type="button" name="filterEU" value="EU" onclick="sizesEU()" />
<input type="button" name="filterUK" value="UK" onclick="sizesUK()" />
<input type="button" name="filterUS" value="US" onclick="sizesUS()" />
</div>
<?php
global $product;
$terms = get_terms( 'pa_size', $args );
$page_url = esc_url( home_url( '/' ) );?>
<div id="filterEU">
<ul class="jcaa_attr_select jcaa_attr_variable_select jcaa_size_medium">
<?php foreach( $terms as $term ):
$slug = $term->slug;
$num = (float)$slug;
if ($num > 20){
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
$term_link = $page_url . 'product-tag/cf-size-eu-' . $eu_s . '-uk-' . $uk_s . '-us-' . $us_s; ?>
<li><a class="jcaa_attr_option jcaa_obj_text" href="<?php echo esc_url($term_link ); ?>"><?php echo $eu_s ?></a>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<div id="filterUK" style="display:none">
<ul class="jcaa_attr_select jcaa_attr_variable_select jcaa_size_medium">
<?php foreach( $terms as $term ):
$slug = $term->slug;
$num = (float)$slug;
if ($num > 20){
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
$term_link = $page_url . 'product-tag/cf-size-eu-' . $eu_s . '-uk-' . $uk_s . '-us-' . $us_s; ?>
<li><a class="jcaa_attr_option jcaa_obj_text" href="<?php echo esc_url($term_link ); ?>"><?php echo $uk_s ?></a></li>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<div id="filterUS" style="display:none">
<ul class="jcaa_attr_select jcaa_attr_variable_select jcaa_size_medium">
<?php foreach( $terms as $term ):
$slug = $term->slug;
$num = (float)$slug;
if ($num > 20){
$eu_s = get_field('eu-size', 'pa_size_' . $term->term_id);
$uk_s = get_field('uk-size', 'pa_size_' . $term->term_id);
$us_s = get_field('us-size', 'pa_size_' . $term->term_id);
$term_link = $page_url . 'product-tag/cf-size-eu-' . $eu_s . '-uk-' . $uk_s . '-us-' . $us_s; ?>
<li><a class="jcaa_attr_option jcaa_obj_text" href="<?php echo esc_url($term_link ); ?>"><?php echo $us_s ?></a></li>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<script>
function sizesEU() {
document.getElementById('filterEU').style.display = "block";
document.getElementById('filterUK').style.display = "none";
document.getElementById('filterUS').style.display = "none";
}
function sizesUK() {
document.getElementById('filterEU').style.display = "none";
document.getElementById('filterUK').style.display = "block";
document.getElementById('filterUS').style.display = "none";
}
function sizesUS() {
document.getElementById('filterEU').style.display = "none";
document.getElementById('filterUK').style.display = "none";
document.getElementById('filterUS').style.display = "block";
}
</script>
Don't hesitate if any question about it.
Cheers
how can i make a simple accordian toggle like in https://www.wireshark.org/download.html that works like getting data from a database i have,which has questions and answers? that works simply for all the rows.
this is the current code i have and want to modify.
<?php
$connection = ($GLOBALS["___mysqli_ston"] = mysqli_connect('localhost', 'root', ''));
((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . 'db'));
$query = "SELECT * FROM AS_Questions";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query);
if (!$result) {
printf("Errormessage: %s\n", $mysqli->error);
}
echo "<table>";
while($row = mysqli_fetch_array($result)){
echo "<div class='span3 tiny'>
<div class='pricing-table-header-tiny'>
<h2>" . $row['Question'] . "</h2>
</div>
<a href='##' id='s'>Show answer</a>
<div class='dq'>
<div class='pricing-table-features'>
<p>" . $row['Answer'] . "</p>
</div>
<div class='Dass'>
<p id='Dassp'>Answered by:" . $row['Doctor'] . "<p>
</div>
</div>
</div>"; //$row['index'] index here is a field name
}
echo "</table>"; //Close the table in HTML
((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
?>
I want to pass this value doctoridclickedRightNow into t_appointmentdetails table. I have made few changes to previous code using AJAX and JS as suggested on How to Pass variable from JavaScript to PHP Page using XMLHTTP . Appointment details are getting inserted into DB and I also want the doctorid of the corresponding doctor to be saved. So with the below changes I am able see the correct values being displayed when I use inspect element in mozilla. Kindly suggest me how to pass this to DB. Thanks in advance.
$sql = "SELECT doctorid, FIRST_NAME,LAST_NAME, Address, Qualification, Specialization, Consultation_Fee, Experience,image_path
from t_doctorprofile";
$results = mysqli_query($db,$sql)
or die('MySQL Error');
echo '<h3 style="color:#674172;margin- left:120px;float:center;display:inline-block"><strong>Available Dentists</strong></h3>';
while($result = mysqli_fetch_assoc($results)){
echo '<div class= "fetch" style="margin-left:120px">';
echo "<img src = 'uploads/".$result['image_path']."' width='150' height='150'>";
echo "<div id='info'>";
echo "<p><strong>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</strong></p></div>";
echo "<p>".$result['Qualification']."</p>";
echo "<p>".$result['Specialization']."</p>";
echo "<p>".$result['Address']."</p>";
echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."</p>";
echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"." </p>";
echo "<button class='btn btn-success btn-lg' id='$result[doctorid]' data-toggle='modal' data-target='#myModal' onclick='AssignDoctorIdClicked(id)'>
Appointment</button>";
echo "<script>var doctoridclickedRightNow;</script>";
echo "</div>";
echo '<form action="appointment_insert.php" method="POST">';
echo "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content' style='background-color:#F1A9A0'>";
echo "<div class='modal-header'>";
echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>";
echo "<h4 class='modal-title' id='myModalLabel' style='text-align:center; color:#fff'>
<strong>Book Appointment</strong></h4><br>";
echo "</div><br><br>";
echo "<div class='modal-body'>";
script for AssignDoctorIdClicked function:
<script>
function AssignDoctorIdClicked(id) {
console.log(id);
var doctoridclickedRightNow = id;
console.log(doctoridclickedRightNow);
</script>
appointment_insert.php page
if (isset($_POST["submit"])) {
$login_user = $_SESSION['username'];
$datetime = $_POST['datetime'];
$info = $_POST['info'];
$recieved_1 = $_GET['FIRST_NAME'];
$query = mysqli_query($db, "INSERT INTO t_appointmentdetails (patient_name,datetime,info) VALUES ('$login_user','$datetime','$info');");
$insertedDataBoolean = true;
if($insertedDataBoolean){
echo "Name: " . $recieved_1 . " booked successfully.";
}
else{
echo "Data-insertion error.";
}
}
Im trying to create a shopping cart style website. I'm able to display the products through setting the products as a class and passing that through to my shopping cart page. However, I need to save the list of products into a session so I can add and or clear each item added to the cart.
Products.php
<?php
require_once 'class_product.php';
$product = new product();
$product_id =(int)$_GET['product_id']; //get id from home page
$username = "";
$password = "";
$hostname = "";//blanked this out for public use
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("poti",$dbhandle)
or die("Could not select examples");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM products where product_id=$product_id");
echo '<form name="form1" method="post" action="cart.php" target="bottom_right">';
echo '<table class="Grocery-table">';
while($row = mysql_fetch_array($result))
{
$product->setProductId($row['product_id']);
$product->setProductName($row['product_name']);
$product->setStock($row['in_stock']);
$product->setUnitPrice($row['unit_price']);
$product->setUnitQuantity($row['unit_quantity']);
}
$_SESSION['product'] = serialize($product);
echo "<tr><td><b>Product ID</b></td>";
echo "<td>";
echo $product->getProductId();
echo "</td></tr>";
echo "<tr><td><b>Product Name</b></td>";
echo "<td>";
echo $product->getProductName();
echo "</td></tr>";
echo "<tr><td><b>Unit Price</b></td>";
echo "<td>";
echo $product->getUnitPrice();
echo "</td></tr>";
echo "<tr><td><b>Unit Quantity</b></td>";
echo "<td>";
echo $product->getUnitQuantity();
echo "</td></tr>";
echo "<tr><td><b>In Stock</b></td>";
echo "<td>";
echo $product->getStock();
echo "</td></tr>";
echo '<tr><td><b>Add</b></td><td><Input type="number" min="0" id="add_value" name="cart"></input>
<Input type="hidden" id="stock_value" name="stock_value" value ='.trim($product->getStock()).'></input></td></tr>';
echo '<tr><td></td><td><input type="submit" value="Submit" onclick="return numCheck()"></td></tr>';
echo "</table>";
echo "</form>";
?>
cart.php
<?php
session_start();
?>
<html>
<style type="text/css">
</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Grocery Store</title>
</head>
<body>
<h2>Cart</h2>
<?php
require_once 'class_product.php';
$product = unserialize($_SESSION['product']);
//this allows me to see the information when i click submit
echo $product->getProductName();
echo $product->getProductId();
echo $product->getStock();
echo $product->getUnitPrice();
echo $_POST['cart'];
?>
</body>
</html>
How do i place the following $product->getProductName() etc into a Session that enables me to display all the products i've added to my cart.
Try this,
session_start();
$_SESSION['ProductName'] = $product->getProductName();
$_SESSION['ProductId'] = $product->getProductId();
$_SESSION['Stock'] = $product->getStock();
$_SESSION['UnitPrice'] = $product->getUnitPrice();
For multiple products, you may have to use an array of session.
<?php
session_start();
if(!isSet($_SESSION['cart_items']))
{
$_SESSION['cart_items'] = array();
}
$items =$product->getProductName()."|".$product->getProductId()."|".$product-
>getStock()."|".$product->getUnitPrice();
array_push($_SESSION['cart_items'],$items);
echo $_SESSION['cart_items'][0]; //First Product
echo "<br>";
echo $_SESSION['cart_items'][1]; //Second Product
?>
I have a problem. I need to get the value from a select tag then use it in php for my sql. Here is my code
<div class="form-group">
<label> ROOMS </label>
<?php
echo "<select value= 'TRoom1' id ='TRoom1' class='form control'>";
echo "<option>Select Room Type</option>";
while ($row1 = mysql_fetch_array($result2))
{
echo "<option>" . $row1['Room_type'] . "</option>";
}
echo "</select>";
?>
this is for the sql command
<div class="modal-body">
<div class="container">
<?php
$selectedValue = $_POST['TRoom1'];
$sql = "SELECT RoomNumber FROM rooms Where Room_type = '$selectedValue' ";
$result = mysql_query($sql);
echo "<select value= 'RoomNo' id ='RoomID' class='form-control'>";
echo "<option>Select Room Number</option>";
while ($row = mysql_fetch_array($result))
{
echo "<option>" . $row['RoomNumber'] . "</option>";
}
echo "</select>";
?>
TIA! :))
THis is the code ofor room type with its corresponding room number
<div class="form-group">
<label for="exampleInputEmail1"> ROOMS </label>
<?php
echo "<select value= 'TRoom1' name ='TRoom1' id ='TRoom1' class='form-control'>";
echo "<option>Select Room Type</option>";
while ($row1 = mysql_fetch_array($result2))
{
echo "<option>" . $row1['Room_type'] . "</option>";
}
echo "</select>";
?>
</div>
<div class="form-group">
<?php
$select_value=$_POST['selectedValue'];
$sql = "SELECT RoomNumber FROM rooms Where Room_type = '$select_value' ";
$result = mysql_query($sql);
echo "<select value= 'RoomNo' id ='RoomID' class='form-control'>";
echo "<option>Select Room Number</option>";
while ($row = mysql_fetch_array($result))
{
echo "<option>" . $row['RoomNumber'] . "</option>";
}
echo "</select>";
?>
</div>
you need to use name attribute for your select tag if u want to fetch the value in the php part and in the option u have to pass the value attibute.that value u will get in the php part.
<html>
<head></head>
<body>
<form action="a.php" method="post">
<select name="selectname" id="someid" >
<?php
while ($row1 = mysql_fetch_array($result2))
{
?>
<option value="<?php echo $varible ?>"> <?php echo $row1['Room_type']; ?></option>
<?php } ?>
</select>
<input type="submit" value="submit">
</form>
</body>
</html>
for php part:u can fetch value like this:
filename=a.php
<?php
$select_value=$_REQUEST['selectname'];
$sql1 = "SELECT RoomNumber FROM rooms Where Room_type = '$select_Value' ";
$sql=mysql_result(mysql_query($sql1),0);
?>
Please google your doubts before posting here. There are plenty of example available. mysql_query is deprecated use mysqli_ function
<div class="form-group">
<label> ROOMS </label>
<?php
echo "<select id ='TRoom1' name ='TRoom1' class='form control'>";
echo "<option>Select Room Type</option>";
while ($row1 = mysql_fetch_array($result2))
{
echo "<option value=".$row1['Room_type'].">" . $row1['Room_type'] . "</option>";
}
echo "</select>";
?>
If you are submitting your form as post you would get values as
$sql = "SELECT Room_type, Rate, RoomNumber FROM rooms Where Room_type ='".$_POST['TRoom1']."' ";
Try like
var Sel_val = document.getElementById('TRoom1').value;
Sel_val will be the selected value of that Dropdown.Better you use ajax in your case.If it is on the same page then you use Form submit method.
For the ajax first you need the target url and the value which you want to send..So try like
$.ajax({
url : Url of the page at which the sql command will be there,
type : 'POST',
data : { Sel_val : Sel_val }
});
Then at your target file get the Sel_val via POST method.
I think you used the self action and try this below code
if($_POST){
$selectedValue = $_POST['TRoom1'];
$sql = "SELECT RoomNumber FROM rooms Where Room_type = '$selectedValue' ";
$result = mysql_query($sql);
echo "<select value= 'RoomNo' id ='RoomID' class='form-control'>";
echo "<option>Select Room Number</option>";
while ($row = mysql_fetch_array($result))
{
echo "<option>" . $row['RoomNumber'] . "</option>";
}
echo "</select>";
}