I have the following code that is supposed to be a list of "facilities" and I made a div acting as a popUp that contain information that should change depending on the Lab I click info, I already made the popUp appear and dissapear playing with adding a hide and show class to it using Js.
But I don´t really know how should I write that each li element has to retrive information from a database I made in wamp for practice purposes, should I use a label? Or perhaps create a table instead of a list?
In short I need that when I click Lab 1 the popUp says Name: Lab1, if the clicks Lab 2, then Lab2 and so on. The code I was going to use in PHP is below as well.
HTML
<div class="box">
<p>Lab #1</p>
<p class="info">Info</p>
<p class="info">Reservar</p>
</div>
<div class="box">
<p>Lab #2</p>
<p class="info">Info</p>
<p class="info">Reservar</p>
</div>
<div class="box">
<p>Lab #3</p>
<p class="info">Info</p>
<p class="info">Reservar</p>
</div>
<div class="popUp1 hide" id="popUpCorrecto1">
<div class="estiloPopUp">
<span>Información de laboratorio</span>
<span value="Cerrar" id="btnCerrar">x</span>
</div>
<ul>
<li>Nombre: Lab #1</li>
<li>Carrera: Desarrollo</li>
<li>Capacidad: 20</li>
<li>Ubicación:Abajo</li>
<li><a href='horarios.html'>Ver horarios</a></li>
</ul>
<input type = "button" value = "Eliminar" id = "btnEliminar" onclick="window.location='labEliminado.html';" />
<input type = "button" value = "Modificar" id = "btnModificar" onclick="window.location='modificarLab.html';" />
</div>
PHP
function displayLab(){
$query = "SELECT bk.idLab , bk.capacidad, bk.carrera, bk.ubicacion FROM labs";
$result = do_query($query);
return $result;
}
function displayBooks(){
$books = getBooks();
while($row = mysql_fetch_assoc($books)){
echo '<tr>' .
'<td>' . $row['idLab'] . '</td>' .
'<td>' . $row['carrera'] . '</td>' .
'<td>' . $row['capacidad'] . '</td>' .
'<td>' . $row['ubicación'] . '</td>' .
'</tr>';
}
}
Gonna add the box CSS just in case:
.box {
color: #ecf0f1;
background-color: #34495e;
display: inline-block;
padding: 2px;
width: 75px;
border: 2px solid black;
margin: 3px;
}
.box:hover{
border:2px solid white;
}
JS for PopUp
var elementoVerInfo = document.getElementById('lnkInfo'),
elementoBotonCerrar = document.getElementById('btnCerrar');
elementoVerInfo.addEventListener('click', function () {
displayPopUp('popUpCorrecto1');
});
elementoBotonCerrar.addEventListener('click', function () {
hidePopUp('popUpCorrecto1');
});
function displayPopUp(pIdDivToShow){
var fElementDivToShow = document.getElementById(pIdDivToShow),
newClass ='';
newClass = fElementDivToShow.className.replace('hide','');
fElementDivToShow.className = newClass + ' show';
}
function hidePopUp(pIdDivToShow){
var fElementDivToShow = document.getElementById(pIdDivToShow),
newClass ='';
newClass = fElementDivToShow.className.replace('show','');
fElementDivToShow.className = newClass + ' hide';
}
That is if I decide to use a table...and if the code runs >.>
Anyway thanks a lot in advance
Best Wishes
If anyone else wants to do something similar I came with a solution:
function displayLabs(){
$labs = getLabs();
while($row = mysql_fetch_assoc($labs)){
echo '<ul>' .
'<li>"Nombre: "'. $row['idlab'] . '</li>' .
'<li>"Capacidad: "'. $row['capacidad'] . '</li' .
'<li>"Carrera: "'. $row['carrera'] . '</li>' .
'<li>"Ubicación: "'. $row['ubicacion'] . '</li>' .
'</ul>';
}
}
Related
I was working on my term project i fetched data from api and print with php on my html page but after adding my php codes, my main headers are looks broken in the picture below.
So i tried many times to fix this problem using some other divs, make some changes on my css file etc. but still the same result.
here is my code:
<div class="topRated">
<h1>Top Rated Movies</h1>
<?php
//echo ' <h1>Top Rated Movies</h1>';
$id_movie = urlencode("id");
$data = file_get_contents("https://api.themoviedb.org/3/movie/top_rated?api_key=59419be18ecb300104521be9c3837f01&language=en-US&page=1");
$data = json_decode($data,true);
foreach($data['results'] as $result){
echo '<div class="column">
<div class="row">
<img src="'."http://image.tmdb.org/t/p/w500".''. $result['poster_path'] . '" width="140" height="180"><h4><span style="color:#000000;text-align:center;">' . $result['original_title']. "</h4><h5><span style=color:#000000;text-align:center;>"." Rate : " . $result['vote_average'] . " | Vote : " . $result['vote_count'] ."</h5> </h6><span style=color:#000000;text-align:center;>"."Popularity : " . round($result['popularity']) . "</h6>
</div>
</div>";
}
?>
</div>
<div class="popular">
<h1>Popular Movies</h1>
<?php
//echo '<h1>Popular Movies</h1>';
$id_movie = urlencode("id");
$data = file_get_contents("https://api.themoviedb.org/3/movie/popular?api_key=59419be18ecb300104521be9c3837f01&language=en-US&page=1");
$data = json_decode($data,true);
foreach($data['results'] as $result){
echo '<div class="column">
<div class="row">
<img src="'."http://image.tmdb.org/t/p/w500".''. $result['poster_path'] . '" width="140" height="180"><h4><span style="color:#000000;text-align:center;">' . $result['original_title']. "</h4><h5><span style=color:#000000;text-align:center;>"." Rate : " . $result['vote_average'] . " | Vote : " . $result['vote_count'] ."</h5> </h6><span style=color:#000000;text-align:center;>"."Popularity : " . round($result['popularity']) . "</h6>
</div>
</div>";
}
?>
</div>
<div class="upcoming">
<h1>Upcoming Movies</h1>
<?php
//echo '<h1>Upcoming Movies</h1>';
$id_movie = urlencode("id");
$data = file_get_contents("https://api.themoviedb.org/3/movie/upcoming?api_key=59419be18ecb300104521be9c3837f01&language=en-US&page=1");
$data = json_decode($data,true);
foreach($data['results'] as $result){
echo '<div class="column">
<div class="row">
<img src="'."http://image.tmdb.org/t/p/w500".''. $result['poster_path'] . '" width="140" height="180"><h4><span style="color:#000000;text-align:center;">' . $result['original_title']. "</h4><h5><span style=color:#000000;text-align:center;>"." Rate : " . $result['vote_average'] . " | Vote : " . $result['vote_count'] ."</h5> </h6><span style=color:#000000;text-align:center;>"."Popularity : " . round($result['popularity']) . "</h6>
</div>
</div>";
}
?>
</div>
Also my css codes are in below:
.column {
height: 340px;
margin-top: 70px;
margin-left: 45px;
float: left;
width: 13%;
padding: 0px;
font-family: serif;
font-style: normal;
text-align: center;
display: inline;}
.row::after {
margin-left: 40px;
font-family: serif;
font-style: normal;
text-align: center;}
I didn't write any css codes for the div outside of the php codes. But i can't fix this problem.
How can i fix this?
I have a small question: I created a dynamic search bar until now it's ok. But the problem I have is that when I type the beginning of a letter or a number, I don't have a display limit it takes all the page someone already have a solution?
Thanks a lot
Here is the jQuery code:
$(document).ready(function () {
$('#search-stock').keyup(function (){
$('#result-search').html('');
var stock = $(this).val();
if (stock != "") {
$.ajax({
type: 'GET',
url: '../ajax/stock_search.php',
data: 'stocks=' + encodeURIComponent(stock),
success: function (data) {
if (data != "")
{
$('#result-search').append(data);
} else {
document.getElementById('result-search').innerHTML = "" + "<div style='font-size: 20px; text-align: center; margin-top: 10px'> Aucun élement trouver</div>"
}
}
});
}
});
});
Here is the php
<?php
session_start();
include('../include/bdd.php');
if(isset($_GET['stocks'])){
$stock_aema = (string) trim($_GET['stocks']);
$req = $bdd->prepare("SELECT * FROM stock_aema WHERE model LIKE :model LIMIT 10");
$req2 = $bdd->prepare("SELECT * FROM stock_aema WHERE id LIKE :id LIMIT 10");
$req3 = $bdd->prepare("SELECT * FROM stock_aema WHERE aema LIKE :aema LIMIT 10");
$req->execute(array('model' => "%$stock_aema%"));
$req = $req->fetchAll();
foreach ($req as $r){
?>
<div style="margin-top: 20px ; border-bottom: 2px solid #ccc">
<?= $r['id'] . " " . $r['model']. " " . $r['aema']?>
</div>
<?php
}
$req2->execute(array('id' => "%$stock_aema%"));
$req2 = $req2->fetchAll();
foreach ($req2 as $s){
?>
<div style="margin-top: 20px ; border-bottom: 2px solid #ccc">
<?= $s['id'] . " " . $s['model']. " " . $s['aema']?>
</div>
<?php
}
$req3->execute(array('aema' => strval("%$stock_aema%")));
$req3 = $req3->fetchAll();
foreach ($req3 as $x){
?>
<div style="margin-top: 20px ; border-bottom: 2px solid #ccc">
<?= $x['id'] . " " . $x['model']. " " . $x['aema']?>
</div>
<?php
}
}
?>
A couple of months ago, I asked a similar question like this and the answer that where given worked for me. I now have another change I would like to add to my page. I would like that each post I create has its own unique div. My page currently looks like this:
the previous question helped me break the div each 3 post, so what I tried was within the if statement that creates a new dive each 3 div was to add another if which would break each 1 div so that each post has its own div and it still breaks to a new div section each 3, maybe I just complicated everything with my description, but I want to get something like:
Here is my code
CSS:
.column {
display: inline-flex;
border: 5px black;
border-style: solid;
padding: 10px;
background: #ffa500;
}
PHP:
else {
$break = 0;
$nRows = $connection->prepare("SELECT post_id, post_title,
post_author, post_file, post_time
FROM posts
ORDER BY post_id DESC");
$nRows->execute();
if($nRows->rowCount() > 0) {
while ($row = $nRows->fetch()) {
$post_title = str_replace('_', ' ', $row['post_title']);
$post_author = $ed->encrypt_decrypt('decrypt',$row['post_author']);
$post_file = $row['post_file'];
$post_date = $row['post_time'];
// Create a new div each 3 columns
if ($break % 3 === 0) {
echo '<br><div class="column"><br>';
}
$break++;
?>
<!-- Blog Content BEGIN Display-->
<div class="box"><?php
// Display the content
$file_parts = pathinfo($post_file);
if(isset($file_parts['extension'])) {
switch ($file_parts['extension']) {
case "jpg":
if(!empty($post_file)) { ?>
<img src="post/postFiles/<?php echo $post_file;?>"><?php
}
break;
case "mp4":?>
<div class="thumbnail">
<video preload="auto" loop muted>
<source src="post/postFiles/<?php echo $post_file;?>">
</video>
</div>
<!-- Preview video on hover -->
<script>
$(document).ready(function () {
$(".thumbnail").hover(function () {
$(this).children("video")[0].play();
}, function () {
var el = $(this).children("video")[0];
el.pause();
el.currentTime = 0;
});
});
</script><?php
break;
case "": // Handle file extension for files ending in '.'
case NULL: // Handle no file extension
break;
}
}
// Title URL Variable
$urlFetchPostId = '<h2><a href="post/postFetch/fetchByTitle/fetchByPT.php?post_id=';
$urlFetchPostTitle = '&post_title=';
$urlFetchPostAuthor = '&post_author=';
echo $urlFetchPostId . $row['post_id'] . $urlFetchPostAuthor. $row['post_author']. $urlFetchPostTitle . $row['post_title'] . '"' . 'class="link-post-title" style="font-family: Arial">' . " ". $post_title . '</a></h2>';
// Author/User URL Variable
$urlFetchPostUser = '<a href="post/postFetch/fetchByAuthor/fetchByPA.php?post_author=';
echo $urlFetchPostUser . $row['post_author'] . '"' . 'class="link-post-author" style="font-family: Arial">' . " ". strtoupper($post_author) . '</a>';
// Posted Date
echo '<br><p style="font-family: Arial">Posted on ' . $post_date . '</p>';
?>
</div><?php
if ($break % 3 === 0) {
echo '<br></div><br>';
}?>
<!-- Blog Content END Display --><?php
}
} else { ?>
<p style="color: darkgoldenrod" class="mssgAlign"><u>NO RECORDS</u></p><?php
}
$nRows = null;
}
Any help, tip or improvement suggestion is welcomed
You want to use margins. Margins specify a buffer around the outside of your container. As opposed to padding, which specifies buffer inside the container. Add this to your css
.column {
display: inline-flex;
border: 5px black;
border-style: solid;
padding: 10px;
background: #ffa500;
margin-left: 20px;
margin-right: 20px;
}
I have a php to echo three variable fields :
<li>
<mark> <?php while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
echo $toprow2['overallRank'] ." ".$toprow2['EmployeeName'] ." ".$toprow2['Total_points_Rewarded']."<br/>";} ?>
</mark>
</li>
Among these three variables of the list,I want to align the first field "overallRank " to left ,"EmployeeName " to centre and "Total_points_Rewarded" to extreme right.
Below is the code I tried for the first field:
<li>
<mark> <?php while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
echo "<div style = "text-align=left" ."$toprow2['overallRank'] "</div>"." ".$toprow2['EmployeeName'] ." ".$toprow2['Total_points_Rewarded']."<br/>";} ?>
</mark>
</li>
when I use three divs :
echo "<div style ='text-align:left'>" . $toprow2['overallRank'] . "</div><div style ='text-align:left'>" . $toprow2['EmployeeName'] . "</div><div style ='text-align:right'>" . $toprow2['Total_points_Rewarded'] . "</div>";
I am not able to align them :Current scenario :
the first block is the rank,then name and last points - the three fields that I am trying to echo here.
You can wrap your content elements with <div> and use flexbox to align your items, e.g. like this:
li mark {
display: flex;
justify-content: space-between;
}
li mark div {
flex: 0 1 auto;
width: 100px;
height: 100px;
border: 1px solid;
}
<li>
<mark>
<div>some content</div>
<div>some content</div>
<div>some content</div>
</mark>
</li>
Your PHP code would than probably look like this:
<li>
<mark>
<?php while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
echo "<div>" . $toprow2['overallRank'] . "</div><div>" . $toprow2['EmployeeName'] . "</div><div>" . $toprow2['Total_points_Rewarded'] . "</div>";
} ?>
</mark>
</li>
See MDN for more information or CSS-tricks for a nice guide.
You could still use list you would want to add the style to your style sheet but you will get the idea
Add new classes to style sheet
/* CSS layout */
.rstlist {
}
.ovrank {
list-style:none;
display:inline-block;
width:33%;text-align:center
}
.emname {
list-style:none;
display:inline-block;
width:33%;text-align:center
}
.tpr {
list-style:none;
display:inline-block;
width:33%;text-align:center
}
Then here is the edited script
<?php while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
echo '<ul class="rstlist">' . PHP_EOL .
'<li class="ovrank">' . $toprow2['overallRank'] . '</li>' . PHP_EOL .
'<li class="emname">' . $toprow2['EmployeeName'] . '</li>' . PHP_EOL .
'<li class="tpr">' . $toprow2['Total_points_Rewarded'] .'</li>' . PHP_EOL .
'<ul>';
}
?>
Now you can view in different browsers and adjust the style of each element to get your desired look based on you actual output...
How do I "highlight" (turn to a different color, make bold, whatever..) a link that has been clicked on?
Example is here: http://www.celebrything.com/
Trying to get the Today, Week, and Month links in the right sidebar to turn a different color once clicked.
Here's the code I'm using to show the results in the right sidebar:
<div id="sidebar">
<div class="post">
<h2>
<font color="#333333">Top 50 Celebrities</font>
<br>
<br>
<font color="#333333">Today</font>
<font color="#333333">Week</font>
<font color="#333333">Month</font>
</font>
<br>
<br>
<?php
function showTable ($table){
if (!in_array($table, array('today', 'week', 'month'))) {
return false;
}
global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
urlencode($row->name) . '&search=Search">' . $row->name .
'</a> - ' . $row->count . ' Posts<br/>';
}
}
if (!empty($_GET['table'])) {
showTable($_GET['table']);
} else { showTable('today'); }
?>
</h2>
</div>
</div>
<div class="clear"></div>
CSS can do this.
If a link has been visited at any point:
<style type="text/css">
a:visited { color: red; }
</style>
If the link has focus:
a:focus { color: red; }
Note: IE7 and lower don't support :focus. See CSS contents and browser compatibility and :focus.
If your asking howto make the current page active here is how you can do it:
<font color="#333333"><a class="<?php echo currentPage('today') ?>" href="index.php?table=today">Today</a></font>
<font color="#333333"><a class="<?php echo currentPage('week') ?>" href="index.php?table=week">Week</a></font>
<font color="#333333"><a class="<?php echo currentPage('month') ?>"href="index.php?table=month">Month</a></font>
function currentPage($isTableSet)
{
if($_GET['table'] == $isTableSet)
return 'selected'
else
return '';
}
And you will need to add the .selected class in your css and style it to whatever you want, maybe something like this:
<style type="text/css">
.selected {
font-weight: bold;
}
</style>