Jump to content

While loop help


Logix

Recommended Posts

I am ready to bang my head o the wall on this..  I am doing a standard while loop with some tables.

[code]
$connect=mysql_connect("$db_Hostname","$db_UserName","$db_Password");
mysql_select_db("$db_Database",$connect);
$showpfsinst=mysql_query("SELECT * FROM Instructor WHERE Rank='CEI' ORDER BY LName ASC")or die;
while($pfsq = mysql_fetch_array($showpfsinst)) {


//START
Echo " <tr>\n";
Echo " <td align=middle><font face=Verdana size=1 color=" . $textcolor_inst . ">" . $pfsq[FName] . " " . $pfsq[LName] . "</font></a></td>\n";
Echo " <td align=middle><font face=Verdana size=1 color=" . $textcolor_inst . ">" . $pfsq[FName] . " " . $pfsq[LName] . "</font></a></td>\n";
Echo " <td align=middle><font face=Verdana size=1 color=" . $textcolor_inst . ">" . $pfsq[FName] . " " . $pfsq[LName] . "</font></a></td>\n";
Echo " <td align=middle><font face=Verdana size=1 color=" . $textcolor_inst . ">" . $pfsq[FName] . " " . $pfsq[LName] . "</font></a></td>\n";
Echo "</tr>\n";
//END
}
[/code]

This works - but displays the same record for each of the cells..  How can I change the record for each cell?  Basically I just want those 4 cells wide - each with a different record...

thank you in advance!!!!!!
Link to comment
https://forums.phpfreaks.com/topic/19358-while-loop-help/
Share on other sites

i think it will work try it
<?
while($result = @mysql_fetch_array($sel_query))
{
?>
    <tr>
      <td width="56%" colspan="2" class="nav_off3"><? print $result['sub_category'];?></td>
      <td width="22%"><a href="add_sub_category.php?id=<? print $result['id'];?>" class="nav_off1" target="_parent">Edit</a></td>
      <td width="22%"><a href="view_sub_category.php?del_id=<? print $result['id'];?>" class="nav_off1" onClick="javascript: return confirm('Are you Sure to DELETE <? print $result['sub_category'];?>');">Delete</a></td>
    </tr>
    <?
}
?>
Link to comment
https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-83990
Share on other sites

Use this instead:
[code=php:0]$c = 0;
while($pfsq = mysql_fetch_assoc($showpfsinst))
{
    echo ($c % 4) == 0) ? "<tr>\n" : '';

    echo ' <td align="middle"><font face="Verdana" size="1" color="' . $textcolor_inst . '>' . $pfsq[FName] . ' ' . $pfsq[LName] . "</font></a></td>\n";

    echo ($c % 4) == 0) ? "</tr>\n" : '';
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-83992
Share on other sites

I am getting

Parse error: syntax error, unexpected ')', expecting ',' or ';' in /home/fighting/www/www/testdb/pfs_cei.php on line 54

until I change echo ($c % 4) == 0) ? "<tr>\n" : ''; to echo ($c % 4) == 0 ? "<tr>\n" : '';
but then I just get the same results i was without the count..

First time I am working with counters in code like this....


I change my array also - didnt make a difference tho but thanks

Link to comment
https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85666
Share on other sites

I forgot to add $c++; to the end of the while loop so it wasnt counting!
[code=php:0]$c = 0;
while($pfsq = mysql_fetch_assoc($showpfsinst))
{
    // I missout the the opening ( on this line:
    echo (($c % 4) == 0) ? "<tr>\n" : '';

    echo ' <td align="middle"><font face="Verdana" size="1" color="' . $textcolor_inst . '>' . $pfsq['FName'] . ' ' . $pfsq['LName'] . "</font></a></td>\n";

    echo ($c % 4) == 0) ? "</tr>\n" : '';

    $c++;
}[/code]
Hows that now?
Link to comment
https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85670
Share on other sites

As I didnt test the code when I made it. It wasnt functioning correctly. try this new code:
[code=php:0]$c = 0;
while($pfsq = mysql_fetch_assoc($showpfsinst))
{
    echo (($c % 4) == 0) ? "  <tr>\n" : '';

    echo '    <td align="middle"><font face="Verdana" size="1" color="' . $textcolor_inst  . '">' . $pfsq['FName'] . ' ' . $pfsq['LName'] . "</font></td>\n";

    // If $c equal to 3 we reset the
    // counter and echo the closing table row tag
    if($c == 3) {
        echo "  </tr>\n";
        // reset counter to zero
        $c = 0;
        $tr = true;
    } else {
        // increment counter by 1
        $c++;
        $tr = false;
    }
}
// check that the the current table row hasn't been closed yet. If it hasn't we'll close it
echo ($c != 3 && $tr == false) ? "  </tr>\n" : '';[/code]
Link to comment
https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85696
Share on other sites

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.