So i got this for display in row my sql select:
$result = mysql_query("SELECT nome_sitio, horario, contato, morada, imagem FROM sitio where id_tipo=1");
echo "<table border='1'>
<tr>
<th>Nome</th>
<th>Horário</th>
<th>Contato</th>
<th>Morada</th>
<th>Imagem</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['nome_sitio'] . "</td>";
echo "<td>" . $row['horario'] . "</td>";
echo "<td>" . $row['contato'] . "</td>";
echo "<td>" . $row['morada'] . "</td>";
echo "<td>" . $row['imagem'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
But i made a design in html, that with html and css looks like this:
http://i.stack.imgur.com/gb1s9.png
And the html code is:
<div id="sitios">
<div class="imageRow">
<div class="single">
<img src="backoffice/images_sitios/thumbnails/$imagem"/>
</div>
</div>
<div id="texto">
<h2><b>$nome_sitio</b></h2>
<h3><b>Morada:</b></h3> $morada</br>
<h3><b>Horário:</b></h3> $horario</br>
<h3><b>Contato:</b></h3> $contato</br>
<h3><b>Freguesia:</b></h3> $idfreguesia
</div>
</div>
Can someone help me replacing the text with the vars?
You need to escape back to PHP to display the variables:
<div id="sitios">
<div class="imageRow">
<div class="single">
<img src="backoffice/images_sitios/thumbnails/<?php echo $imagem; ?>"/>
</div>
</div>
<div id="texto">
<h2><b><?php echo $nome_sitio; ?></b></h2>
<h3><b>Morada:</b></h3> <?php echo $morada; ?></br>
<h3><b>Horário:</b></h3> <?php echo $horario; ?></br>
<h3><b>Contato:</b></h3> <?php echo $contato; ?></br>
<h3><b>Freguesia:</b></h3> <?php echo $idfreguesia; ?>
</div>
</div>
Related
I create pdf in php using FPDF it's always showing blank documents. its size only 1.60kb. i fetching mysql data and want to admit card.
I create pdf in php using FPDF it's always showing blank documents. its size only 1.60kb. i fetching mysql data and want to admit card.
(i) admitcard.php
<div class="container">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#viewapp">View Applications</a></li>
<li>Logout</li>
</ul>
<div class="tab-content">
<div id="viewapp" class="tab-pane fade in active">
<?php
$rs1 = mysqli_query($con,"select * from demodata");
echo '<table class="table table-striped" id="tblData">';
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>NAME</th>";
echo "<th>DATE OF BIRTH</th>";
echo "<th>EMAIL ID</th>";
echo "<th>CONTACT NO.</th>";
echo "<th>SIGNUP DATE</th>";
echo "<tr>";
echo "</thead>";
echo "<tbody>";
while($ar = mysqli_fetch_array($rs1))
{
echo "<tr>";
echo "<td><a href='viewform.php?id=".$ar[0]."'>" . $ar[0] . "</a></td>";
echo "<td>" . $ar[3] . "</td>";
echo "<td>" . $ar[2] . "</td>";
echo "<td>" . $ar[4] . "</td>";
echo "<td>" . $ar[5] . "</td>";
echo "<td>" . $ar[6] . "</td>";
echo "<td> <a target='_blank' href='generate_pdf.php?id=".$ar[0]."'>
<input type='button' value='PDF' name='adcard' class='toggle btn btn-primary'> </a></td>";
echo "</tbody>";
echo "</table>";
?>
</div>
</div>
(ii) genrate_pdf.php
<?php
require("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$a=$_POST["add"];
$pdf->Cell(40,10,$a);
$pdf->Output();
?>
I am trying to create a CRUD dashboard, using a MySql backend and a bootstrap front-end with PHP and PDO to communicate with the database. I am a noob to web development, but not to coding.
The goal is to create a web app to log my patient consults. Thus, my table structure is a single "main" table and two children tables with relationships to the "main" table, named "consults" and "procedures".
I am trying to make a dashboard, where I display my "main" table, and then add two children tables below it. (Later on I will style it better, but I am trying to get this working).
The following is the best MWE I could think of (would love it if someone had a simpler solution). The first "logbook patients" table works well, and displays rows of patients well. Its the second table that is the problem, and in particular:
$sql = "SELECT * FROM proc";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
This is the area I keep getting an error. The error is:
Fatal error: Uncaught Error: Call to a member function query() on null in /home/paincl5/public_html/logbook/logbook.php:110 Stack trace: #0 {main} thrown in /home/paincl5/public_html/logbook/logbook.php on line 110
The code at line 110 is
unset($pdo);
My full code is:
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header clearfix">
<h2 class="pull-left">Logbook Patients</h2>
<a href="create.php" class="btn btn-success pull-right" >Add New Patient</a>
</div>
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM main";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
echo "<div style='height:300px;overflow-y:scroll;;'>";
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Surname</th>";
echo "<th>first_name</th>";
echo "<th>DOB</th>";
echo "<th>Hospital</th>";
echo "<th>MRN</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = $result->fetch()){
echo "<tr>";
echo "<td>" . $row['Surname'] . "</td>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['DOB'] . "</td>";
echo "<td>" . $row['Hospital'] . "</td>";
echo "<td>" . $row['MRN'] . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
// Free result set
unset($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
// Close connection
unset($pdo);
?>
</div>
</div>
</div>
</div>
// Procedure Table
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header clearfix">
<h2 class="pull-left">Procedures</h2>
<a href="create_proc.php" class="btn btn-success pull-right" >Add New Procedure</a>
</div>
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM proc";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
echo "<div style='height:300px;overflow-y:scroll;;'>";
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Procedure Type</th>";
echo "<th>Procedure Name</th>";
echo "<th>Notes</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = $result->fetch()){
echo "<tr>";
echo "<td>" . $row['procedure_type'] . "</td>";
echo "<td>" . $row['procedure_name'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>";
echo "<a href='update.php?id=". $row['id1'] ."' title='Update Record' data-toggle='modal' data-target='#myModal' ><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id1'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
// Free result set
unset($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
// Close connection
unset($pdo); //Here occurs the error (line 110)
?>
</div>
</div>
</div>
</div>
You are destroying your $pdo variable with unset($pdo) so any subsequent calls are trying to run methods against a null object.
Try removing references to that unset.
I'm assuming that the $pdo object is coming from config.php. Since you're using require_once, it will only include the config file the first time the require_once is called. That's why the $pdo is destroyed and not recreated.
I'm creating a thumbnail with a title, image and caption on it. I'm trying to select data from my table to show it into my homepage. Can someone help me to create a normal thumbnail in my php that contains the detail from my sql. I tried to search and can't find how to create a thumbnail using php and not html.
$sql = "SELECT * FROM news";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>first_name</th>";
echo "<th>last_name</th>";
echo "<th>email</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['image'] . "</td>";
echo "<td>" . $row['caption'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
In short, is there a way to create a php file from this?
<div class="col-md-4">
<div class="thumbnail">
<img alt="Memory" img src="../../images/a2.jpg">
<div class="caption">
<h3><b>
Title
</b></h3>
<p>
Caption Caption Caption Caption Caption
</p>
<p align="right">
<a class="btn btn-primary" href="news2.html">Read More</a>
</p>
</div>
</div>
</div>
Do you want to replace your table structure with that template structure? You'll need to adjust some of the data to fill the hyperlink (I don't know how you want to build that).
while($row=mysqli_fetch_array($result)){
echo "<div class=\"col-md-4\">";
echo "<div class=\"thumbnail\">";
echo "<img alt=\"Memory\" src=\"../../images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo "<h3>{$row["title"]}</h3>";
echo "<p>{$row["caption"]}</p>";
echo "<p align=\"right\">";
echo "<a class=\"btn btn-primary\" href=\"news2.html\">Read More</a>";
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
}
I already show the list of names from the database, but the problem is I don't know how to show the information each user, once I click some user in my list her/his information will appear.
html
<div class="member_list">
<div class="list-unstyled">
<?php require_once "../function/admin_function.php"; ?>
</div>
</div>
<div class="information" id="table_information">
<table class="table_information">
<tr>
<th colspan="4">Information</th>
</tr>
<tr>
<th>lastname</th>
<th>address</th>
<th>contact</th>
</tr>
<tr>
<td>
<?php include "../function/information_function.php"; ?>
</td>
</tr>
</table>
</div>
information_function - php
<?php
include "../connection/connection.php";
$sql = "SELECT * FROM registration";
$result = mysqli_query($dbconn, $sql);
while ($row = mysqli_fetch_array ($result)){
echo "<tr>";
echo "<td>" . $row['lname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "</tr>";
}
?>
user list - php
<?php
include "../connection/connection.php";
$sql = "SELECT * FROM registration";
$result = mysqli_query ($dbconn, $sql);
while($row = mysqli_fetch_array ($result)) {
echo "<ul class='table_php'>";
echo "<li>";
echo "<a href='#table_information' class='friends_link'>";
echo "<span class='chat-img pull-left'>";
echo "<img src='user.png' class='img-circle'>";
echo "</span>" . $row['lname'] . "</a>";
echo "</li>";
echo "</ul>";
}
?>
Put your code inside a function and just call that function after include statement.
//information_function//
<?php
include "../connection/connection.php";
function get_information(){
$sql = "SELECT * FROM registration";
$result = mysqli_query($dbconn, $sql);
while ($row = mysqli_fetch_array ($result)){
echo "<tr>";
echo "<td>" . $row['lname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['contact'] . "</td>";
echo "</tr>";
}
}
?>
//html//
<div class="member_list">
<div class="list-unstyled">
<?php require_once "../function/admin_function.php"; ?>
</div>
</div>
<div class="information" id="table_information">
<table class="table_information">
<tr>
<th colspan="4">Information</th>
</tr>
<tr>
<th>lastname</th>
<th>address</th>
<th>contact</th>
</tr>
<?php include "../function/information_function.php"; ?>
<?php get_information(); ?>
</table>
</div>
so I am using an HTML template, and have a dynamic table generated by PHP. For whatever reason, when I add the php table in, I can no longer scroll on the page. I am wondering if there is some work around, or there is something I should be looking for in the template CSS to fix this.
Here is my HTML with the embedded PHP:
<div class="block-head">
<h2>Datatable All Features</h2>
</div>
<div class="block-content np">
<table cellpadding="0" cellspacing="0" width="100%" class="table table-bordered table-striped sortable">
<thead>
<tr>
<th><input type="checkbox" class="checkall"/></th>
<th width="25%">Name</th>
<th width="25%">Gender</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row[username] . "</td>";
echo "<td>" . $row[gender] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
Here is my query, which I have above my HTML, for whatever it's worth. I know it's deprecated (just not a top priority right now):
$query = mysql_query("SELECT * FROM markerfollowing WHERE markerID = '$markerid'"); //query
When I remove the php in the table, it scrolls fine. When I put it back, no dice.
Sincere thanks for any help!
Here is my solution:
<?php
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . '<input type="checkbox" name="checkbox"/>' . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "</tr>";
}
?>
It's probably an error 500 which you cannot see because of your PHP.ini configuration.
change the $row[username] to $row['username'] and do the same with the gender.
This should do the job:
<?php
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "</tr>";
}
?>