Jump to content

I can't place my Thumb on it


Defibber

Recommended Posts

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>";
}

}

Link to comment
Share on other sites

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>";
}

}

Link to comment
Share on other sites

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++;
}

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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.

 

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.