0byt3m1n1
Path:
/
var
/
www
/
listcrawler.app
/
public_html
/
cron
/
[
Home
]
File: cron-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) { while ($rowLocation = mysqli_fetch_assoc($getLocationResult)){ $getList = "SELECT `id` FROM `lists` WHERE `is_active` = 'Y' ORDER BY RAND() LIMIT " . rand(65, 95); $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<br>"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } /*}*/ } } } ?>