dflow Posted February 12, 2009 Share Posted February 12, 2009 i have this record set: RsCities: $colname_RsCities = "-1"; if (isset($_GET['CountryID'])) { $colname_RsCities = $_GET['CountryID']; } mysql_select_db($database_international, $international); $query_RsCities = sprintf("SELECT * FROM city_list WHERE CountryID = %s ORDER BY CityName ASC", GetSQLValueString($colname_RsCities, "text")); $RsCities = mysql_query($query_RsCities, $international) or die(mysql_error()); $row_RsCities = mysql_fetch_assoc($RsCities); $totalRows_RsCities = mysql_num_rows($RsCities); and the loop needs to generate all Cityies with the same countryID <?php $RsCities_endRow = 0; $RsCities_columns = 5; // number of columns $RsCities_hloopRow1 = 0; // first row flag do { if($RsCities_endRow == 0 && $RsCities_hloopRow1++ != 0) echo "<tr>"; ?> <td><a href="http://mysite.com/city_hotels.php?CityID=<?php echo $row_RsCities['CityID']; ?>" class="style1">HOTELS IN<?php echo $row_RsCities['CityName']; ?></a></td> <?php $RsCities_endRow++; if($RsCities_endRow >= $RsCities_columns) { ?> </tr> <?php $RsCities_endRow = 0; } } while ($row_RsCities = mysql_fetch_assoc($RsCities)); if($RsCities_endRow != 0) { while ($RsCities_endRow < $RsCities_columns) { echo("<td> </td>"); $RsCities_endRow++; } echo("</tr>"); }?> no error just no result Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/ Share on other sites More sharing options...
steveh62 Posted February 12, 2009 Share Posted February 12, 2009 try just using the php variable alone for the countryID <?php $colname_RsCities = "-1"; if (isset($_GET['CountryID'])) { $colname_RsCities = $_GET['CountryID']; } mysql_select_db($database_international, $international); $query_RsCities = sprintf("SELECT * FROM city_list WHERE CountryID = $colname_RsCities ORDER BY CityName ASC"); $RsCities = mysql_query($query_RsCities, $international) or die(mysql_error()); $row_RsCities = mysql_fetch_assoc($RsCities); $totalRows_RsCities = mysql_num_rows($RsCities); ?> Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/#findComment-760524 Share on other sites More sharing options...
Brian W Posted February 12, 2009 Share Posted February 12, 2009 Try changing: if($RsCities_endRow == 0 && $RsCities_hloopRow1++ != 0) echo "<tr>"; to> if($RsCities_endRow == 0) echo "<tr>"; ++ incriment doesn't change the value for the time that you have ++, but all uses after that will be 1 higher. <?php $i=0; echo $i++."<br>"; echo $i; ?> will echo 0 1 Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/#findComment-760525 Share on other sites More sharing options...
dflow Posted February 12, 2009 Author Share Posted February 12, 2009 unfortunately nada Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/#findComment-760531 Share on other sites More sharing options...
premiso Posted February 12, 2009 Share Posted February 12, 2009 Ok, using a do while you would have to pull the first result. Instead just use a while. No reason to do the do while in this scenario: <?php $RsCities_endRow = 0; $RsCities_columns = 5; // number of columns $RsCities_hloopRow1 = 0; // first row flag while ($row_RsCities = mysql_fetch_assoc($RsCities)) { if($RsCities_endRow == 0 && $RsCities_hloopRow1++ != 0) echo "<tr>"; ?> <td><a href="http://mysite.com/city_hotels.php?CityID=<?php echo $row_RsCities['CityID']; ?>" class="style1">HOTELS IN<?php echo $row_RsCities['CityName']; ?></a></td> <?php $RsCities_endRow++; if($RsCities_endRow >= $RsCities_columns) { ?> </tr> <?php $RsCities_endRow = 0; } } if($RsCities_endRow != 0) { while ($RsCities_endRow < $RsCities_columns) { echo("<td> </td>"); $RsCities_endRow++; } echo("</tr>"); }?> Try that and see if it works. Chances are it was throwing an error. Part 2, I do not see the query statement in that code. I assume you omitted it. That is fine, if you did not omit it, you need it . Similar to what steve wrote, except remove the last 2 lines and then put your original code. Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/#findComment-760534 Share on other sites More sharing options...
Brian W Posted February 12, 2009 Share Posted February 12, 2009 Add this before your loop somewhere if($totalRows_RsCities <= 0){ die('Your problem is that you aren't getting results'); } did you write you loop or did you get a plugin for dreamweaver? Also, what level of error reporting do you have on? If you don't know, add this to the top of your page: error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/#findComment-760538 Share on other sites More sharing options...
dflow Posted February 12, 2009 Author Share Posted February 12, 2009 thanks it works now Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/#findComment-760555 Share on other sites More sharing options...
Brian W Posted February 12, 2009 Share Posted February 12, 2009 What fixed it? Link to comment https://forums.phpfreaks.com/topic/144930-loop-not-working/#findComment-760562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.