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>";
}
Related
I have the following code, which successfully creates separate link for each of the group_concat objects, but instead of placing them into one table cell, it placing them to separate cells.
Can anyone help me?
Here is the full code:
<?php
if (isset($search))
{
$count=mysqli_num_rows($query) ;
if($count>=1){
$search_output .= "<hr color=red />$count results for <strong>$search</strong><hr color=red />";
while ($row = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$Title = $row['Title'];
$Year = $row['Year'];
$Authors = $row['Authors'];
$Journal=$row['Journal'];
$Genes=explode(',', $row['Genes']);
$Data_Type=$row['Data_Type'];
echo"<tr>";
echo "<td>".htmlspecialchars($row['Title'])."</td>";
echo "<td>".htmlspecialchars($row['Year'])."</td>";
echo "<td>".htmlspecialchars($row['Authors'])."</td>";
echo "<td>".htmlspecialchars($row['Journal'])."</td>";
foreach($Genes as $aGenes){
echo "<td><a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> </td>";
}
echo "<td>".htmlspecialchars($row['Data_Type'])."</td>";
echo"</tr>";
}
}else{
$search_output = "<hr />0 results for <strong>$search</strong><hr />";
}
echo "$search_output";
}
?>
I guess the problem is that you are creating separate cells for each link here
foreach($Genes as $aGenes){
echo "<td><a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> </td>";
}
instead of that do this
echo '<td>';
foreach($Genes as $aGenes){
echo "<a target=\"_blank\" href='http://www.ncbi.nlm.nih.gov/gene/?term=" .$aGenes."'> ".$aGenes." </a> ";
}
echo '</td>';
That is move the td tag out of foreach loop so that they are echoed only once for every element in while loop
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.
I'm attempting to display my data in a table from my database, I used the exact same code for another table but for some reason the table appears but is empty.
Thanks its solved!
you have to put brackets in while loop, close tag and the last :
echo "<table border=1 cellpadding=5>";
echo "<tr>";
echo "<th>Workshop Name</th>";
echo "<th>Workshop Price (£)</th>";
echo "<th>Workshop Description</th>";
echo "<th>Further Information</th>";
echo "</tr>";
$SQL="select workshopId,workshopName, workshopPrice,workshopDescription from Workshops order by workshopId";
$exeSQL=mysql_query($SQL) or die (mysql_error());
while ($arrayworkshop=mysql_fetch_array($exeSQL))
{
echo "<tr>";
//display details
echo "<td>".$arrayworkshop['workshopName']."</td>";
echo "<td>".$arrayworkshop['workshopPrice']."</td>";
echo "<td>".$arrayworkshop['workshopDescription']."</td>";
echo "<td><a href='ViewWorkshop.php?workshopId=".$arrayworkshop['workshopId']."'>";
//Display name of the Task
echo "Further Information"."</a></td>";
echo "</tr>";
}
echo "</table>";
I am building a zip/postal code search for the US & Canada. I have the code working great with just the US zip code search, which are 5 characters. The Canadian Postal codes are 6 characters. I need this code so if the user only adds 1-4 characters, if it matchs anything in the database, I don't want those results displayed, becuase it would display hundreds and they would all be wrong.
In my code, I have:
if (strlen($search_name)>=5)
How do I set this up so it takes both 5 or 6 characters?
So, this is the code I am using:
<?php
if (isset($_POST['search_name'])) {
$search_name = $_POST['search_name'];
if (!empty($search_name)) {
if (strlen($search_name)>=5) {
$query = "SELECT * FROM `search4` WHERE `ZipCode` LIKE '%".mysql_real_escape_string($search_name)."%'";
$query_run = mysql_query($query);
if (mysql_num_rows($query_run)>=1) {
echo "<table width=700' border='0'>";
echo "<tr>";
echo "<td width='700' valign='top'><table width='100%' border='0'>";
echo "<tr>";
echo "<td><p><strong>Results found: </strong></p>";
while ($query_row = mysql_fetch_assoc($query_run)) {{
echo $query_row ['ZipCode'].', ';
echo $query_row['ZipCity'].', ';
echo $query_row['ZipState'].'<br>';
echo '<p><strong>Area: </strong></p>'; echo $query_row['Area'].'';
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo '<span class="productdescription"><p>Mar Cor Office: </p></span></h2>';
echo $query_row['MCPOffice'].', ';
echo $query_row['CustClassID'].'<br>';
echo $query_row['Address1'].'<br>';
if(!empty($query_row['Address2'])) // This will skip if the field if it's empty
echo $query_row['Address2'].'<br>';
echo $query_row['City'].', ';
echo $query_row['State'].' ';
echo $query_row['Zip'].'<br>';
echo '<p><strong>Phone Number: </strong></p>';
echo $query_row['Phone'].'<br>';
echo '<p><strong>Fax Number: </strong></p>';
echo $query_row['Fax'].'<br><br>';
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</td>";
//BeginImage display result
$res=mysql_query("select * from Images");
{
echo "<td width='703' align='right' valign='top'>";?> <img src="<?php echo $query_row["Image"]; ?>"> <?php echo "</td>";
echo "</tr>";
}
//EndImage display result
}
}
}else{
echo 'No results found.';
}
}else{
echo 'Your search must be a 5-digit zip code.';
}
}
}
?>
if(strlen($search_name) == 5 || strlen($search_name) == 6) {
// Whatever your code is here
}
This condition will only pass if the string length is 5 characters or 6 characters
Strlen manual here
This question already has answers here:
Object Not Found error for simple php script
(4 answers)
Closed 9 years ago.
This code returns me a 404 Object Not Found error that I could not solve by modifying the code. And I don't know whether it's a code problem or a localhost problem. I need this to be running for my Final Year Project. Please help. Thanks a lot guys.
<?php
session_start();
require "dbc.php";
echo "<center>";
echo "<img src='web_header.jpg'/>";
echo "</center>";
if($_SESSION['admin_username'])
{
echo "Hello : ".$_SESSION['admin_username'];
echo "<p><a href ='admin_panel.php'>Admin Main</a> || <a href='manage_patients.php'>Manage Patients</a> || <a href ='manage_doctor.php'>Manage Doctors</a> || <a href ='mail_form.php'>Send Email</a> || <a href='logout.php'>Logout</a> ";
echo "<title>Manage Patients</title>";
echo "<h2>Manage Patients</h2>";
$query = mysql_query("SELECT * FROM users");
$numrows = mysql_num_rows($query);
if ($numrows != 0)
{
echo "<table width='1285' height='102' border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>IC Number</th><th>Address</th><th>Mobile Number</th><th>E-mail Address</th><th>Doctor ID</th></tr>";
while ($rows = mysql_fetch_assoc($query))
{
echo "<tr>";
echo "<td width='57' height='33'>";
echo "<center>";
echo $rows['id'];
echo "</center>";
echo "</td>";
echo "<td width='173'>";
echo $rows['name'];
echo "</td>";
echo "<td width='113'>";
echo "<center>";
echo $rows['icnum'];
echo "</center>";
echo "</td>";
echo "<td width='622'>";
echo $rows['address'];
echo "</td>";
echo "<td width='110'>";
echo "<center>";
echo $rows['mobile'];
echo "</center>";
echo "</td>";
echo "<td width='170'>";
echo "<center>";
echo $rows['email'];
echo "</center>";
echo "</td>";
echo "<td width='90'>";
echo "<center>";
echo $rows['docID'];
echo "</center>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo"<br>";
echo"</br>";
echo "<form action = 'manage_patients.php method=POST'>";
echo "<p>Assign Doctor ID : ";
echo "<input type='text' name='assign_id' value='Insert Doctor ID Here'>";
echo " for Patient ID : ";
echo "<input type='text' name='id' value='Insert Patient ID Here'></p>";
echo "<input type= 'submit' name='submit' value='Assign Now'>";
echo "</form>";
if (isset($_POST['submit']))
{
require "dbc.php";
$name = mysql_real_escape_string($_POST['assign_id']);
$id = mysql_real_escape_string($_POST['id']);
$query = mysql_query("UPDATE users SET docID='$assign_id' WHERE id='$id'");
echo "Doctor ID Successfully Assigned for Patient ID : $name ";
echo "<p>Refresh page to view changes.</p>";
}
}
}
else
{
header("location:index.html");
}
?>
change this
<form action = 'manage_patients.php method=POST'>
to
<form action = 'manage_patients.php' method='POST'>
If you are getting a 404 Error, it means that the page could not be found. So it is most likely not a problem with your code (that would give you a 500 Server Error). Instead you most likely have used the wrong URL.
<form action = 'manage_patients.php method=POST'>
I find this line of yours a bit suspiscious