0byt3m1n1
Path:
/
var
/
www
/
listcrawler.app
/
public_html
/
cron
/
[
Home
]
File: fix-lists-locations.php
<?php ini_set('max_execution_time', 0); require '../db.php'; // TRUNCATE TABLE `lists_locations`; $truncate = "TRUNCATE TABLE `lists_locations` "; mysqli_query($conn, $truncate); $getLocation = "SELECT `id` from `locations` "; $getLocationResult = mysqli_query($conn, $getLocation); $countLocation = mysqli_num_rows($getLocationResult); if ( $countLocation > 0) { $records = 10; $start = 0; $counter = 0; $getListCount = "SELECT `id` FROM `lists` "; $getListCountResult = mysqli_query($conn, $getListCount); $numCountList = mysqli_num_rows($getListCountResult); $records = floor($numCountList/$countLocation) + 1; while ($rowLocation = mysqli_fetch_assoc($getLocationResult)){ echo "counter = " . $counter . "\n"; if ( $counter % 2 == 0 ) { $records = $records = floor($numCountList/$countLocation); } else { $records = $records = floor($numCountList/$countLocation) + 1; } echo $getList = "SELECT `id` FROM `lists` ORDER BY `id` DESC LIMIT $start, $records "; $getListResult = mysqli_query($conn, $getList); $countList = mysqli_num_rows($getListResult); while ($rowList = mysqli_fetch_assoc($getListResult)){ /*$chkListLocation = "SELECT count(id) AS count_list_location from `lists_locations` WHERE `list_id` = $rowList[id] AND `location_id` = $rowLocation[id] ORDER BY RAND()" ; $chkListLocationResult = mysqli_query($conn, $chkListLocation); $rowListLocation = mysqli_fetch_assoc($chkListLocationResult); $count_list_location = $rowListLocation['count_list_location'];*/ /*if ( $count_list_location == 0 ) {*/ // get sub areas $chkSubarea = "SELECT `id` from `subareas` WHERE `location_id` = $rowLocation[id] AND `is_active` = 'Y' ORDER BY RAND() LIMIT 1 " ; $chkSubareaResult = mysqli_query($conn, $chkSubarea); $count_subarea = mysqli_num_rows($chkSubareaResult); if ($count_subarea > 0) { $rowSubareaResult = mysqli_fetch_assoc($chkSubareaResult); $subarea_id = $rowSubareaResult['id']; } else { $subarea_id = 0; } // get mobile number $chkMobileNumber = "SELECT `id` from `contacts` ORDER BY RAND() LIMIT 1 " ; $chkMobileNumberResult = mysqli_query($conn, $chkMobileNumber); $count_mobile_number = mysqli_num_rows($chkMobileNumberResult); if ($count_mobile_number > 0) { $rowMobileNumberResult = mysqli_fetch_assoc($chkMobileNumberResult); $mobile_id = $rowMobileNumberResult['id']; } else { $mobile_id = 0; } $insertListLocation = "INSERT INTO `lists_locations` (`list_id`, `location_id`, `subarea_id`, `mobile_id`) VALUES ($rowList[id], $rowLocation[id], $subarea_id, $mobile_id )"; if (mysqli_query($conn, $insertListLocation)) { echo "New record is added successfully \n"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } /*}*/ } $counter++; $start = (int)$start + (int)$records; echo "Start = " . $start . "\n"; } } ?>