Jump to content

st0ked56

Members
  • Posts

    4
  • Joined

  • Last visited

st0ked56's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I am creating a jquery menu and I am having a problem displaying the correct data. It uses data from MySQL database. When I print the loops not nested the data prints out correctly. You'll see the data above the menu in the picture. Once I start nesting the loops, I can't seem to pull the right data, and I am not sure what data it is actually pulling. This is my html controller: {foreach from=$aYear item=aYear} <p>{$aYear.seasonyear}</p> {/foreach} {foreach from=$aTeam item=aTeam} <p>{$aTeam.team_id} - {$aTeam.teamname} - {if $aTeam.season == 0} Fall {elseif $aTeam.season == 1} Winter {elseif $aTeam.season == 2} Spring {elseif $aTeam.season == 3} Summer {/if}</p> {/foreach} <div id="left_block"> <div class="headerbar">Seasons</div> <div id="left_dropbar" class="left_content"> <!-- First level menu start here --> <ul id ="firstlevel"> {foreach from=$aYear item=aYear} <li><a href="#">{$aYear.seasonyear}</a> <!-- Controls Sub level 1 menu start here --> <ul class="subfirstlevel"> {foreach from=$aSeason item=aSeason} <li><a href="#"> {if $aSeason.season == 0} Fall {elseif $aSeason.season == 1} Winter {elseif $aSeason.season == 2} Spring {elseif $aSeason.season == 3} Summer {else} Error! {/if} </a> <!-- Controls Sub level 2 menu start here --> <ul> {foreach from=$aTeam item=aTeam} <li><a href="#" onclick="displaySeason('{$aTeam.team_id}')" id="menu_teamname">{$aTeam.teamname}</a></li> {/foreach} </ul> {/foreach} <!-- Controls Sub level 2 menu end here --> </li> </ul> </li> {/foreach} <!-- Controls Sub level 1 menu end here --> </ul> <!-- First level menu end here --> <button id="team-season">Add Team</button> <div id="teamadd"></div> </div> </div> Also it looks like my code is not looping all the way through. Should display to 1st level menus (2013, 2012). Second level should have 1 item (Fall) and third level should have 1 item (Raptors). Any help would be appreciated. Let me know if you need more information. Thank you, Mike
  2. Hi, I am trying to display multiple rows using ajax. I currently am able to pass the json string back to ajax and loop through the array. Right now my ajax call only displays the last record in the table instead of all records (should be 2 in this case). The variable "len" is correct with the number 2. So it loops through twice but only displays the second row. Here is my ajax code: function displaySeason(teamID) { if (teamID > 0) { $.get( "getTeamResult.php?team_id=" + teamID, function(data) { var len = data.length; console.log(len); for (var i = 0; i < len; i++){ $("#gamedateTeam").html(data[i][0]); $("#homeTeam").html(data[i][1]); $("#awayTeam").html(data[i][2]); $("#goalsforTeam").html(data[i][3]); $("#goalsagainstTeam").html(data[i][4]); $("#yellowCardsTeam").html(data[i][5]); $("#redCardsTeam").html(data[i][6]); } }, 'json' ) } } Here is my PHP and MySQL <?php require_once 'connect.php'; // Retrieve game_id number to make sure we should the right stats $teamid = mysql_real_escape_string($_GET['team_id']); $sql = "SELECT gamedate, home, away, goalsfor, goalsagainst, yellowcards, redcards FROM `game` WHERE `team_id` = $teamid"; //query $r = mysqli_query($dbc, $sql) or die (mysqli_error($dbc)); //if (mysqli_affected_rows($dbc) == 1){ $results = array(); while ($array = mysqli_fetch_array($r)){ //fetch result $results[] = $array; } echo json_encode($results); mysqli_close(); and the HTML table it should be printing both rows out to. <tr> <td id="gamedateTeam"></td> <td id="homeTeam"></td> <td id="awayTeam"></td> <td id="goalsforTeam"></td> <td id="goalsagainstTeam"></td> <td id="yellowCardsTeam"></td> <td id="redCardsTeam"></td> </tr> I have been staring at this for hours. Any help would be greatly appreciated. Thank you, Mike
  3. Figured out my problem... The needed to add more divs.
  4. Hello, I am trying to make an accordion menu using 2 MySQL queries (1 for the header and 1 for the contents) and PHP. Below is my code PHP and JQuery code, I can't seem to figure out how to make the contents stay inside the headers. Everything from the MySQL prints out in order. Any help would be greatly appreciated. PHP and MySQL <div id="left"> <div class="menu"> <?php $sqlseasons = "SELECT * FROM seasons"; $resultseasons = mysqli_query($dbc, $sqlseasons); while ($row = mysqli_fetch_array($resultseasons)){ $year_id = $row['year_id']; ?> <h3><?php echo $row['seasonyear'] ?></h3> <?php $sqlteam = "SELECT team.team_id, team.year_id, team.teamname FROM team WHERE team.year_id = '$year_id'"; $resultsteam = mysqli_query($dbc, $sqlteam); while ($sqlrow = mysqli_fetch_array($resultsteam)){ $teamid = $sqlrow['team_id']; ?> <p><a href="#" onclick="displaySeason('<?php echo $teamid ?>')" id="menu_teamname"><?php echo $sqlrow['teamname']; ?></a></p> <?php } mysqli_close(); } mysqli_close(); ?> </div> <button id="team-season">Add Team</button> JQuery $(document).ready(function(){ $('.menu').accordion(); }); Attached is a picture of a menu describing what I am trying to do. Thank you for the help, Mike
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.