hi.
what i'm trying to do is have a popup window that displays all of the data from a specific row. the popup works fine but i can't get the correct row to display.
basically, i have an index that lists organization's alphabetically (in this case it will be 'a'). when i click on the organization i want it to hyperlink and popup a window that will display the rest of the row's data (right now the only other column is 'last_name'). i know there's either something wrong with my query and/or i can't get the row numbers to match up correctly.
here's the code below (2 files: a.php(which lists the organization's starting with 'a') and alpha.php(which is supposed to display the entire row's data for the clicked-on organization) ):
A.PHP
<script>
function openpopup(){
var popurl="alpha.php"
winpops=window.open(popurl,"","left=150,top=100,width=500,height=400,")
}
</script>
<?PHP
include("../header.inc");
/* set the allowed order by columns */
$default_sort = 'organization';
$allowed_order = array ('last_name','organization');
/* if order is not set, or it is not in the allowed
* list, then set it to a default value. Otherwise,
* set it to what was passed in. */
if (!isset ($_GET['order']) ||
!in_array ($_GET['order'], $allowed_order)) {
$order = $default_sort;
} else {
$order = $_GET['order'];
}
$query = "SELECT organization FROM uwnorman WHERE organization LIKE 'a%' ORDER BY $order";
//Connect to database
include("../connect.php");
/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
if ($numrows == 0) {
echo "No data to display!";
exit;
}
/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
/* check if the heading is in our allowed_order
* array. If it is, hyperlink it so that we can
* order by this column */
echo "<TD><b>";
if (in_array ($heading, $allowed_order)) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD>\n";
}
echo "</TR>\n";
/* reset the $result set back to the first row and
* display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TR>\n";
foreach ($row as $column) {
echo "<TD><a href=\"javascript:openpopup()\">$column</a></TD>\n";
}
echo "</TR>\n";
}
echo "</TABLE>\n";
//Close connection
include("../close.php");
include("../footer.inc");
?>
ALPHA.PHP
<?PHP
include("../header.inc");
/* set the allowed order by columns */
$default_sort = 'organization';
$allowed_order = array ('last_name','organization');
/* if order is not set, or it is not in the allowed
* list, then set it to a default value. Otherwise,
* set it to what was passed in. */
if (!isset ($_GET['order']) ||
!in_array ($_GET['order'], $allowed_order)) {
$order = $default_sort;
} else {
$order = $_GET['order'];
}
$query = "SELECT * FROM uwnorman WHERE organization LIKE 'a%' ORDER BY $order";
//Connect to database
include("../connect.php");
/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
//Print number of rows in query
echo "$numrows";
if ($numrows == 0) {
echo "No data to display!";
exit;
}
/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
/* check if the heading is in our allowed_order
* array. If it is, hyperlink it so that we can
* order by this column */
echo "<TD><b>";
if (in_array ($heading, $allowed_order)) {
echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>";
} else {
echo $heading;
}
echo "</b></TD>\n";
}
echo "</TR>\n";
/* reset the $result set back to the first row and
* display the data */
echo "<TR>\n";
foreach ($row as $column) {
mysql_data_seek ($result, $column);
echo "<TD>$column</TD>\n";
}
echo "</TR>\n";
echo "</TABLE>\n";
//Close connection
include("../close.php");
include("../footer.inc");
?>
i'm sure the problem seems to be around the query for alpha.php and
foreach ($row as $column) {
mysql_data_seek ($result, $column);
echo "<TD>$column</TD>\n";
}
i would also like to have it where alpha.php would not only sort the a's but all letters. i know i have to change the LIKE 'a%' part but i don't know how to get the specific letter i want to show without the LIKE 'a%'.
to see a working example of what i'm talking about check http://uwn.betachitheta.org/ and click on 'A' at the top of the page. it will list three organization's: a, ab, and abc. the last name for a is f, ab is ef, abc is def. so if i click on the second one, ab, it should popup ab and ef as the organization and last_name, respectively.
any help would be appreciated. sorry for the long message.
nabeel ahmad