error_reporting(0); ini_set('display_errors', 0); define('_HOST2', '45.33.72.197'); define('_USER2', 'bythesea_w'); define('_PW2', 'pneuAtyh'); define('_DB2', 'bythesea_data'); $dbh2 = mysqli_connect(_HOST2, _USER2, _PW2, _DB2); // Your code here $q = "SELECT * FROM classf_boats b, classf_pics p WHERE b.broker_id = 66 AND b.boat_id = p.boat_id AND p.web_loc != '' AND cloak = 0 AND b.property0 = 'BROKERAGE' AND categ = 'boat' ORDER BY RAND()"; $r = mysqli_query($dbh2, $q) or die(mysqli_error($dbh2)); $aListings = []; while ($rec = mysqli_fetch_object($r)) { $aListings[$rec->boat_id] = $rec; } if (is_array($aListings) && !empty($aListings)) { $key = array_rand($aListings); $value = $aListings[$key]; $c = count($aListings); foreach ($aListings as $k => $v) { $descr = $v->description; $len = strlen($descr); $textclean = 50; if ($len > $textclean) $descr = substr($descr, 0, $textclean) . ' . . . '; $web_loc = $v->web_loc; $q2 = "SELECT * FROM classf_pics WHERE broker_id = 66 AND boat_id=$k AND web_loc!='' ORDER BY pic_id ASC"; $r2 = mysqli_query($dbh2, $q2); while ($rec2 = mysqli_fetch_object($r2)) { $web_loc = $rec2->web_loc; if ($web_loc) break; } $price = $v->price; $price_type = $v->price_type; if ($price_type == 1) $price = 'SOLD'; elseif ($price_type == 2) $price = 'DEAL PENDING'; elseif (!intval($price)) $price = 'CALL FOR PRICE'; else $price = '$' . number_format($price); if (!$web_loc) $web_loc = 'images/boat-image-placeholder.jpg'; else $web_loc = str_replace("http://www.zeccomarine.com", "", $web_loc); $c--; break; // Assuming you want to break after processing the first listing } } mysqli_close($dbh2); @require('_start.php'); ?>