Search Results display - php

i have a website project, where customers will need to search and the results will display, so i have done all that, but the problem is when a search results comes up,if there's more than 1 row,it dublicate the results on the same row,here are the code.
<h1 style="font-family:calibri;color:#13CC0D;text-align:center;">BODABODA SEARCH RESULTS</h1>
<table cellpadding="1" cellspacing="1" id="resultTable">
<thead>
<tr>
<th style="border-left: 1px solid #C1DAD7"> Region</th>
<th> District </th>
<th> Ward </th>
<th> Street</th>
<th> Driver Name </th>
<th>Identification Type</th>
<th>Identification Number</th>
<th>Motorcycle Type</th>
<th>Motorcycle Reg No</th>
<th>Phone Number</th>
</tr>
</thead>
<?php
$conn = mysqli_connect('localhost', 'efalococ_calcia', '*ad4#zNQ=nfN') or die('can not connect to the server'.mysqli_error);
mysqli_select_db($conn, 'efalococ_safirii');
if(isset($_POST['search'])){
$query = $_POST['region'];
$query1 = $_POST['district'];
$query2 = $_POST['ward'];
$query3 = $_POST['street'];
$results = mysqli_query($conn,"SELECT * FROM bodaboda WHERE (`region` LIKE '%".$query."%') && (`district` LIKE '%".$query1."%') && (`ward` LIKE '%".$query2."%') && (`street` LIKE '%".$query3."%')") or die(mysql_error());
if(mysqli_num_rows($results) >0){
while($row = mysqli_fetch_array($results)){
echo "<td>".$row['Region']."</td>" ;
echo "<td>".$row['District']."</td>";
echo "<td>".$row['Ward']."</td>";
echo "<td>".$row['Street']."</td>";
echo "<td>".$row['DriverName']."</td>";
echo "<td>".$row['IdentificationType']."</td>";
echo "<td>".$row['IdentificationNumber']."</td>";
echo "<td>".$row['MotorcycleType']."</td>";
echo "<td>".$row['MotorcycleRegNo']."</td>";
echo "<td>".$row['PhoneNumber']."</td>";
}
}else{
echo '<span style="color:red;font-family:cursive;font-size:14px;">No results found, Please Modify your search </span> Click here'.mysqli_error($conn);
}
}
?>
</table>
And the results shows like this!
Can you please help on that? any idea?

You just need to use the <tr> for every row.
The tag defines a row in an HTML table.
Learn more about HTML tr tag
while($row = mysqli_fetch_array($results)) {
echo "<tr>";
echo "<td>".$row['Region']."</td>" ;
echo "<td>".$row['District']."</td>";
echo "<td>".$row['Ward']."</td>";
echo "<td>".$row['Street']."</td>";
echo "<td>".$row['DriverName']."</td>";
echo "<td>".$row['IdentificationType']."</td>";
echo "<td>".$row['IdentificationNumber']."</td>";
echo "<td>".$row['MotorcycleType']."</td>";
echo "<td>".$row['MotorcycleRegNo']."</td>";
echo "<td>".$row['PhoneNumber']."</td>";
echo "</tr>";
}

Related

Query data from multiple database tables into form table (MYSQL,PHP)

As I'm new to PHP, I want to know that how to put data from different database tables into one table form on the page.
My codes so far as below,
<?php
include('DBconnect.php');
mysql_query("USE onlinerecruitment");
$username =$_SESSION['user'];
$result = mysql_query("SELECT * FROM application_data_file");
$rows = mysql_fetch_array($result, MYSQL_ASSOC);
$pos_id = $rows['Position_ID'];
$resultt = mysql_query("SELECT * FROM position WHERE Position_ID = '".$pos_id."' ");
$resulttt = mysql_query("SELECT * FROM resume_data_file WHERE App_Email = '".$pos_id."' ");
?>
<TABLE border ='1'>
<table style="width:100%">
<tr>
<th>Application ID</th>
<th>Applicant E-mail</th>
<th>Position Selected</th>
<th></th>
<th></th>
<th></th>
</tr>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) & $rowss = mysql_fetch_array($resultt, MYSQL_ASSOC)){
echo "<TR>";
echo "<TD>".$row['App_Data_ID']."</TD>";
echo "<TD>".$row['App_Email']."</TD>";
echo "<TD>".$rowss['Position_Name']."</TD>";
echo "<TD><a href='view-app-form.php?app_mail=".$row['App_Email']."'>View Application Data</a></TD>";
echo "<TD><a href='view-resume-form.php?app_mail=".$row['App_Email']."'>View Resume Data</a></TD>";
echo "<TD><a href='view-test-score.php?app_mail=".$row['App_Email']."'>View Testing Score Data</a></TD>";
echo "</TR>";
}
?>
</table>
I will focus the part here.
<TABLE border ='1'>
<table style="width:100%">
<tr>
<th>Application ID</th>
<th>Applicant E-mail</th>
<th>Position Selected</th>
<th></th>
<th></th>
<th></th>
</tr>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) & $rowss = mysql_fetch_array($resultt, MYSQL_ASSOC)){
echo "<TR>";
echo "<TD>".$row['App_Data_ID']."</TD>";
echo "<TD>".$row['App_Email']."</TD>";
echo "<TD>".$rowss['Position_Name']."</TD>";
echo "<TD><a href='view-app-form.php?app_mail=".$row['App_Email']."'>View Application Data</a></TD>";
echo "<TD><a href='view-resume-form.php?app_mail=".$row['App_Email']."'>View Resume Data</a></TD>";
echo "<TD><a href='view-test-score.php?app_mail=".$row['App_Email']."'>View Testing Score Data</a></TD>";
echo "</TR>";
}
?>
</table>
But if there is any problem in the section that I didn't focused, I still appreciate your solution.
Thank you in advance.
To do this you would need to use a JOIN in the sql statement.
mysql_query("SELECT resume_data_file.App_Email, position.Position_ID FROM position INNER JOIN resume_data_file ON position.Position_ID = position.Position_ID WHERE position.Position_ID = '".$pos_id."' ");
http://www.w3schools.com/sql/sql_join.asp

How to do pagination in wordpress page that contain mysql query?

I have one wordpress page in that I want to add pagination code. Because of mysql query the data in page is dynamic so I searched on google this but as I'm new in wordpress don't know what is WP-PageNavi plugin and how to use it. Please suggest me how to use it or any simpler way to do this.
My code is:
<table id="myTable" class="table table-striped" style="width:200% !important" name="myTab">
<thead>
<tr>
<th>Sr.No</th>
<th>Name</th>
<th>College Name </th>
<th>Passout Year</th>
<th>Branch</th>
<th>Email ID </th>
<th> Phone No.</th>
</tr>
</thead>
<tbody>
[hi_php]
mysql_connect("localhost","root","");
mysql_select_db("wp");
$query = mysql_query("select id,value from wp_crf_entries where value like '%Alumini%' ")or die(mysql_error());
while ($row=mysql_fetch_array($query))
{
$users = maybe_unserialize($row['value']);
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $users['firstname_1'];
echo " ".$users['lastname_2'] ."</br>";
echo "</td><td>";
echo $users['collegename_4'] ;
echo "</td><td>";
echo $users['passoutyear_7'] ;
echo "</td><td>";
echo $users['branch_8'] ;
echo "</td><td>";
echo $users['user_email'] ;
echo "</td><td>";
echo $users['contactno_10'] ;
echo "</td></tr>";
echo "<tr><td>";
}
[/hi_php]
</tbody>
</table>

Start tag em seen in table

I am coding php and seen this error while I trying to do a HTM5 validator. But the things is there is no in my whole file. Any suggestions what is wrong here?
Error Line 27, Column 4: Start tag em seen in table.
<em><br />
Edit note : I rarely want to add this code here due to the fact that's it is long and have nothing to do with the error (like I said above, there is no tag in the html)
<section>
<table>
<?php
include("./settings.php");
$conn = #mysqli_connect($host, $user, $pwd, $sql_db);
if (!$conn) {
echo "<p>Databse connection error</p>";
} else {
$eoinumber = trim($_POST["num"]);
$lname = trim($_POST["lname"]);
$query = "SELECT * FROM eoi WHERE EOInumber = $eoinumber AND lname = '$lname'";
$result = mysqli_query($conn,$query);
if (!$result) {
echo "<p>There is something wrong with the $query</p>";
} else {
$temp = mysqli_num_rows($result);
if ($temp == 0) {?>
<p>0 enquiry found. Please check again your EOInumber and last name</p>
<?php } else {
?>
<thead>
<tr>
<th>EOI number</th>
<th>Job ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Date of Birth</th>
<th>Gender</th>
<th>Street</th>
<th>Town</th>
<th>State</th>
<th>Postcode</th>
<th>Mail</th>
<th>Telephone</th>
<th>Skills</th>
<th>Other Skills</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>",$row["EOInumber"],"</td>";
echo "<td>",$row["job_num"],"</td>";
echo "<td>",$row["fname"],"</td>";
echo "<td>",$row["lname"],"</td>";
echo "<td>",$row["bday"],"</td>";
echo "<td>",$row["gender"],"</td>";
echo "<td>",$row["street"],"</td>";
echo "<td>",$row["town"],"</td>";
echo "<td>",$row["state"],"</td>";
echo "<td>",$row["postcode"],"</td>";
echo "<td>",$row["mail"],"</td>";
echo "<td>",$row["tele"],"</td>";
echo "<td>",$row["skill"],"</td>";
echo "<td>",$row["other"],"</td>";
echo "</tr>";
echo "</tbody>";
// echo "<p>Sucess</p>";
}
?>
</table>
Regardless of the presence or otherwise of the <em> tag, you are going to run into problems because you are opening the table tag and then potentially putting a <p> or other elements directly inside it, which is illegal (you can put <thead>, <tbody>, <caption>, <tr>, <tfoot> elements inside a <table>). It would be better if you opened the table after checking whether the queries had run successfully or not, i.e.:
<section>
<?php
include("./settings.php");
$conn = #mysqli_connect($host, $user, $pwd, $sql_db);
if (!$conn) {
echo "<p>Databse connection error</p>";
} else {
$eoinumber = trim($_POST["num"]);
$lname = trim($_POST["lname"]);
$query = "SELECT * FROM eoi WHERE EOInumber = $eoinumber AND lname = '$lname'";
$result = mysqli_query($conn,$query);
if (!$result) {
echo "<p>There is something wrong with the $query</p>";
} else {
$temp = mysqli_num_rows($result);
if ($temp == 0) {
echo "<p>0 enquiry found. Please check again your EOInumber and last name</p>";
} else {
echo "<table>";
... echo the table header...
while ($row = mysqli_fetch_assoc($result)) {
... echo table results...
}
echo "</table>";
}
}
?>
You missed a few }
So this should work:
<section>
<table>
<?php
include("./settings.php");
$conn = #mysqli_connect($host, $user, $pwd, $sql_db);
if (!$conn) {
echo "<p>Databse connection error</p>";
exit;
}
$eoinumber = trim($_POST["num"]);
$lname = trim($_POST["lname"]);
$query = "SELECT * FROM eoi WHERE EOInumber = $eoinumber AND lname = '$lname'";
$result = mysqli_query($conn,$query);
if (!$result) {
echo "<p>There is something wrong with the $query</p>";
exit;
} else {
$temp = mysqli_num_rows($result);
}
if ($temp == 0) { ?>
<p>0 enquiry found. Please check again your EOInumber and last name</p>
<?php } else { ?>
<thead>
<tr>
<th>EOI number</th>
<th>Job ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Date of Birth</th>
<th>Gender</th>
<th>Street</th>
<th>Town</th>
<th>State</th>
<th>Postcode</th>
<th>Mail</th>
<th>Telephone</th>
<th>Skills</th>
<th>Other Skills</th>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_assoc($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>",$row["EOInumber"],"</td>";
echo "<td>",$row["job_num"],"</td>";
echo "<td>",$row["fname"],"</td>";
echo "<td>",$row["lname"],"</td>";
echo "<td>",$row["bday"],"</td>";
echo "<td>",$row["gender"],"</td>";
echo "<td>",$row["street"],"</td>";
echo "<td>",$row["town"],"</td>";
echo "<td>",$row["state"],"</td>";
echo "<td>",$row["postcode"],"</td>";
echo "<td>",$row["mail"],"</td>";
echo "<td>",$row["tele"],"</td>";
echo "<td>",$row["skill"],"</td>";
echo "<td>",$row["other"],"</td>";
echo "</tr>";
echo "</tbody>";
// echo "<p>Sucess</p>";
}
}
?>
</table>
<!--...-->

viewing a table based on a previous id

I have a table set up called Modules, that once a user is logged in it brings up the modules related to that user, this works fine. At the side of each module in the table I have a lessons link. once the user clicks on that I want it to display the lessons based on the module ID.
Any help would be great full.
My Module code in case I need to add something to it is as follows;
<?
include('../inc/security.inc.php');
authorise();
// Include databse connection file
include('../inc/connection.inc.php');
// Connect to the database
connect();
$userID = $_SESSION['userID'];
$sql = "SELECT * FROM tblModule WHERE userID = '$userID'" ;
$result = #mysql_query($sql) or die(mysql_error());
?>
and displaying the module table as follows;
<?php
// run a while loop through all records and create a new row for each one
while ($record = mysql_fetch_object($result))
{
?>
<table class="myTable">
<th class="col">Module ID</th>
<th class="col">Module Title</th>
<th class="col">Module Description</th>
<th class="col">User ID</th>
<th class="col">Manage</th>
</tr>
<tr class="row">
<td class="cell"><?php echo $record->moduleID; ?></td>
<td class="cell"><?php echo $record->moduleTitle; ?></td>
<td class="cell"><?php echo $record->moduleDescription; ?></td>
<td class="cell"><?php echo $record->userID; ?></td>
<td class="cell">Lessons</td>
</tr>
</table>
<?
}
// clean up after ourselves by cleating $result and closing the database connection
mysql_free_result($result);
mysql_close();
?>
Then so far in the lesson table i have;
<?
include('../inc/security.inc.php');
authorise();
// Include databse connection file
include('../inc/connection.inc.php');
// Connect to the database
connect();
$moduleID = $_SESSION['moduleID'];
$sql = "SELECT * FROM tblLessons WHERE moduleID = '$moduleID'" ;
$result = #mysql_query($sql) or die(mysql_error());
?>
With the result been displayed as;
<?php
// run a while loop through all records and create a new row for each one
while ($record = mysql_fetch_object($result))
{
?>
<table class="myTable">
<th class="col">LessonID</th>
<th class="col">Lesson Number</th>
<th class="col">Lesson Description</th>
<th class="col">ModuleID</th>
<th class="col">Lesson Plan ID</th>
<th class="col">Manage</th>
</tr>
<tr class="row">
<td class="cell"><?php echo $record->lessonID; ?></td>
<td class="cell"><?php echo $record->lessonNumber; ?></td>
<td class="cell"><?php echo $record->lessonDescription; ?></td>
<td class="cell"><?php echo $record->moduleID; ?></td>
<td class="cell"><?php echo $record->lessonPlanID; ?></td>
</tr>
</table>
<?
}
// clean up after ourselves by cleating $result and closing the database connection
mysql_free_result($result);
mysql_close();
?>
You're passing the moduleID as a query string variable to lessons.php, but in lessions.php you're looking for it in session data.
$moduleID = $_SESSION['moduleID'];
Try:
$moduleID = isset($_GET['moduleID']) ? $_GET['moduleID'] : false;
if ( $moduleID ) {
$sql = sprintf('SELECT * FROM tblLessons WHERE moduleID = %d', $moduleID);
$result = #mysql_query($sql) or die(mysql_error());
} else {
// No moduleID, so show an error message, redirect user, or the like
}
Note that I'm using sprintf so that $moduleID is converted to a digit. The code you're using - passing the value directly to MySQL - is dangerous. Google: "sql injection".
If $moduleID can in fact be a string, then you need to take extra steps to ensure that the data is sanitized before being passed to MySQL, e.g.
$moduleID = isset($_GET['moduleID']) ? $_GET['moduleID'] : false;
if ( $moduleID ) {
$sql = sprintf("SELECT * FROM tblLessons WHERE moduleID = '%s'", mysql_real_escape_string($moduleID));
$result = #mysql_query($sql) or die(mysql_error());
} else {
// No moduleID, so show an error message, redirect user, or the like
}
You should also consider switching to PDO, as the mysql_ functions are depreciated. PDO is a much easier, safer way to interact with MySQL.

tablesorter.pager plugin

The number of returned results is 2 which is correct and it comes up with 2 for the number of pages which is also correct but instead of showing 1 on the first page it shows both records. I'm not sure hwy the tablesorter.pager plugin is doing that.
<?php
session_start();
require("../inc/dbconfig.php");
require("../inc/global_functions.php");
require("../inc/variables.php");
// find out how many rows are in the table
$query = "SELECT CONCAT_WS(' ',firstName,lastName) AS name, username, emailAddress, userID FROM manager_users WHERE statusID != 4";
$result = mysqli_query($dbc,$query);
$rows = mysqli_num_rows($result);
$itemsPerPage = 1;
$totalPages = ceil($rows/$itemsPerPage);
$fileName = basename($_SERVER[PHP_SELF]);
$pageName = "User Accounts";
$userData = $_SESSION['user_data'];
$userID = $userData['userID'];
?>
<script type="text/javascript">
$(document).ready(function() {
$('#usersPageList').tablesorter().tablesorterPager({sortlist: [0,0], container:$('#usersPageList .pagination'),cssPageLinks:'a.pageLink'});
$('a.bt_green').click(function(e) {
e.preventDefault();
$('div.right_content').load('forms/addnew/' + $(this).attr('id'));
});
$('.ask').jConfirmAction();
});
</script>
<h2>User Accounts</h2>
<table id="usersPageList" class="rounded-corner">
<thead>
<tr>
<th scope="col" class="rounded-first"></th>
<th scope="col" class="rounded">Name</th>
<th scope="col" class="rounded">Email Address</th>
<th scope="col" class="rounded">Username</th>
<th scope="col" class="rounded">Edit</th>
<th scope="col" class="rounded-last">Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5" class="rounded-foot-left"><em>Displays all of the registered and verified users!</em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"\" /></td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['emailAddress']."</td>";
echo "<td>".$row['username']."</td>";
echo "<td><img src=\"images/user_edit.png\" alt=\"\" title=\"\" border=\"0\" /></td>";
echo "<td>";
if (($row['userID'] !== '10000') && ($row['userID'] !== $userID)){
echo "<img src=\"images/trash.png\" class=\"delete\" alt=\"\" title=\"\" border=\"0\" id=\"".$row['userID']."\" />";
}
echo "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<?php
addRemove($fileName,$pageName);
pagination($totalPages);
?>
<input type="hidden" name="myhiddenPageToken" id="myhiddenPageToken" value="useraccounts" />
Maybe I'm misunderstanding what you want, but I think you want just one record at a time to show on the page? I have no idea why you would do that, but you can use the pager's size option:
$("table").tablesorter({
widthFixed: true,
widgets: ['zebra']
}).tablesorterPager({
container: $("#pager"),
size: 1 // only show one record
});
Also, if you are using the select to change the number of records showing, you'll need to include a "1" (demo).

Categories