0% found this document useful (0 votes)
3 views

php4

The document is a PHP script that connects to a MySQL database to fetch and display data from the 'farmer_basic_details' table. It includes HTML for a user interface that allows users to view, filter, and manage farmer information, including options to add new farmers and view detailed information. The script also handles potential errors in database queries and ensures proper data sanitization for display.

Uploaded by

rock singh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

php4

The document is a PHP script that connects to a MySQL database to fetch and display data from the 'farmer_basic_details' table. It includes HTML for a user interface that allows users to view, filter, and manage farmer information, including options to add new farmers and view detailed information. The script also handles potential errors in database queries and ensures proper data sanitization for display.

Uploaded by

rock singh
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

<?

php
// Establish connection to the MySQL database
$conn = mysqli_connect("localhost", "root", "", "mahacot");

// Check if the connection was successful


if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// Query to fetch all data from the 'farmer_basic_details' table


$sql = "SELECT * FROM `farmer_basic_details`";
$result = mysqli_query($conn, $sql);

// Initialize $farmers array to hold the fetched data


if ($result) {
// Fetch all results as an associative array
$farmers = mysqli_fetch_all($result, MYSQLI_ASSOC);
} else {
// Handle query error
echo "Error: " . mysqli_error($conn);
}
?>

<!-- HTML structure for displaying farmers' data -->


<section class="section">
<div class="row">
<div class="col-lg-12">
<div class="d-flex justify-content-end mb-3">
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-
target="#addCboModal">Add New Farmer</button>
</div>
<div class="card">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center
mb-3">
<select id="statusFilter" class="form-control"
style="width: 200px;">
<option value="">All Farmers</option>
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
<div class="ms-auto">
<input type="text" id="searchInput"
placeholder="Search..." class="form-control" style="width: 200px;">
</div>
</div>
<div class="table-responsive">
<table id="tbl" class="table table-bordered">
<thead>
<tr>
<th scope="col">UID</th>
<th scope="col">Name</th>
<th scope="col">Contact</th>
<th scope="col">DOB</th>
<th scope="col">Gender</th>
<th scope="col">Address</th>
<th scope="col">Division</th>
<th scope="col">District</th>
<th scope="col">Tahsil</th>
<th scope="col">Village</th>
<th scope="col">APMC/Ginning Mills</th>
<th scope="col">CBO Details</th>
<th scope="col">7/12 Details</th>
<th scope="col">Crop Details</th>
<th scope="col">Upload Docs</th>
<th scope="col">Total Area</th>
<th scope="col">Expected Cotton Production
(quintals)</th>
<th scope="col">Form Status</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
// Check if $farmers array is populated before
using foreach
if (isset($farmers) && !empty($farmers)) {
// Loop through each farmer and display the
data in a table row
foreach ($farmers as $farmer): ?>
<tr>
<td><?php echo
htmlspecialchars($farmer['aadhaar_no']); ?></td>
<td><?php echo
htmlspecialchars($farmer['name_en'].' '.$farmer['father_en'].' '.
$farmer['surname_en']); ?></td>
<td><?php echo
htmlspecialchars($farmer['contact']); ?></td>
<td><?php echo
htmlspecialchars($farmer['dob']); ?></td>
<td><?php echo
htmlspecialchars($farmer['gender_name']); ?></td>
<td><?php echo
htmlspecialchars($farmer['add_en']); ?></td>
<td><?php echo
htmlspecialchars($farmer['division_name']); ?></td>
<td><?php echo
htmlspecialchars($farmer['district_name']); ?></td>
<td><?php echo
htmlspecialchars($farmer['tahsil_name']); ?></td>
<td><?php echo
htmlspecialchars($farmer['village_name']); ?></td>
<td>
<button class="view-btn1" data-
apmc="<?php echo htmlspecialchars($farmer['apmc_name']); ?>" data-ginning="<?php
echo htmlspecialchars($farmer['ginning_mill_name']); ?>">View</button>
</td>
<td>
<button class="view-btn2" data-
lrp="<?php echo htmlspecialchars($farmer['lrp_name']); ?>" data-cbo="<?php echo
htmlspecialchars($farmer['cbo_name']); ?>" data-mobile_no="<?php echo
htmlspecialchars($farmer['mobile_no']); ?>">View</button>
</td>
<td>
<button class="view-btn3" data-
ulpin_no="<?php echo htmlspecialchars($farmer['ulpin_no']); ?>" data-year="<?php
echo htmlspecialchars($farmer['year']); ?>" data-date_7_12="<?php echo
htmlspecialchars($farmer['date_7_12']); ?>" data-survey_no="<?php echo
htmlspecialchars($farmer['survey_no']); ?>" data-gad_no="<?php echo
htmlspecialchars($farmer['gad_no']); ?>" data-khate_no="<?php echo
htmlspecialchars($farmer['khate_no']); ?>" data-area="<?php echo
htmlspecialchars($farmer['area']); ?>">View</button>
</td>
<td>
<button class="view-btn4" data-
crop_name="<?php echo htmlspecialchars($farmer['crop_id_name']); ?>" data-
season="<?php echo htmlspecialchars($farmer['season_name']); ?>" data-area_ha="<?
php echo htmlspecialchars($farmer['area_ha']); ?>" data-appro_production="<?php
echo htmlspecialchars($farmer['appro_production']); ?>">View</button>
</td>
<td>
<button class="view-docs-btn" data-
docs='<?php echo json_encode([$farmer['profile_image'], $farmer['7_12_docs'],
$farmer['front_filepath'], $farmer['back_filepath']]); ?>'>View</button>
</td>
<td><?php echo
htmlspecialchars($farmer['area']); ?></td>
<td><?php echo
htmlspecialchars($farmer['appro_production']); ?></td>
<td><?php echo
htmlspecialchars($farmer['form__status_name']); ?></td>
<td>
<div class="form-check form-
switch">
<input class="form-check-input"
type="checkbox" role="switch" id="statusSwitch<?php echo $farmer['uid']; ?>" <?php
echo $farmer['status'] ? 'checked' : ''; ?> data-id="<?php echo $farmer['uid']; ?
>">
</div>
</td>
<td>
<a href="#" data-bs-toggle="modal"
data-bs-target="#userEditModal" data-user-id="<?php echo $farmer['uid']; ?>">
<i class="bi bi-pencil-
fill"></i>
</a>
</td>
</tr>
<?php endforeach;
} else {
echo "<tr><td colspan='19'>No farmers found or
data is not available.</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</section>

<?php
// Close the database connection
mysqli_close($conn);
?>

You might also like