Jump to content

Recommended Posts

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

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.