I have the following code as shown below.
The code is working but the bottom part seems highly inefficient to me so I was wondering if anyone has any ideas how I can rewrite the code so that its not required to create a
baseUrl + '<?php echo $urls[0]; ?>',
for every row?
(the $urls contain only text like in this way: something-more (so no http: etc))
<?php
include("includes/connect.php");
$sql = mysql_query("SELECT url FROM urls ORDER BY listorder ASC");
$urls = array();
while ($rw = mysql_fetch_array($sql)) {
$urls[] = $rw['url'];
}
?>
<script>
var baseUrl = '/';
var mySwipe = $('#pageBody').responsiveSwipe({
edition: [
baseUrl,
baseUrl + '<?php echo $urls[0]; ?>',
baseUrl + '<?php echo $urls[1]; ?>',
baseUrl + '<?php echo $urls[2]; ?>',
baseUrl + '<?php echo $urls[3]; ?>',
baseUrl + '<?php echo $urls[4]; ?>',
baseUrl + '<?php echo $urls[5]; ?>',
baseUrl + '<?php echo $urls[6]; ?>',
baseUrl + '<?php echo $urls[7]; ?>',
baseUrl + '<?php echo $urls[8]; ?>',
baseUrl + '<?php echo $urls[9]; ?>',
baseUrl + '<?php echo $urls[10]; ?>'
],
widthGuess: 0,
emulator: window.location.hash.match(/emulator/)
});
$(document).ready(function(){
$(document).on('click', '.next', function (e) {
e.preventDefault();
mySwipe.gotoNext();
});
$(document).on('click', '.prev', function (e) {
e.preventDefault();
mySwipe.gotoPrev();
});
})
</script>
forloop?json_encode-ed. fetching an array, and passingit on to JS is easily done by writingvar someArr = <?= json_encode($urls); ?>job done