i have a problem with my code below..
I want to display the data that is not associated with the ID of my $jid but i think i have a problem with my loop. the First data displayed is removed and replaced with the last result...
heres the code. can somebody help me out on this
$check_exist_query = mysql_query("SELECT * FROM physical_abilities_assignment where job_title_id = $jid");
while($check_exist_row = mysql_fetch_array($check_exist_query)){
$list = "";
$physical_title_id = $check_exist_row['2'];
if(empty($physical_title_id)){
$display_abilities_query = "SELECT * FROM physical_abilities";
}else{
$display_abilities_query = "SELECT * FROM physical_abilities WHERE id != $physical_title_id";
}
$display_abilities_result = mysql_query($display_abilities_query);
while($display_abilities_row = mysql_fetch_array($display_abilities_result)){
$abilities_name = $display_abilities_row[2];
$abilities_id = $display_abilities_row[0];
$list .= "<tr>
<td $bgcolor align=center><input type=\"checkbox\" ".$check." name=\"job_title[]\" value=".$title_id." id=\"".$title_id."\"></td>
<td $bgcolor style=\"padding-left:5px;\">".$abilities_name."</td>
<td $bgcolor align=center><a onClick=\"return confirm('Are you sure you want to delete this entry?');\" href=?do=delete&id=". $row[0] ."><img src=\"images/delete-icon.png\" border=0 ></a> <img src=\"images/edit-icon.png\" title=\"Edit This\" border=0/></td>
</tr>";
}
$list = "";
$check_exist_query = mysql_query("SELECT * FROM physical_abilities_assignment where job_title_id = $jid");
while($check_exist_row = mysql_fetch_array($check_exist_query)){
$physical_title_id = $check_exist_row['2'];
if(empty($physical_title_id)){
$display_abilities_query = "SELECT * FROM physical_abilities";
}else{
$display_abilities_query = "SELECT * FROM physical_abilities WHERE id != $physical_title_id";
}
$display_abilities_result = mysql_query($display_abilities_query);
while($display_abilities_row = mysql_fetch_array($display_abilities_result)){
$abilities_name = $display_abilities_row[2];
$abilities_id = $display_abilities_row[0];
$list .= "<tr>
<td $bgcolor align=center><input type=\"checkbox\" ".$check." name=\"job_title[]\" value=".$title_id." id=\"".$title_id."\"></td>
<td $bgcolor style=\"padding-left:5px;\">".$abilities_name."</td>
<td $bgcolor align=center><a onClick=\"return confirm('Are you sure you want to delete this entry?');\" href=?do=delete&id=". $row[0] ."><img src=\"images/delete-icon.png\" border=0 ></a> <img src=\"images/edit-icon.png\" title=\"Edit This\" border=0/></td>
</tr>";
}
echo $list;
Try this.
Related
In our website, we have textbox to ask input values from user. If user input the data Q54497899, rest of the results must be shown from database. Rightnow, I want to add checkbox on each result. I tried to add with foreach but it still doesn't work for me. I will provide codes below which were written in the correlationwafer_result.php. Want to add checkbox beside each Q54497899
<?php
// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();
$productlotid = isset ($_GET['productlotid'])? $_GET['productlotid']:'';
$sql = "SELECT * FROM productdb.tbl_correlationwafer WHERE `lotid` = '$productlotid'";
$result1 = mysqli_query($conn,$sql);
$cnt = 0;
echo "<table id='corwafer'>";
while ($row = mysqli_fetch_assoc($result1)) {
echo "<tr>";
echo "<th colspan='2'>Lot ID:</th>";
echo "<th colspan='2'>Product:</th>";
echo "<th colspan='4'>EWSFLOW </th>";
echo "<th>Zone</th>";
echo "</tr>";
$field1name = $row["lotid"];
$field2name = $row["product"];
$field3name = $row["ewsflow"];
$field4name = $row["zone"];
echo '<tr>
<td colspan="2">'.$field1name.'</td>
<td colspan="2">'.$field2name.'</td>
<td colspan="4">'.$field3name.'</td>
<td >'.$field4name.'</td>
</tr>';
foreach($productlotid as $k => $v){
if($k == $row["lotid"]){
echo "<input type=\"checkbox\" id=\"chkproductlotid" . $cnt . "\" name=\"chkproductlotid\" value=\"$v\"><font face=\"arial\" size=\"2\" color=\"#3C5F84\">". $k . "</font>";
}
}
$cnt++;
}
echo "</table>";
flush();
mysqli_close($conn);
?>
Try :
$('chkproductlotid').val();
$productlotid = isset ($_GET['productlotid'])? $_GET['productlotid']:'';
Your $productlotid is more like a string not an array, does it?
You should put your checkbox inside td, and I think your checkbox value should be able to take from the first While Loop, no need that Foreach..
I am creating a page in PHP, HTML and using MySQL. Currently When I load the page, it selects all the data from the staff table and displays it.
I have a search function so the user can filter by first name, last name or full name.
When the user clicks the search button, is it possible to have the data that's showing every row and just to replace it with my searched criteria.
Currently my code is searching correct but its just adding it as a row to all the data rows. I thought i could use a regex to replace but the variable is not accessible globally since it is inside an if statement.
<?php
$output = NULL;
if(isset($_POST['submit'])) {
$regex = '/<table[^>]*>.*?<\/table>/s'; //test doesnt work
$replace = ''; //test doesnt work
$result = preg_replace($regex, $replace, $html); //test doesnt work "no html variable"
echo($result); //test doesnt work
$search = $con->real_escape_string($_POST['search']);
$res = $_POST['searchGroup'];
if($res == "first") {
$resultSet = $con->query("SELECT * FROM staff WHERE firstname LIKE '%$search%'");
if($resultSet->num_rows > 0) {
while($rows = $resultSet -> fetch_assoc()) {
$field1name = $rows["firstname"];
$field2name = $rows["lastname"];
$field3name = $rows["dob"];
$field4name = $rows["created"];
$field5name = $rows["last_updated"];
$field6name = $rows["is_user"];
$output .= '<tr>
<td>'.$field1name.'</td>
<td>'.$field2name.'</td>
<td>'.$field3name.'</td>
<td>'.$field4name.'</td>
<td>'.$field5name.'</td>
<td>'.$field6name.'</td>
</tr>';
}
}
else {
$output = "No Results";
}
}
And then my code which is currently displaying all the data
<?php
$query = "SELECT * FROM staff";
echo '<div class="tableFixHead">
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td> <font face="Arial"><b>First Name</b></font> </td>
<td> <font face="Arial"><b>Last Name</b></font> </td>
<td> <font face="Arial"><b>Date of Birth</b></font> </td>
<td> <font face="Arial"><b>Creation Date</b></font> </td>
<td> <font face="Arial"><b>Last Updated</b></font> </td>
<td> <font face="Arial"><b>Is User</b></font> </td>
</tr>
</div>';
echo $output;
if ($result = $con->query($query)) {
while ($row = $result->fetch_assoc()) {
$field1name = $row["firstname"];
$field2name = $row["lastname"];
$field3name = $row["dob"];
$field4name = $row["created"];
$field5name = $row["last_updated"];
$field6name = $row["is_user"];
$html= '<tr>
<td>'.$field1name.'</td>
<td>'.$field2name.'</td>
<td>'.$field3name.'</td>
<td>'.$field4name.'</td>
<td>'.$field5name.'</td>
<td>'.$field6name.'</td>
</tr>';
echo $html;
}
$result->free();
}
?>
My approach is probably wrong but I was wondering if it is possible to somehow remove that data that is in the current $html echo tag when my search button is pressed.
Besides the code style, vulnerabilities i would like to offer you an example of some sorts. as i presume that you are still a student.
just a simple example what you could do;
$query = "SELECT * FROM staff";
if(isset($_POST['submit'])) {
$search = $con->real_escape_string($_POST['search']);
$query .= " WHERE firstname LIKE '%$search%'"
}
This should be sufficient to help you forward.
i have this kind of report
i want to make a report like in the image above.
i already try it with this code :
$id = 0;
$id2 = 0;
$no = 1;
$q3 = mysql_query("SELECT * FROM pendidikan, unsur, subunsur WHERE pendidikan.id_sub = subunsur.id_sub AND subunsur.id_unsur = unsur.id_unsur AND pendidikan.nidn = $_GET[nidn]");
$q4 = mysql_query("SELECT * FROM pendidikan, unsur, subunsur WHERE pendidikan.id_sub = subunsur.id_sub AND subunsur.id_unsur = unsur.id_unsur AND pendidikan.nidn = $_GET[nidn]");
$data = array();
while($d=mysql_fetch_assoc($q3)){
$no++;
if($id != $d['id_unsur']){
$no = $no+1;
echo"<tr>
<td>$d[kode_unsur]</td>
<td colspan='8'>$d[nama_unsur]</td>
</tr>";
while($f=mysql_fetch_array($q3)){
if($id2 != $f['id_sub']){
echo"<tr>
<td rowspan='$no'>$d[kode_sub]</td>
<td colspan='8'>$d[nama_sub]</td>
</tr>";
}
$id2 = $f['id_sub'];
while($g=mysql_fetch_assoc($q4)){
if($g['id_sub'] == $f['id_sub']){
echo"<tr>
<td>$g[no_butir]</td>
<td>$g[uraian]</td>
<td>$g[thn_smt_akademik]</td>
<td>$g[tanggal]</td>
<td>$g[satuan_hasil]</td>
<td>$g[jml_vlm_kegiatan]</td>
<td>$g[jml_angka_kredit]</td>
<td>$g[bukti]</td>
</td>";
}
}
}
}
$id = $d['id_unsur'];
}
what should i do, because with that code, im creating row with the same sub A, not B like this :
any help will be appreciated. Thanks.
I have set up a for and while loop to print through the contents of my database for my menu system. It works fine, however, the places to where each of the table contents is displayed is one below where it should be. See this picture below:
The problem is that the items which are showing under "Main Courses" are supposed to be under the "Starters" section.
See my code:
<?php
$query = "SELECT * FROM menu_type";
$result = mysqli_query($connect, $query);
$result_array = array();
$numRows = mysqli_num_rows($result); // returns the num of rows from the query above, allowing for dynamic returns
while($row = mysqli_fetch_assoc($result)){
$menuType = $row['type'];
$result_array[] = $menuType; // This array holds each of the menu_types from DB
}
$countArray = count($result_array);
for($i = 0; $i < $countArray; $i++){
echo "<h1 id='starters' class='head-font text-center head'>$result_array[$i]</h1>";
$query = "SELECT * FROM menu WHERE type_id='$result_array[$i]'";
$result = mysqli_query($connect, $query) or die(mysqli_error($connect));
echo
"
<div id='hide'>
<table class='table table-hover table-responsive'>
<thead>
<tr>
<th>
Item
</th>
<th class='text-right'>
Price
</th>
</tr>
</thead>
<tbody>
";
$menuQuery = "SELECT * FROM menu, menu_type WHERE type_id='$i' AND menu.type_id = menu_type.id";
$menuResult = mysqli_query($connect, $menuQuery) or die(mysqli_error($connect));
while ($row = mysqli_fetch_assoc($menuResult)) {
$name = $row['name'];
$description = $row['description'];
$price = $row['price'];
echo
"<tr>" .
"<td>$name - <small>$description</small></td>" .
"<td class='text-right'>" . "£" . $price . "</td>" .
"</tr>";
}
echo "</tbody>
</table>
</div>";
}
for($j = 1; $j < $numRows+1; $j++){
echo $j;
}
// print_r($result_array[2]);
?>
I'm trying to fetch multiple rows in MySQL database but it is fetching only the first entry!
$data = mysql_query("SELECT * FROM twitter_tbl")
while($info = mysql_fetch_array($data))
{
$desc = $info['description'];
$screen_name1 = $info['screen_name'];
$final_oauth_token = $info['final_oauth_token'];
$final_oauth_token_secret = $info['final_oauth_token_secret'];
);
So I get only 1 row but I need to get multiple rows as every row has got its unique screen_name and description.
I don't know where I'm going wrong.
Correct code to this:
$data = mysql_query("SELECT * FROM twitter_tbl");
while($info = mysql_fetch_array($data))
{
echo $desc = $info['description'];
echo $screen_name1 = $info['screen_name'];
echo $final_oauth_token = $info['final_oauth_token'];
echo $final_oauth_token_secret = $info['final_oauth_token_secret'];
}
While statements are enclosed within {} not {);
Edited:
$data = mysql_query("SELECT * FROM twitter_tbl")
while($info = mysql_fetch_array($data))
{
Echo $desc = $info['description'];
Echo $screen_name1 = $info['screen_name'];
Echo $final_oauth_token = $info['final_oauth_token'];
Echo $final_oauth_token_secret = $info['final_oauth_token_secret'];
}
You simply need to place it in a container that would display the results on your webpage
Try This:
echo "<table>";
$data = mysql_query("SELECT * FROM twitter_tbl");
while($info = mysql_fetch_array($data))
{
$desc = $info['description'];
$screen_name1 = $info['screen_name'];
$final_oauth_token = $info['final_oauth_token'];
$final_oauth_token_secret = $info['final_oauth_token_secret'];
echo "
<tr>
<td>".$desc."</td>
<td>".$screen_name1."</td>
<td>".$final_oauth_token."</td>
<td>".$final_oauth_token_secret."</td>
</tr>";
}
echo "</table>";
Adding data into array.
what is your target? (Store data? echo?)
CODE:
$data = mysql_query("SELECT * FROM twitter_tbl");
if($data && mysql_num_rows($data) > 0)
{
while($info = mysql_fetch_array($data))
{
$desc[$i] = $info['description'];
$screen_name1[$i] = $info['screen_name'];
$final_oauth_token[$i] = $info['final_oauth_token'];
$final_oauth_token_secret[$i] = $info['final_oauth_token_secret'];
++$i;
}
unset($i, $info, $data);
}
Or like Echo mode
CODE:
$data = mysql_query("SELECT * FROM twitter_tbl");
if($data && mysql_num_rows($data) > 0)
{
$x = "
<table>
<tr>
<th>
desc
</th>
<th>
screen_name
</th>
<th>
oauth Token
</th>
<th>
secret oauth Token
</th>
</tr>";
//Warning it's eat a lot of memory
while($info = mysql_fetch_array($data))
{
$x .= "
<tr>
<td>
{$info['description']}
</td>
<td>
{$info['screen_name']}
</td>
<td>
{$info['final_oauth_token']}
</td>
<td>
{$info['final_oauth_token_secret']}
</td>
</tr>";
}
$x = "
</table>";
echo $x;
unset($info, $data, $x);
}