We have a bunch of data in a MySQL database which call by using this phpcode:
$query = "SELECT * FROM `dmt_objects` WHERE PipelineAndWorkflow = 'RWP WF Ready for 4Sprint' ORDER BY `Team` DESC ;"; $select_projects = mysql_query($query); $project_array = mysql_fetch_array($select_projects); $json_project_array = json_encode($project_array);
However, we would no like to create one div for each team. If its ten teams we want to creat ten divs. We tried something like this in our HTML:
<script type="text/javascript"> var project_array = $json_project_array; number_of_teams = project_array.length; for(var i = 0; i < number_of_teams; i++){ var iDiv = document.createElement('div'); iDiv.className = 'project_array['Team']'; } </script>
However, it don’t seam to work, even if put document.write(i); in the for loop instead of trying to creat a div.
Advertisement
Answer
I believe this is the code that will give you the output you desire…
$query = "SELECT * FROM `dmt_objects` WHERE PipelineAndWorkflow = 'RWP WF Ready for 4Sprint' ORDER BY `Team` DESC ;"; $select_projects = mysql_query($query); if (mysql_num_rows($select_projects) > 0) { while($row = mysql_fetch_assoc($select_projects)) { echo '<div>'.$row['Team'].'</div>'; } }
Also, do yourself a favor and change your code to pdo_mysql
. mysql
has been deprecated and will soon be removed. When this happens your code will stop functioning completely.
Reference