jeudi 29 janvier 2015

Break If Statement in While loop without breaking the while loop PHP

Ok, So Im creating a while loop for multiple accordions in php. I marked up some php code that ALMOST works. The problem I am having is that I had to nest five different IF statements in a while loop for the five different accordions. The If statements contain the content to be in the accordion. The content is a list of songs in a particular album. What I need to happen is for the If statement containing the content for one accordion to break, but still continue with the original while statement and do this for each accordion. Here is my PHP Code.



if ($result)
{
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo '<div class="col-small-6 col-med-6 col-lg-4 albumContainer">';
echo '<img src=' . $row['Album_Art'] . 'alt="">';
echo '<div class="panel-group" id="accordion">';
echo '<div class="panel panel-default">';
echo '<div class="panel-heading">';
echo '<h2 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href=' . $row['direction'] . '>' . $row['Title'] . '</a></h2></div><div id=' . $row['destination'] . ' class="panel-collapse collapse"><div class="panel-body"> <ol>';
if($result1)
{
while ($row1 = mysqli_fetch_array($result1, MYSQLI_ASSOC))
{
echo '<li>' . $row1['Name'] . '</li>';
};
};
if($result2)
{
while($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC))
{
echo '<li>' . $row2['Name'] . '</li>';
}
};
if($result3)
{
while($row3 = mysqli_fetch_array($result3, MYSQLI_ASSOC))
{
echo '<li>' . $row3['Name'] . '</li>';
}
};
if($result4)
{
while($row4 = mysqli_fetch_array($result4, MYSQLI_ASSOC))
{
echo '<li>' . $row4['Name'] . '</li>';
}
};
if($result5)
{
while($row5 = mysqli_fetch_array($result5, MYSQLI_ASSOC))
{
echo '<li>' . $row5['Name'] . '</li>';
}
};
if($result6)
{
while($row6 = mysqli_fetch_array($result6, MYSQLI_ASSOC))
{
echo '<li>' . $row6['Name'] . '</li>';
}
};
echo '</ol>';
echo '<h3>available at:</h3><a href=' . $row['Location'] . '>iTunes</a>
<a href=' . $row['Location2'] . '>Amazon</a>
<a href=' . $row['Location3'] . '>United Interests</a></div>';
echo '</div></div></div></div>';
}
mysqli_free_result ($result);
}
else
{
echo '<p class="error">The current users could not be retrieved. We apologize for any inconvenience.</p>';
echo '<p>' . mysqli_error($dbcon) . '<br><br />Query: ' . $q . '</p>';
}
mysqli_close($dbcon);
?>


Any insights on how to make this work for me would be greatly appreciated. I cant use Jquery for the accordion because of how the code was previously structured.


Aucun commentaire:

Enregistrer un commentaire