Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown is locking up page???

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
After getting the results back from the query, I count the rows and put into $rowcount, echo out and return say three records. I then want to populate a dropdown with the results. Just isn't happening for some reason. Out of the database is returns date format like 2005-03-07, I want the dropdown to reflect 03/07/2005. Can someone see what I have incorrect? Thanks


$myquery4 = "SELECT direct_deposit.checkdate AS TRANSACTION
FROM
human_resources.direct_deposit
WHERE
direct_deposit.ssn = '$ss_num'
ORDER BY direct_deposit.checkdate DESC";
$myresult4 = mysql_query ($myquery4, $link);
if (!$myresult4)
echo "Direct Deposit Query Failed.";
$rowcount = mysql_num_rows($myresult4);


{
if ($rowcount > 0){
echo "<select name='directdeposit'>\n";
while ($ddrows = mysql_fetch_row($myresult4)) {
$ddperend = mysql_result ($myresult4,'TRANSACTION');
$ddperend1 = explode("-", $ddperend);
$mod_ddperend = $ddperend1[1] . "/" . $ddperend1[2] . "/" . $ddperend1[0];
$ddout = $mod_ddperend;
echo '<option value="'.$ddout.'">'.$ddout.'</option>'."\n";
}
echo "</select>\n";
}
}
 
while condition was always TRUE... Endless loop... The following is the fix...

<?
if ($s_count > 0)
{
if ($rowcount > 0){
echo "<select name='directdeposit'>\n";
for($i=0;$i<$rowcount;$i++){
$ddperend = mysql_result ($myresult4,'checkdate');
$ddperend1 = explode("-", $ddperend);
$mod_ddperend = $ddperend1[1] . "/" . $ddperend1[2] . "/" . $ddperend1[0];
$ddout = $mod_ddperend;
echo '<option value="'.$ddout.'">'.$ddout.'</option>'."\n";
}
echo "</select>\n";
}
}
?>
 
I think you have to simplify your code:
Code:
  if ($rowcount > 0){
    echo '<select name="directdeposit">'."\n";
    while ($ddrows = mysql_fetch_assoc($myresult4)) {
        $td = date("m/d/Y",strtotime($ddrows['TRANSACTION']));
        echo '<option value="' . $td . '">' . $td . '</option>' . "\n"; }
    echo '</select>'."\n";
  }

I'm not sure why you were exploding the date from MySQL and then putting it back together, instead of using strtotime and date.

Ken
 
Apollo6: No the while condition is NOT always true. It will return FALSE when there are no more rows to return.

Here's another way to code it which will eliminate the need to test the number of rows:
Code:
$tmp = array();
while ($ddrows = mysql_fetch_assoc($myresult4)) {
        $td = date("m/d/Y",strtotime($ddrows['TRANSACTION']));
        $tmp[] = '<option value="' . $td . '">' . $td . '</option>'; }
if (!is_empty($tmp)) {
   echo '<select  name="directdeposit">'."\n";
   echo implode("\n",$tmp);
   echo '</select>'."\n";
}

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top