need help sending $_GET info through ajax/jquery.. i think..
Hello,
So, bear with me cause I've only been doing this a month. I've been trying to create a site for a comic I'm working on and I already have a register/signing framework, a forum framework, a comic display framework.
Now I'm working on fleshing out a link that allows any viewer (registered or not) to view the characters in a horizontal carousel and when they click on them, have a div pop down that has information correlating to the image they pick.
I set up two databases, one to handle to photo params and the other to handle the info about the character. The img database has 3 fields: image_id (AI), hero_id (INT), and ext(VAR 4). The other has hero_id(AI), name, height, weight, etc..
Then in php I did this:
- function heroes_id() {
$hero_id = array();
$heroes_query = mysql_query("
SELECT *
FROM `heroes`
JOIN `heroimg`
ON `heroes`.`hero_id` = `heroimg`.`hero_id`
WHERE `heroes`.`hero_id` = `heroimg`.`hero_id`
");
while ($hero_id_row = mysql_fetch_assoc($heroes_query)) {
$hero_id[] = array(
'hero_id' => $hero_id_row['hero_id'],
);
}
return $hero_id;
}
And this:
- function get_hero_images($hero_id) {
$hero_id = (int)$hero_id;
$images = array();
$image_query = mysql_query("SELECT *
FROM `heroimg`");
while ($images_row = mysql_fetch_assoc($image_query)) {
$images[] = array(
'id' => $images_row['image_id'],
'ext' => $images_row['ext'],
'hero_id' => $images_row['hero_id'],
);
}
return $images;
}
Then I did this in the php file I want the viewer to see:
- <?php
include 'lib/innit.php';
include 'views/template/header.php';
?>
<h4> The Heroes </h4>
- <div id="charcaroselbkgnd">
<div class="navbtnl"></div>
<?php
$hero_id = heroes_id();
$images = get_hero_images($hero_id);
if (empty($images)) {
echo 'There are no images in this file.';
} else {
foreach ($images as $image) {
echo '<img class="char" src="heroes/', $image['id'], '.', $image['ext'], '"
title ="',$image['hero_id'], '"
alt="image" >
';
}
}
echo '<br><br>';
print_r($hero_id);
echo '<br><br>';
print_r ($images);
?>
<div class="navbtnr"></div>
</div>
<hr class="blw_crsl">
<h4 class="blw_crsl"> Bio </h4>
<div id="bio_area"></div>
- <?php include 'views/template/footer.php' ?>
Then this is.. err, the lastest version of the jqeury/ajax function I have in my func.js file:
- $('.char').click(function() {
var hero_id = $(this).attr('title');
$('.blw_crsl').show(500, function() {
$.get('characterinfo.php', { 'hero_id': 'hero_id' }, function(data) {
$('#bio_area').hide().html(data).fadeIn('normal');
});
});
});
And this is the page I made to process the jquery/ajax and provide the callback.. if I'm saying that right >.>;
- <?php
include 'lib/innit.php';
if(admin_check() === true) {
echo '<a href="edit_hero.php'">Edit / </a>';
echo '<a href="upload_hero_img.php'"> Add Hero </a><br>';
} else {
}
if(isset($_GET['hero_id']) === true && empty($_GET['hero_id']) === false) {
$hero_id = $_GET['hero_id'];
$hero_data = hero_data($hero_id, 'name', 'height', 'weight', 'eyes', 'hair', 'pob', 'bio');
print_r ($hero_data);
echo '<br>';
print_r ($hero_id);
} else {
echo 'Not getting hero id';
}
?>
<p></p>
<?php
?>
<div class="bio_content">
<b>Name:</b> <?php echo $hero_data['name']; ?> <br>
<b>Height:</b> <?php echo $hero_data['height']; ?> <br>
<b>Weight:</b> <?php echo $hero_data['weight']; ?> <br>
<b>Eyes:</b> <?php echo $hero_data['eyes']; ?> <br>
<b>Hair:</b> <?php echo $hero_data['hair']; ?> <br>
<b>Place of Birth:</b> <?php echo $hero_data['pob']; ?> <br> <br>
<b>Bio:</b> <br>
<?php echo $hero_data['bio']; ?> <br>
</div>
<div class="bio_pic">
<div>
The only thing that doesn't seem to be happening is the transference of the hero_id value. The print_r for hero_id in the code right above comes up as plain text which I think means it wasn't set. I've spent a couple nights up now trying to figure out why that is.
Aside from that, everything seems to work. All my other print_r functions show me lovely feedback saying all my information is present. When I hover over my photo on the php page it shows the hero_id = 1 and when I enter $hero_id = 1; into the code right above instead of $hero_id=$_GET['hero_id']; it displays the character info corresponding to hero_id equaling 1.
Help??