Logix Posted September 1, 2006 Share Posted September 1, 2006 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)) {//STARTEcho " <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!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/ Share on other sites More sharing options...
rajmohan Posted September 1, 2006 Share Posted September 1, 2006 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> <?}?> Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-83990 Share on other sites More sharing options...
wildteen88 Posted September 1, 2006 Share Posted September 1, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-83992 Share on other sites More sharing options...
tomfmason Posted September 1, 2006 Share Posted September 1, 2006 ^ Nice wildteen. That is much nicer then the simple counter that I was going to post. I will use that from now on. Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-83994 Share on other sites More sharing options...
Logix Posted September 4, 2006 Author Share Posted September 4, 2006 Thank you!!!!!!I will try it in a little bit and let you know.... Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85642 Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 just a note.. your accessing your arrays incorrectly..[code=php:0]$array['index'];[/code]not[code=php:0]$array[index];[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85664 Share on other sites More sharing options...
Logix Posted September 4, 2006 Author Share Posted September 4, 2006 I am getting Parse error: syntax error, unexpected ')', expecting ',' or ';' in /home/fighting/www/www/testdb/pfs_cei.php on line 54until 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 Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85666 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85670 Share on other sites More sharing options...
Logix Posted September 4, 2006 Author Share Posted September 4, 2006 I see how this works now.. Thank you... Its almost there - I am getting weird output - but that might be formatting... its doingNameName Name NameNameName Name Namethanks alot man - at least I can learn from this code now... Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85686 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 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 itecho ($c != 3 && $tr == false) ? " </tr>\n" : '';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85696 Share on other sites More sharing options...
Logix Posted September 4, 2006 Author Share Posted September 4, 2006 WOW!!!!I also got it to work by doing this$c++;Echo ($c % 4) == 0 ? "</tr>\n" : ''instead ofEcho ($c % 4) == 0 ? "</tr>\n" : ''$c++;but now I am going to try your new way... Thanks for everything I am learning a sh*t oad from this! Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85700 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Note I have update the code slightly as it wasnt closing the table rows correctly. Recopy the code posted above to replace the old code. Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85703 Share on other sites More sharing options...
Logix Posted September 4, 2006 Author Share Posted September 4, 2006 this worked great - thanks a lot!!!!My new problem (go figure) - is to list them the same way but up and down thenleft to right..ie currently:a b c de f g hI need to get a c e gb d f hthanks for all your help!b Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-85983 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 I've never done that before, However I believe it'll take a look of working out. I'll see if I can come up with something. Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-86040 Share on other sites More sharing options...
Logix Posted September 4, 2006 Author Share Posted September 4, 2006 yeah - I was trying to think how to do it - if its even possible.... ;D Quote Link to comment https://forums.phpfreaks.com/topic/19358-while-loop-help/#findComment-86061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.