I have a Attendance table containing attendance of all the employee.
Currently i am working on report_generation page.
So, i want to pass emp_mail id through drop-down box to fetch records of that particular employee.
here is the database table containing records
Here is the code from the report generation page:
$dbh = getDBH();
$output = "";
$sql = "SELECT ATT.AttDate FROM attandance ATT";
$query = $dbh->prepare($sql);
$query->execute();
$results = $query->fetchAll(\PDO::FETCH_OBJ);
$arrDates = array();
foreach($results as $intKey=>$objAttDate)
{
$arrDates[] = $objAttDate->AttDate;
}
var_dump($arrDates);
Related
Trying to insert form data into mysql database, my issues is as the user submits the form the data gets inserted twice into database. I know that I am doing something wrong with my 2nd query $query_file = "INSERT INTO upperbit_files... statment as when I remove the whole if loop if(mysqli_query($dbc, $query_info)){...} the form gets submitted once as expected.
Basically I need to insert data into 2 tables. One is for general product info and the other one is to store photos relating to that product both the table are connected via a global variable $advert_id. I am using 2 separate queries
Table1: advert_sell_category1, is for general product info
Table2: upperbit_files, is to store details of the images uploaded
But for some reason the 1st query relating to general product info is getting inserted twice into database and the irony is both the time the $advert_id is the same. Below is my code and a screenshot of the database for your understanding,
if(isset($_POST['postad'])){
$adtype = $_POST['offering_type'];
$manufacturer = mysqli_real_escape_string($dbc, $_POST['manufaturer']);
$mediafile = mysqli_real_escape_string($dbc,$_POST['mediafile']);
$GLOBALS['advrt_post_id'] = crypto_rand_secure(10, 100000);
$query_info = "INSERT INTO advert_sell_category1(advert_id,manufacturer,image_file)
VALUES('$advrt_post_id','$manufacturer','$mediafile')";
$result = mysqli_query($dbc, $query_info) or die(mysqli_error($dbc));
if(mysqli_query($dbc, $query_info)){
$last_id = mysqli_insert_id($dbc);
$query_link_id = "SELECT advert_id FROM advert_sell_category1 WHERE id = '$last_id' ";
$result_id = mysqli_query($dbc, $query_link_id);
while ($row = mysqli_fetch_assoc($result_id)) {
$link_id = $row['advert_id'];
if(!empty($mediafile)){
$media_file = explode(",", mysqli_real_escape_string($dbc,$_POST['mediafile']));
$media_file = array_filter($media_file);
$media_file_size = explode(",", mysqli_real_escape_string($dbc,$_POST['mediafilesize']));
$media_file_size = array_filter($media_file_size);
$media_file_type = explode(",", mysqli_real_escape_string($dbc,$_POST['mediafiletype']));
$media_file_type = array_filter($media_file_type);
for ($var = 0; $var < sizeof($media_file); $var++){
$query_file = "INSERT INTO upperbit_files(file,size,type,link_id) VALUES ('$media_file[$var]','$media_file_size[$var]','$media_file_type[$var]','$link_id')";
$result_file = mysqli_query($dbc, $query_file) or die(mysqli_error($dbc));
}
}
}
}
/********** Your Code ************/
$result = mysqli_query($dbc, $query_info) or die(mysqli_error($dbc));
if(mysqli_query($dbc, $query_info)){
/**********************/
See here in if statement you are calling mysqli_query() second time so same data is inserted twice. Use following code to solve your problem
/********** Suggested Code ************/
$result = mysqli_query($dbc, $query_info) or die(mysqli_error($dbc));
if(mysqli_affected_rows()>0){
/**********************/
I'm trying to get all rows from database , but when my database only have 1 row, it will show on website, if i'm add more 1 row, nothing show in website.
My code:
require_once('data/class.dbsetting.php');
Mysql sql = new Mysql();
sql->connect();
$query = 'select * from accounts';
$result = $sql->query($query);
While($row = $sql->fetch_assoc($result))
{
echo $row['Username'];
}
Try with :
mysql_fetch_all($result,MYSQL_ASSOC);
In my database i have 32 tables, and most of the tables has contain same ids. How can I delete all the data in the whole database that contains only an specific ID in one query(I mean each tables that contain that specific id).
DELETE * from (ALL TABLES) where id = 3;
Good question. Query might be optimal solution for this.
I have give solutions using PHP here below as PHP tag specified by you
<?php
require("db_connect.php");
$tables = mysqli_query($con, "SHOW TABLES FROM dbname");
while ($row = mysqli_fetch_assoc($tables)) {
$table_name = $row["Tables_in_dbname"];
mysqli_query($con, "DELETE FROM $table_name WHERE `id`=3");
}
?>
OR
create one more table where you make daily entries for id which needed to delete from all tables and everyday you might get the different list of id to delete from all tables.
Below here i have created a table ids_to_delete where i specified list of ids to be deleted.
<?php
require("db_connect.php");
//get ids from table where specified ids to be deleted
$ids = mysqli_query($con, "SELECT `id` FROM `ids_to_delete`");
$id_list = '';
//create ids list like 1,4,3,9,5,6,...
while ($row_id = mysqli_fetch_assoc($tables)) {
$id_list .= $row_id['id'] . ',';
}
$id_list = trim($id_list, ',');
$tables = mysqli_query($con, "SHOW TABLES FROM dbname");
while ($row = mysqli_fetch_assoc($tables)) {
$table_name = $row["Tables_in_dbname"];
mysqli_query($con, "DELETE FROM $table_name WHERE `id` IN ($id_list)");
}
//clear the ids_to_delete table
mysqli_query($con,"DELETE FROM `ids_to_delete`");
?>
I have a select option to get data from a table by using while loop
$select_material_code = "SELECT material FROM tbl_material";
$get_material_code = mysqli_query ($con, $select_material_code);
$options_material_Code = "--Select material Code--";
while ($result_material_code = mysqli_fetch_array($get_material_code))
{
$options_material_Code = $options_material_Code."<option>$result_material_code[0]</option>";
}
All data is coming into the list as expected, so, i want to continue selection data from selection option and fetch a value into next textbox, but i cannot get it.
please help....
$select_material_code = "SELECT material FROM tbl_material";
$get_material_code = mysqli_query ($con, $select_material_code);
$options_material_Code = "--Select material Code--";
while ($result_material_code = mysqli_fetch_array($get_material_code))
{
$options_material_Code =
$result_material_Code."<option>$result_material_code[0]</option>";
}
I have a drop down menu populated from a mysql database , is it possible to display two columns from the database but only when clicked ?
By this I mean, when you click you see a list of items on the left and a brief description on the right. The description column should only be visible when clicking on the dropdown.
Is this possible ?
My code is as follow, this queries the DB to check the current selection for the user.
I have tried adding a second column but it shows at all times which looks terrible.
<?php
require_once('db_connect.php');
$id = $_GET['id'];
$qry = "SELECT issue FROM issuetbl WHERE issueid =?";
$stmt = $mysqli->prepare($qry);
$stmt->bind_param('s', $id);
$stmt->execute();
$result = $stmt->get_result();
$client_result = $result->fetch_assoc();
$qry2 = "SELECT data FROM issdd";
$stmt = $mysqli->prepare($qry2);
$stmt->execute();
$resultdata = $stmt->get_result();
echo '<select name="enqiss">';
while($row = $resultdata->fetch_assoc()) {
if($client_result['issue']==$row['data']){
$selectCurrent='selected';
}else{
$selectCurrent='';
}
echo '<option value="'.$row['data'].'" '.$selectCurrent.'>'.$row['data'].'</option>';
}
echo '</select>';
?>
Many thanks