I'm working for a system by the use of php. We have an admin.php page where all the list of applicants were listed. And we want that when we click on a specific applicant's name, a lightbox would appear that will show more information about the applicant. But, these codes below seems to be not working and I don't know why. I am a newbie in php btw.
<?php
include('config.php');
$result = mysql_query("SELECT * FROM employee as t1")
or die(mysql_error());
echo "<table border='0' cellpadding='15' text-align = 'center' >";
echo "<tr>";
echo " <caption><b><font size = '5'> <h2>List of Applicants </h2> </b> </font><hr></caption>";
echo "<th>Applicant ID</th>";
echo "<th>Application Date</th>";
echo "<th>Name</th>";
echo "<th>Job</th>";
echo "</tr>";
while($row = mysql_fetch_array( $result ))
{
echo "<tr class='gradeC'>";
echo '<td><b><font color="#663300">' . $row['employee_id'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['date'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['fname'] . '</font></b></td>';
echo '<td><td>';
echo "</tr>";
}
echo "</table>";
function runMyFunction() {
echo "<div onclick =\"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\"></div>";
echo "<div id=\"light\" class=\"white_content\">This is the lightbox content. Close</div>";
echo "<div id=\"fade\" class=\"black_overlay\"></div>";
}
if (isset($_GET['hello'])) {
runMyFunction();
}
?>
I'm not sure but I think the problem is in the function, or the way I'm using the codes for lightbox to appear.
Can you rewrite this line
function runMyFunction() {
echo "<div onclick =\"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\"></div>";
echo "<div id=\"light\" class=\"white_content\">This is the lightbox content. Close</div>";
echo "<div id=\"fade\" class=\"black_overlay\"></div>";
}
to
function runMyFunction() {
?>
<div onclick ="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'"></div>
<div id="light" class="white_content">This is the lightbox content.
Close</div>
<div id="fade" class="black_overlay"></div>
<?php }
By eliminating the slashes could help make the code easier to process.
I hope this help.
Related
Why cannot call the div #popup1? I want to pass the $row['staffId'] to div and call the popup to show the information .
$result = mysql_query("SELECT * FROM Staff WHERE companyId='$companyIdResult'");
echo "<div>
<table >";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td >" . $row['staffName'] . "</td>";
echo "<td>" . $row['staffPhone'] . "</td>";
echo "<td><a class ='editbutton' href=' #popup1?edit_id=".$row['staffId'] ."'>Edit</a></td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
if($_GET['edit_id'] != ""){
$staffId = $_GET['edit_id'];
$sql2 = mysql_query("SELECT *FROM Staff WHERE staffId='".$staffId."'");
echo '<div id="popup1" class="overlay" >';
echo '<div class="popup">';
echo '<input type="text" name="staffName" value= ".$row['staffName']." ><br>';
echo '<input type="text" name="staffPhone" value=".$row['staffPhone']."><br>';
echo '</div>';
echo '</div>';
}
First of all you cannot append query parameters (?edit_id=...) to an anchor like #popup1, also you seem to misunderstand how PHP and the browser interact, you cannot open a popup and create it dynamically on the server side the way you seem to plan to. You could use AJAX to load the matching form for the staffId into your popup or generate a popup for every staffId beforehand (and create matching links with different anchors), but you try to open a popup1 with values generated on the server side and that doesn't work in this way.
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>";
}
So I want to apply this DIV class to these PHP items.
This is what I have, I know it does not work, but what would be correct for what I am trying to achieve.
I cant add the class to each individually, as I want the entire contents to be within the one div.
Hope that makes sense, thanks!
<?php
while($campaigns= mysqli_fetch_assoc($result)){
<div class="feeditem">;
echo "<div class='field'>".$test['part0']."</div>";
echo "<div class='field'>".$test['part1']."</div>";
echo "<div class='field'>".$test['part2']."</div>";
echo "<div class='field'>".$test['part3']."</div>";
echo "<div class='field'>".$test['part4']."</div>";
echo "<div class='field'>".$test['part5']."</div>";
echo "<div class='field'>".$test['part6']."</div>";
</div>;
}
?>
You should use an IDE that gives you errors for syntax problems... You do not have all the html code wrapped in echo ""; statements.
while ($campaigns = mysqli_fetch_assoc($result)) {
echo '<div class="feeditem">';
echo "<div class='field'>" . $test['part0'] . "</div>";
echo "<div class='field'>" . $test['part1'] . "</div>";
echo "<div class='field'>" . $test['part2'] . "</div>";
echo "<div class='field'>" . $test['part3'] . "</div>";
echo "<div class='field'>" . $test['part4'] . "</div>";
echo "<div class='field'>" . $test['part5'] . "</div>";
echo "<div class='field'>" . $test['part6'] . "</div>";
echo '</div>';
}
I believe this is what you're trying to accomplish:
<?php
echo '<div class="feeditem">';
while($campaigns = mysqli_fetch_assoc($result)){
echo"<div class='field'>".$test['part0']."</div>";
echo"<div class='field'>".$test['part1']."</div>";
echo"<div class='field'>".$test['part2']."</div>";
echo"<div class='field'>".$test['part3']."</div>";
echo"<div class='field'>".$test['part4']."</div>";
echo"<div class='field'>".$test['part5']."</div>";
echo"<div class='field'>".$test['part6']."</div>";
}
echo '</div>';
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to build a webpage about a football team.
So, I put info in a sql file, and then in xampp database. The problem is, when I put info for players and coaches like this:http://i.imgur.com/6EuYNPh.png they appear in the section of 'Stores' and 'Trophies' too which makes it look like annoying :P
http://i.imgur.com/tht9vTP.png
So I need a code like IF market value or Position or Place of birth = empty, then to hide those values (I mean to hide the: market value, position etc) I know that I must use the IF function in the functions file. I tried something but didn't work actually.
what is the exact code that I must use and where should I put it?
The functions file is here:
<?php
//Position:
//function to generate the local navigation bar for the bookstore web application
function gen_navigation(){
include("dbconnect.php");
echo "<head>";
echo '<link rel="stylesheet" type="text/css" href="css/navigation.css" />';
echo "</head>";
$query="select * from categories";
$result=mysql_query($query);
echo "<div id=navcontainer>";
echo "<ul id=navlist>";
while($row=mysql_fetch_array($result)){
echo "<li>";
echo "<a href=items.php?categoryid=";
echo $row['categoryid'];
echo ">";
echo $row['name'];
echo "</a>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
mysql_close();
}
//Position:
//function to display the new items. The layout is formated by using tables
//position:
//function to display the new items. The layout is formated by using tables
function showbooksbycat($categoryid=1,$offset=0,$limit=8){
if(empty($offset)){
$offset=0;
}
include("dbconnect.php");
$query="select * from items where categoryid=$categoryid order by isbn limit $offset,$limit";
$result=mysql_query($query);
echo "<br>";
while($row=mysql_fetch_array($result)){
echo "<table width=100% border=0>";
echo "<tr class=newitems>";
echo "<th>";
echo "Market Value".$row['market value'];
echo "</th>";
echo "<th>";
echo $row['name'];
echo "</th>";
echo "</tr>";
echo "<tr>";
echo "<td width=100>";
echo "<img src=pictures/".$row['picture'].">";
echo "</td>";
echo "<td align=left>";
echo "<p class=itemmaininf>";
echo "<b>Name:</b> ".$row['name']."<br>";
echo "<b>Position:</b> ".$row['position']."<br>";
echo "<b>Place Of Birth:</b> ".$row['birthplace']."<br>";
echo "<b>Date Of Birth:</b> ".$row['date']."<br>";
echo "<b>Previous Clubs:</b> ".$row['previous clubs']."<br>";
echo "</p>";
echo "<p class=footitem>";
echo "</p>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
}
mysql_close();
}
function nav($categoryid=1,$offset=0,$limit=8){
include("dbconnect.php");
$query="select * from items where categoryid=$categoryid";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
echo " ";
if($offset>0){
echo "<a href=items.php?categoryid=".$categoryid."&offset=".($offset-$limit);
echo ">";
echo "<img border=0 src=pictures/prev.gif></a>";
echo " ";
}
if($offset+$limit<$numrows){
echo "<a href=items.php?categoryid=".$categoryid."&offset=".($offset+$limit);
echo ">";
echo "<img border=0 src=pictures/next.gif></a>";
}
echo "</font>";
}
?>
the basic approach is
change
echo "<b>Place Of Birth:</b> ".$row['birthplace']."<br>";
to
if(!empty($row['birthplace'])){ //! is not, so this says not empty
echo "<b>Place Of Birth:</b> ".$row['birthplace']."<br>";
}
I have been trying to work this out for hours and I’m not sure how to achieve the correct result, hopefully someone will be able to help me.
I have the below code that will echo the result is a table vertically, but I want the cells next to each other horizontally, how can I achieve this?
<?php
echo "<table border='1' cellpadding='1' width='100%' bordercolor='000099'border='solid'>
";
echo '<div style="width:100%;">';
while($row = mysql_fetch_array($boxlink))
echo "<tr>";
{
echo "<td>" . $row['page_page_title'] . "</td>";
}
echo "</tr>";
echo "</table>";
echo '</div>';
?>
Brill that worked thanks a lot, why is it the small things can cause such a problem!
Move your tr tags outside of the loop. Each time a tr tag is seen it makes another row.
try this:
<?php
echo '<div style="width:100%;">';
echo "<table border='1' cellpadding='1' width='100%' bordercolor='000099'border='solid'>
";
echo "<tr>";
while($row = mysql_fetch_array($boxlink))
{
echo "<td>" . $row['page_page_title'] . "</td>";
}
echo "</tr>";
echo "</table>";
echo '</div>';
?>