Page is a not externally linkable
- WebmasterWorld
-- New To Web Development
---- Output Listing


Ollie_3rd - 5:55 pm on Dec 29, 2009 (gmt 0)


Rockinbil:
Thanks again for your help!
Things are close to working but no cigar yet. I get 325 lines of web addresses that have no rhyme or reason (ie same ones for Alabama multiple times and in no order) except at the end I only get one for ALASKA; ARIZONA; AND ARKANSAS. Then I get the state name ALABAMA with all (22) web sites for that state. But then I get the same 22 for the other 3 states I have for testing. It doesn't select the web addresses for the next state(s). To keep this from being too long here is a sample output:

(mucho before these)
West Alabama Beekeepers Association
Wiregrass Beekeepers Association
Alaska Beekeepers Association
Beekeepers Association of Central Arizona
Arkansas Beekeepers Association
State Listings

ALABAMA

Alabama Beekeepers Association
Baldwin County Beekeepers Association
Central Alabama Beekeepers Association
Choctaw County Beekeepers Association
Cullman County Beekeepers Association
East Alabama Beekeepers Association

ALASKA

Alabama Beekeepers Association
Baldwin County Beekeepers Association
Central Alabama Beekeepers Association
Choctaw County Beekeepers Association
Cullman County Beekeepers Association
East Alabama Beekeepers Association

Another thing is I don' see a closing for the <?php and I have tried to remove/modify the last echo before " <!DOCTYPE html PUBLIC \"-//W3C//DTD HT that was close to the bottom of the code you suggested but nothing works when I do that. I had to remove the var before $allstates = Array because it didn't like that either.

Here is my code so far:

<html>
<head>
<title>Anne Arundel Beekeepers Association</title>
<META NAME="Listing of US Beekeeping Organizations" CONTENT="Links to Beekeeping Web Sites">
<META NAME="Bee,Bees,Beekeeping,Honey,Web Sites,Queen,Drone,Worker" CONTENT="PHP code to retreive data from a MySql Database">
</head>
<body>
<?php
mysql_connect("localhost", "root") or die(mysql_error());

//echo "Connected to MySQL<br />";
mysql_select_db("test") or die(mysql_error());
//echo "Connected to Database<p>";
$allstates = Array (
'ALABAMA',
'ALASKA',
'ARIZONA',
'ARKANSAS'
// And so on, full state list.
);

$currState=$rowData=NULL;

foreach ($allstates as $state) {

if ($currState != $state) {
$output .= "<h3>$state</h3>";

$currState=$state; // only prints once per section
}

$query = "SELECT web,name FROM aaba WHERE state='$currState' order by name asc";

$result=mysql_query($query);
if (!$result) { die("can't get data from tablename: " . mysql_error());

} while ($row=mysql_fetch_array($result)) {

//$row[0] is web, $row[1] is name. You can also use
//assoc. values: $row['web'] and $row['name']

echo $rowData .= " $row[0] <br />";
}
if ($rowData) { $output .= $rowData; }
else { $output .= "<p>No results in $state</p>";
}
}
mysql_free_result($result);

echo "
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> <html lang=\"en\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">
<title>Listings
</title>
</head>
<body> <h1>State Listings</h1>
$output

</body>
</html>
";


Thread source:: http://www.webmasterworld.com/new_web_development/4050287.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com