Reputation: 331
I am having a bizarre problem that I cannot figure out. It is quite possible that I just do not know something fundamental which is the cause. I really have no idea. Anyway; I have a function on a page that uses mysql to look up divisions; then it has buttons for each division; and when you click each button; a team list for each division appears within a div container. the buttons send a "div_id" value to the container. The container then uses ajax to go back to mysql and then look up the teams for that division and output information on them. This is all working. But when I try and have the php file which is called from ajax list a simple href link for each team; the links do not appear. It really seems that I cannot have href links present in the php file that is called by ajax.
I do not think I need to post all of the code for all the buttons and all that, if so please let me know; here is the script that does the ajax call on the php file:
<script>
function MyRadFunction(DivId) {
var answer = DivId;
$.ajax({
cache: false,
type: 'GET',
url: 'http://jba.gtdsites.com/gscript3_links.php',
data: 'answer=' + answer,
dataType: 'html',
success: function(response) {
$('#ajax_content').html(response);
}
});
}
</script>
and here is the php file that is called:
<?php
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'
) {
// AJAX request
$answer = $_GET['answer'];
$div_id=$answer;
/* Connect to a mysql database using driver invocation */
$dsn = 'mysql:dbname=gtdtables;host=gtdtables.db.1567753.hostedresource.com';
$user = 'username';
$password = 'password';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = "SELECT * FROM teams WHERE div_id=$div_id";
foreach ($dbh->query($sql) as $resultsg1)
{
$team_id=$resultsg1[team_id];
$team_name=$resultsg1[team_name];
echo "<a href='/team-schedules/?gc_start=2&team_id=<?php echo $team_id; ?>'><?php echo $team_name; ?></a><br/>";
echo $team_name . "<br/>";
echo $team_id . "<br/>";
?>
Teams Page not link
<a href="/final-exam-1-intro/">Final Exam 1</a>
<a href="http://jba.gtdsites.com/team-schedules/?gc_start=2&team_id=<?php echo $team_id; ?>"><?php echo $team_name; ?></a><br/>
<?php
}
}
?>
I echoes the team name and team id just fine; and where i just have it print text that works as well; but all of the html hyperlink stuff just does not appear; I tried a few different ways. Can anyone tell me why this is happening?
Upvotes: 1
Views: 480
Reputation: 41885
Your error is kinda funny, but here it is, upon examining the site, on the network tab the markup built from PHP is rendered correctly. But the thing is:
The CSS is the problem:
a { color: #fff; }
Your text color on the links are white. Therefore its not seen, but its there, just change it accordingly.
a { color: #000; } /** or which color you want **/
And in your PHP, properly concatenate the values:
echo "<a href='/team-schedules/?gc_start=2&team_id=".$team_id."'>".$team_name."</a><br/>";
Important note: Don't just directly use variables inside your statements, use prepared statements to produce safer queries. Here is a tutorial for that.
Upvotes: 3