-
-
Save BradEstey/410414e1b8c81012242e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var horoscopes = document.getElementById('horoscopes-object'); | |
horoscopes = JSON.parse(horoscopes.innerHTML); | |
alert(horoscopes.virgo[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('php_includes/db_conx.php'); | |
$horoscopes = []; | |
$days_of_the_week = [ | |
'Sunday', | |
'Monday', | |
'Tuesday', | |
'Wednesday', | |
'Thursday', | |
'Friday', | |
'Saturday' | |
]; | |
$sql = 'SELECT | |
`sun_zodiac`, | |
`mon_zodiac`, | |
`tue_zodiac`, | |
`wed_zodiac`, | |
`thur_zodiac`, | |
`fri_zodiac`, | |
`sat_zodiac`, | |
`zodiac_sign` | |
FROM `horoscope` | |
WHERE `zodiac_sign` = "Taurus" | |
OR `zodiac_sign` = "Virgo" | |
OR `zodiac_sign` = "Capricorn" | |
LIMIT 0, 30'; | |
$result = mysqli_query($db_conx, $sql); | |
while ($row = mysqli_fetch_array($result)) { | |
// Take the last item (zodiac_sign) from the $row array. | |
$zodiac_sign = strtolower(array_pop($row)); | |
// Add column values to array. Reset array keys. | |
$horoscopes[$zodiac_sign] = array_values($row); | |
} | |
?> | |
<?php foreach ($days_of_the_week as $key => $day) : ?> | |
<h1><?php echo $day; ?> Horoscopes</h1> | |
<?php foreach ($horoscopes as $zodiac_sign => $horoscope) : ?> | |
<p><strong><?php echo $zodiac_sign; ?>:</strong> <?php echo $horoscope[$key]; ?></p> | |
<?php endforeach; | |
endforeach; ?> | |
<script type="application/json" id="horoscopes-object"> | |
<?php echo json_encode($horoscopes); ?> | |
</script> | |
<script src="/horoscopes.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment