Defibber Posted January 12, 2008 Share Posted January 12, 2008 Hello, I am kind of new to PHP and this site. From what I have seen I have come to the right place. I have got this little problem but I just can't quite figure it out. I have been building a website for my Fire Department using PHP with MySql. I created a table consisting of files that can be downloaded from throughout the website. I wanted to create a page that Myself or any of the other web admins(I don't think I am going to get any volunteers on this one), can look at all of the Links grouped together by type. I started our with a for loop that identifies the link type, then it is supposed to populate all of the links that are in that type then move on to the next type and go from there. For some reason the Page starts out right but it only lists one Link, the the next one lists two, next three ........... And it puts links in groups when there is nothing of that type (sorry if that is confusing) Here is the code, if I leave anything that might pose a security risk please let me know. Here is the link that shows the results of the page, I am taking off the authorization checks for awhile. http://www.kearneyfire.org/web_content/dwnld_view_all.php for ($desig = "01"; $desig <= "13" ; $desig++) { $sql = "SELECT * FROM downloads WHERE type = '$desig' ORDER BY art_date DESC"; $result = @mysql_query($sql, $###########) or die(mysql_error()); $num = mysql_num_rows($result); if ($num == 0){ continue; } while ($row = mysql_fetch_array($result)) { $type = $row['type']; $path = stripslashes($row['path']); $filename = stripslashes($row['filename']); $anchor = stripslashes($row['anchor']); $descript = stripslashes($row['descript']); $grp = stripslashes($row['grp']); $art_date = $row['art_date']; $dwnld_date = $row['dwnld_date']; $status = $row['status']; $grp_links .= "<dt><a href=\"http://kearneyfire.org/#########/$path/$filename\">$anchor</a> <strong>$status</strong></dt> <dd>$descript <em>Article Date: $art_date, Group: $grp, Filename: $filename</em></dd>"; switch ($desig) { case 01: $type = "Board Meeting Agenda"; break; case 02: $type = "Board Meeting Minutes (W/O Chief's Report)"; break; case 03: $type = "Board Meeting Minutes (W/ Chief's Report)"; break; case 04: $type = "Officer's Minutes"; break; case 05: $type = "Public Forms"; break; case 06: $type = "Internal Forms"; break; case 07: $type = "Job Opening Related"; break; case 08: $type = "Public Notices"; break; case 09: $type = "Public Information and Handouts"; break; case 10: $type = "Programs"; break; case 11: $type = "Public Miscellaneous"; break; case 12: $type = "Internal Miscellaneous"; break; case 13: $type = "Internal Information Handouts"; break; default: $type = "Type not Defined"; break; } $grouped_output .= " <tr> <td class=\"td_title\"> $type </td> </tr> <tr> <td> <dl> $grp_links </dl> </td> </tr>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/ Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 You set $desig as a string up top with "01" but then check the case with a INT with 01 Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-437117 Share on other sites More sharing options...
Defibber Posted January 12, 2008 Author Share Posted January 12, 2008 Like this? for ($i = 01; $i <= 13 ; $i++) { $i = (int)$desig; Or am I way off? Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-437120 Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 No. Just leave out quotes in numbers. for ($desig = 1; $desig <= 13 ; $desig++) { $sql = "SELECT * FROM downloads WHERE type = '$desig' ORDER BY art_date DESC"; $result = @mysql_query($sql, $###########) or die(mysql_error()); $num = mysql_num_rows($result); if ($num == 0){ continue; } while ($row = mysql_fetch_array($result)) { $type = $row['type']; $path = stripslashes($row['path']); $filename = stripslashes($row['filename']); $anchor = stripslashes($row['anchor']); $descript = stripslashes($row['descript']); $grp = stripslashes($row['grp']); $art_date = $row['art_date']; $dwnld_date = $row['dwnld_date']; $status = $row['status']; $grp_links .= "<dt><a href=\"http://kearneyfire.org/#########/$path/$filename\">$anchor</a> <strong>$status</strong></dt> <dd>$descript <em>Article Date: $art_date, Group: $grp, Filename: $filename</em></dd>"; switch ($desig) { case 01: $type = "Board Meeting Agenda"; break; case 02: $type = "Board Meeting Minutes (W/O Chief's Report)"; break; case 03: $type = "Board Meeting Minutes (W/ Chief's Report)"; break; case 04: $type = "Officer's Minutes"; break; case 05: $type = "Public Forms"; break; case 06: $type = "Internal Forms"; break; case 07: $type = "Job Opening Related"; break; case 08: $type = "Public Notices"; break; case 09: $type = "Public Information and Handouts"; break; case 10: $type = "Programs"; break; case 11: $type = "Public Miscellaneous"; break; case 12: $type = "Internal Miscellaneous"; break; case 13: $type = "Internal Information Handouts"; break; default: $type = "Type not Defined"; break; } $grouped_output .= " <tr> <td class=\"td_title\"> $type </td> </tr> <tr> <td> <dl> $grp_links </dl> </td> </tr>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-437121 Share on other sites More sharing options...
Defibber Posted January 12, 2008 Author Share Posted January 12, 2008 Ok I have tried it without the quotes and using settype() as below with the different but still undesired results. for ($desig = 01; $desig <= 13 ; $desig++) { settype($desig, 'int'); I think I know just enough to be dangerous.... Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-437124 Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 Right before your Switch, do this echo $desig; exit; switch ($desig) { Then see what $desig contains. It may have a problem with the leading zero. Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-437285 Share on other sites More sharing options...
Defibber Posted January 12, 2008 Author Share Posted January 12, 2008 Ok, it did return "1" instead of "01", So I went and looked at the DB and all of the types were without the leading "0" anyways, but I took the leading zero off of everything just in case but I am still having the same results. Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-437323 Share on other sites More sharing options...
Defibber Posted January 12, 2008 Author Share Posted January 12, 2008 Hmm, ok I have tried a couple of variations and on each of them the page times out with no output. Variation 1 $desig = 1; do { #REST of the code $desig++; } while ($desig <= 13) ; Variation 2 $desig = 1; while ($desig <= 13){ #Rest of the code $desig++; } Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-437337 Share on other sites More sharing options...
Defibber Posted January 14, 2008 Author Share Posted January 14, 2008 Ok I have tried to create my own function but now I just get a blank screen. I am not sure what to do. I can never seem to get custom functions to work. If I can get an output, I will use a DO loop to increment the function. function dwnld_links($desig){ global $grouped_output; $sql = "SELECT * FROM downloads WHERE type = '$desig' ORDER BY art_date ASC"; $result = @mysql_query($sql, $con_priv_resources) or die(mysql_error()); $num = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $type = $row['type']; $path = stripslashes($row['path']); $filename = stripslashes($row['filename']); $anchor = stripslashes($row['anchor']); $descript = stripslashes($row['descript']); $grp = stripslashes($row['grp']); $art_date = $row['art_date']; $dwnld_date = $row['dwnld_date']; $status = $row['status']; $links .= "<dt><a href=\"http://kearneyfire.org/downloads/$path/$filename\">$anchor</a> <strong>$status</strong></dt> <dd>$descript <em>Article Date: $art_date, Group: $grp, Filename: $filename</em></dd>"; } switch ($desig) { case 1: $type1 = "Board Meeting Agenda"; break; case 2: $type1 = "Board Meeting Minutes (W/O Chief's Report)"; break; case 3: $type1 = "Board Meeting Minutes (W/ Chief's Report)"; break; case 4: $type1 = "Officer's Minutes"; break; case 5: $type1 = "Public Forms"; break; case 6: $type1 = "Internal Forms"; break; case 7: $type1 = "Job Opening Related"; break; case 8: $type1 = "Public Notices"; break; case 9: $type1 = "Public Information and Handouts"; break; case 10: $type1 = "Programs"; break; case 11: $type1 = "Public Miscellaneous"; break; case 12: $type1 = "Internal Miscellaneous"; break; case 13: $type1 = "Internal Information Handouts"; break; default: $type1 = "Type not Defined"; break; } $grouped_output .= " <tr> <td class=\"td_title\"> $type1 </td> </tr> <tr> <td> <dl> $links </dl> </td> </tr>"; return $grouped_output; } //Then all the HTML <table class="main" width="100%"> <tr> <td class="table_title" width="100%"> All Download Links from entire Website. </td> </tr> <? echo dwnld_links(1); ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-438599 Share on other sites More sharing options...
Defibber Posted January 16, 2008 Author Share Posted January 16, 2008 Why won't this function work?? I have tried several ways to get it to work. Again you can go to this page to see the result. http://www.kearneyfire.org/web_content/dwnld_view_all.php function dwnld_group($desig){ $sql = "SELECT * FROM downloads WHERE type = '$desig' ORDER BY art_date ASC"; $result = @mysql_query($sql, $con_priv_resources) or die(mysql_error()); $num = mysql_num_rows($result); if ($num ==0) { $grp_links = "No download links"; } else { while ($row = mysql_fetch_array($result)) { $type = $row['type']; $path = stripslashes($row['path']); $filename = stripslashes($row['filename']); $anchor = stripslashes($row['anchor']); $descript = stripslashes($row['descript']); $grp = stripslashes($row['grp']); $art_date = $row['art_date']; $dwnld_date = $row['dwnld_date']; $status = $row['status']; $grp_links .= "<dt><a href=\"http://kearneyfire.org/downloads/$path/$filename\">$anchor</a> <strong>$status</strong></dt> <dd>$descript <em>Article Date: $art_date, Group: $grp, Filename: $filename</em></dd>"; } } switch ($desig) { case 1: $type = "Board Meeting Agenda"; break; case 2: $type = "Board Meeting Minutes (W/O Chief's Report)"; break; case 3: $type = "Board Meeting Minutes (W/ Chief's Report)"; break; case 4: $type = "Officer's Minutes"; break; case 5: $type = "Public Forms"; break; case 6: $type = "Internal Forms"; break; case 7: $type = "Job Opening Related"; break; case 8: $type = "Public Notices"; break; case 9: $type = "Public Information and Handouts"; break; case 10: $type = "Programs"; break; case 11: $type = "Public Miscellaneous"; break; case 12: $type = "Internal Miscellaneous"; break; case 13: $type = "Internal Information Handouts"; break; default: $type = "Type not Defined"; break; } $grouped_output = " <tr> <td class=\"td_title\"> ".$type." </td> </tr> <tr> <td> <dl> ".$grp_links." </dl> </td> </tr>"; return $grouped_output; } Then the HTML Output is: <table class="main" width="100%"> <tr> <td class="table_title" width="100%"> All Download Links from entire Website. </td> </tr> <? echo dwnld_group(1); ?> </table> This is driving me nuts thank you to all that have tried to help so far. Quote Link to comment https://forums.phpfreaks.com/topic/85652-i-cant-place-my-thumb-on-it/#findComment-440582 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.