Jump to content

[SOLVED] Where's the error in this code?


tfburges

Recommended Posts

This code returns a form name and the timestamp of when the data was entered into the form.  For some reason, when I load the page, it gets stuck in a loop until timeout and fills the pull down menu with the same value over and over.  I must be too tired to see what's wrong...

 

 

		 <td class=fstyle width=150 align=center valign=middle>
	  <form name='nav'>
	   <select name='SelectURL' onChange='document.location.href=document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value'>
	    <option value=''>                                          
";
$qfnv = mysql_query("SELECT DISTINCT `formx_name_v` FROM `formz`", $link) or die ('MYSQL error: ' . mysql_error());
$dfnv = mysql_fetch_array($qfnv);
while ( $fnv = $dfnv['formx_name_v'] ) {
  $qfn = mysql_query("SELECT `formx_name` FROM `formz` WHERE `formx_name_v` = '$fnv'", $link) or die ('MYSQL error: ' . mysql_error());
  $dfn = mysql_fetch_array($qfn);
  $fn = $dfn['formx_name'];
  if ( $fnv = $formx_name_v ) {
   echo "   <option value='report_select.php?fnvs=",$fnv,"&did=",$did,"' selected>",$fn;
  } else {
   echo "   <option value='report_select.php?fnvs=",$fnv,"&did=",$did,"'>",$fn;
  }
}
echo "
	   </select>
          </form>
	 </td>
	 <td class=fstyle width=150 align=center valign=middle>
          <form name=form method=post action='report.php?fnvs=",$formx_name_v,"&rid=",$rid,"'>
	   <select name=rid>
	    <option value=''>                                          
";
$qid = mysql_query("SELECT `id` FROM `$formx_name_v`", $link) or die ('MYSQL error: ' . mysql_error());
$did = mysql_fetch_array($qid);
while ( $rid = $did['id'] ) {
  $qts = mysql_query("SELECT `timestamp` FROM `$formx_name_v`", $link) or die ('MYSQL error: ' . mysql_error());
  $dts = mysql_fetch_array($qts);
  $ts = $dts['timestamp'];
  if ( $rid = $did ) {
   echo "   <option value='",$rid,"' selected>",$ts;
  } else {
   echo "   <option value='",$rid,"'>",$ts;
  }
}
echo "
	   </select>
	 </td>

Link to comment
Share on other sites

The problem is that you're while statement assigns one variable to another. There's no comparison going on. Since it's always able to assign, the loop is always true.

 

Basic structure of a while loop:

 

while($row = mysql_fetch_array($result)){
    $var = $row['var'];
    echo $var.'<br />';
}

 

On a site note, you should really consider naming your variables something a bit more descriptive.

Link to comment
Share on other sites

WOW......

 

>:( >:(>:( >:(>:( >:(>:(

 

:-\

 

I've done hundreds of while loops.  I don't know how I screwed that up and managed to overlook it.  That's the first time that's happened.

 

 

Thanks...

 

 

:(

 

I really hate this time of day.

 

 

Also, my variable names are abbreviations.  I don't like long names.

Link to comment
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.