Xtremer360 Posted September 21, 2008 Share Posted September 21, 2008 I have a while statement that has two loops but don't want them to be intertwined and need someones help telling me how to separate the two. Everything below belltime should be in it's own loop. But working with the curly braces and what not and I even tried sticking in an else i couldn't get the loops correct. <?php echo "<body bgcolor=\"black\" text=\"white\" link=\"red\" vlink=\"red\">"; require ('database.php'); print '<center><img src=/images/" . $row["showimage"] " height="125" width="500" border="1"></center>'; //Define the query $query = "SELECT *, DATE_FORMAT(`date`, '%M %e, %Y') AS date FROM shows, matches WHERE matches.showid = shows.id"; if ($r = mysql_query ($query)){ // Run the query. // Retrieve and print every record while ($row = mysql_fetch_array ($r)){ print '<center>Date: '.$row['date'].'</center>'; print '<center>Location: '.$row['location'].'</center>'; print '<center>Bell Time: '.$row['belltime'].'</center><br><br>'; print '<center>'.$row['matchtype'].'</center>'; print '<center>'.$row['vs1'].' vs. '.$row['vs2'].'</center>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/ Share on other sites More sharing options...
pocobueno1388 Posted September 21, 2008 Share Posted September 21, 2008 I only see one loop...? Exactly how do you want them separated? Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647027 Share on other sites More sharing options...
Andy-H Posted September 21, 2008 Share Posted September 21, 2008 <?php echo "<body bgcolor=\"black\" text=\"white\" link=\"red\" vlink=\"red\">"; require ('database.php'); print '<center><img src=/images/" . $row["showimage"] " height="125" width="500" border="1"></center>'; //Define the query $query = "SELECT *, DATE_FORMAT(`date`, '%M %e, %Y') AS date FROM shows, matches WHERE matches.showid = shows.id"; $r = mysql_query($query); $n = mysql_num_rows($r); if ($n == 0){ //output for no records... echo '</body></html>'; exit(); } // Retrieve and print every record while ($row = mysql_fetch_array ($r)){ print '<center>Date: '.$row['date'].'</center>'; print '<center>Location: '.$row['location'].'</center>'; print '<center>Bell Time: '.$row['belltime'].'</center><br><br>'; print '<center>'.$row['matchtype'].'</center>'; print '<center>'.$row['vs1'].' vs. '.$row['vs2'].'</center>'; } ?> ??? Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647029 Share on other sites More sharing options...
Xtremer360 Posted September 21, 2008 Author Share Posted September 21, 2008 I'm sorry it is one loop however everything below belltime should be in it's own loop Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647030 Share on other sites More sharing options...
pocobueno1388 Posted September 21, 2008 Share Posted September 21, 2008 I'm sorry it is one loop however everything below belltime should be in it's own loop Why do you need it as a separate loop? You need to explain exactly what your trying to do. Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647031 Share on other sites More sharing options...
Xtremer360 Posted September 21, 2008 Author Share Posted September 21, 2008 I just realized that the only loop should be the matchtype and vs1 and vs2 but when I take the date,location,and belltime out of the loop it doesn't post the values for the date,location, and belltime. Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647032 Share on other sites More sharing options...
Andy-H Posted September 21, 2008 Share Posted September 21, 2008 <?php echo "<body bgcolor=\"black\" text=\"white\" link=\"red\" vlink=\"red\">"; require ('database.php'); print '<center><img src=/images/" . $row["showimage"] " height="125" width="500" border="1"></center>'; //Define the query $query = "SELECT *, DATE_FORMAT(`date`, '%M %e, %Y') AS date FROM matches"; $r = mysql_query($query); // Retrieve and print every record while ($row = mysql_fetch_array ($r)){ print '<center>Date: '.$row['date'].'</center>'; print '<center>Location: '.$row['location'].'</center>'; print '<center>Bell Time: '.$row['belltime'].'</center><br><br>'; $q = "SELECT * FROM shows WHERE id = '{$row['showid']}' ORDER BY id DESC"; $res = mysql_query($q); while ($arr = mysql_fetch_array($res)){ print '<center>'.$arr['matchtype'].'</center>'; print '<center>'.$arr['vs1'].' vs. '.$arr['vs2'].'</center>'; }} ?> Like that ??? Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647033 Share on other sites More sharing options...
Xtremer360 Posted September 21, 2008 Author Share Posted September 21, 2008 Well when I did that the message came up: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/y/a/n/yankeefaninkc/html/upcomingshow3.php on line 13 Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647035 Share on other sites More sharing options...
Andy-H Posted September 21, 2008 Share Posted September 21, 2008 add or die(mysql_error()); to the $res query Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647036 Share on other sites More sharing options...
Xtremer360 Posted September 21, 2008 Author Share Posted September 21, 2008 Same thing Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647037 Share on other sites More sharing options...
pocobueno1388 Posted September 21, 2008 Share Posted September 21, 2008 You still haven't made it clear to what you want. Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647041 Share on other sites More sharing options...
Andy-H Posted September 21, 2008 Share Posted September 21, 2008 then its the $r query, how is your database laid out? Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647042 Share on other sites More sharing options...
Xtremer360 Posted September 21, 2008 Author Share Posted September 21, 2008 After realizing what I said I take all of that back. What I should do is simply just have matchtype and vs1 and vs2 part as the only thing in the loop. But when I took the date,location,belltime out of the loop it wouldn't display those values. Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647044 Share on other sites More sharing options...
Xtremer360 Posted September 21, 2008 Author Share Posted September 21, 2008 Everybody understand what I'm trying to do now?+ Link to comment https://forums.phpfreaks.com/topic/125182-multiple-loops-need-separated/#findComment-647066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.