I am new to PHP and I am trying to print out 5 pictures to which the references are stored inside a string, separated by new line.
Here's what I have so far :
function displayTeam($heroes){
$herolist = array();
$conn = odbc_connect('Dotalyzer', '', '');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
$sql = "SELECT * FROM HeroStats ORDER BY Heroname";
$rs = odbc_exec($conn, $sql);
if (!$rs) {
exit("Error in SQL");
}
foreach(preg_split("/((\r?\n)|(\r\n?))/", $heroes) as $line){
while (odbc_fetch_row($rs)) {
$heroname = odbc_result($rs, "HeroName");
if ($line == $heroname) {
$heroimage = odbc_result($rs, "Portrait");
$herolist[] = $heroimage . ".png";
}
}
}
odbc_close($conn);
echo " <div class='heroimage_wrapper'>";
for ($i = 0; $i < 5; $i++) {
echo " <img src='Hero icons/$herolist[$i]' class='heroimage'>";
}
echo " </div>";
}
I want to print each picture from the array, the references are stored in an Access database.
I am calling the function which generates my $heroes string using:
$(document).ready(function(){
$('.button').click(function(){
var clickBtnValue = $(this).val();
var id = $(this).attr('data-unique-id');
var ajaxurl = 'ajax/ajax',
data = {
'action': clickBtnValue,
'id': id
};
console.log(clickBtnValue);
$.post(ajaxurl, data, function (response) {
// Response div goes here.
alert(response.replace('\\n', '\n'));
});
});
});
$heroesstring and then it prints out some HTML code followed byUndefined offsetfrom 1 to 4 , for theimg src