Jump to content

can I put several whiles inside of whiles?


dsaba

Recommended Posts

Sure it'll work--if you code it right. 

 

Try posting your code.

 

In the meantime, I'll give you an example.

 

$test = 1;
while ($test){
    echo "Line" . $test . ":  ";
    $c = 1;
    while($c){
       echo $c . "-";
       if ($c == 10){
          $c = false;
          echo "<br>";
       }
    }
    if ($test == 10){$test = 0;} 
}

 

I haven't tested this to see if there are any typos (hopefully not) but you should be able to get the gist of it.

 

It should output the following:

 

Line1:  1-2-3-4-5-6-7-8-9-10-

Line2:  1-2-3-4-5-6-7-8-9-10-

Line3:  1-2-3-4-5-6-7-8-9-10-

Line4:  1-2-3-4-5-6-7-8-9-10-

Line5:  1-2-3-4-5-6-7-8-9-10-

Line6:  1-2-3-4-5-6-7-8-9-10-

Line7:  1-2-3-4-5-6-7-8-9-10-

Line8:  1-2-3-4-5-6-7-8-9-10-

Line9:  1-2-3-4-5-6-7-8-9-10-

Line10:  1-2-3-4-5-6-7-8-9-10-

ok what i'm trying to do is this:

 

     while ($searchqueryrow = mysql_fetch_array($searchquery)) {
$filelink = formatSearch($searchqueryrow['filelink'], $trimmedsearchterm);
$filetotalmirrors = $searchqueryrow['filetotalmirrors'];
$filegeneraltype = $searchqueryrow['filegeneraltype_en'];
$filespecifictype = $searchqueryrow['filespecifictype_en'];
$filegeneraltypekey = $searchqueryrow['filegeneraltype_en'];
$filespecifictypekey = $searchqueryrow['filespecifictype_en'];
$filedateadded = $searchqueryrow['filedateadded'];
$filesubmitter = $searchqueryrow['filesubmitter'];
$fileid = $searchqueryrow['fileid'];

$keywordtablequery = mysql_query("SELECT * FROM keywords WHERE keyword='$keyword'");
//--------------------------------------------------------------begin keyword table shit
while ($keywordtablerow = mysql_fetch_array($keywordtablequery))
{
$keywordtablequery = mysql_query("SELECT * FROM keywords WHERE keyword='$keyword'");
$keywordtablerow = mysql_fetch_array($keywordtablequery);
$keywordfileid = $keywordtablerow['keywordfileid'];
$matchedkeyword = $keywordtablerow['keyword'];
echo $matchedkeyword;
$keywordip = $keywordtablerow['keywordip'];
$keywordentryid = $keywordtablerow['keywordentryid'];
$keywordlink = <<<KEYWORDLINK
<a href="searchresults.php?searchterm=$keyword">$keyword</a>
KEYWORDLINK;


if ($keywordfileid == $fileid && $keywordip == $userip && $matchedkeyword == $keyword)
{
$updatekeywordtablequery = mysql_query("UPDATE `keywords` SET `keywordtimestamp`='$datetime', `keywordip`='$userip', `keyworduserid`='$userid' WHERE `keywordentryid`='$keywordentryid'");
echo "KEYWORD TABLE WAS UPDATED ONLY should be no new ids if same search";
}
else
{
$insertkeywordtablequery = "INSERT INTO `keywords` ( `keywordfileid`, `keyword`, `keywordspecifictype`, `keywordgeneraltype`, `keywordip`, `keyworduserid`, `keywordtimestamp`, `keywordfilelink`, `keywordlink` )
VALUES ( '$fileid','$keyword','$filespecifictypekey','$filegeneraltypekey','$userip','$userid','$datetime', '$filelink', '$keywordlink' )";
$runinsertkeywordtablequery = mysql_query($insertkeywordtablequery);
echo "KEYWORD TABLE WAS INSERTED ONLY";
}
}

//-----------------------------------------------------------------------------------------------end keyword table shit

$searchtableinside = <<<EOT
        <tr>
          <td class="nombre">$filelink</td>
          <td class="nombre">$filetotalmirrors</td>
          <td class="fecha">$filedateadded</td>
          <td class="descargas">$filespecifictype</td>
          <td class="descargas">$filesubmitter</td>
        </tr>
EOT;
echo $searchtableinside;
}
//end while function and display searchtableinside
     break;
}
//end switch statement

 

thats the real code i'm using

 

here is the watered down version:

 

while ($searchqueryrow = mysql_fetch_array($searchquery))
{
i know $searchqueryrow will have 5 rows so all this shit should repeat 5 times

while ($keywordtablerow = mysql_fetch_array($keywordtablequery))
{
I know $keywordtablerow has 2 rows so this should repeat 10 times

}
}

the result however is $searchqueryrow shit does loop 5 times, but $keywordtablerow doesn't loop at all

the real code i'm using is pasted in the first code post

You are duplicating the query inside the loop that is processing the query

 

$keywordtablequery = mysql_query("SELECT * FROM keywords WHERE keyword='$keyword'");

//--------------------------------------------------------------begin keyword table shit

while ($keywordtablerow = mysql_fetch_array($keywordtablequery))

{

$keywordtablequery = mysql_query("SELECT * FROM keywords WHERE keyword='$keyword'");

$keywordtablerow = mysql_fetch_array($keywordtablequery);

$keywordfileid = $keywordtablerow['keywordfileid'];

...

...

}

Archived

This topic is now archived and is closed to further replies.

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