Re: Selecting a Queried Row
| From: | aajdubuc at webhart dot net | Date: | Tue, 12 Mar 2002 20:49:27 +0000 |
| Subject: | Re: Selecting a Queried Row | ||
| References: | 1 | Groups: | php.general php.general |
| Request: | Send a blank email to php-general+get-88232@lists.php.net to get a copy of this message | ||
Hi Hugh,
Using the method you've suggested produces a highlighted "ID" field in the
table. However, I can't call it to "do" anything -- I wonder if there's an
"echo" statement I could place somewhere that would indicate whether the
variables of the selected row have been passed.
What I want it to accomplish: The original table would display all the names
(with highlighted ID's). One row would be selected. Its variables (ID or
$rid, First name or $rfname, Last Name or $rsname, City or $rcity, Country or
$rcountry, and Status or $rstatus) would displayed in a new table. I want the
variables to be kept alive for further use (so that I can call them again).
I've scoured the resources, and can't seem to find anything about passing
variables that have been accessed by <a href ....>. Obviously, I don't
understand something very fundamental here, so if you could point me in the
right direction, I'd greatly appreciate it. Also, if you know, from what I've
written, what might be good to "bone-up" on, I'd appreciate your insights!
The code I've written so far (please excuse the primitive form!):
<?php
$db = pg_connect("dbname=dad user=postgres");
$query = "SELECT * FROM rap";
$result = pg_exec($db, $query);
if (!$result) {printf ("ERROR"); exit;}
$numrows = pg_numrows($result);
$row = 0;
printf("<table border=3 cellpadding=5 bgcolor=#FFCC99 align=center>");
printf("<tr><th>ID</th><th>First name</th><th>Last
Name</th><<th>City</th><th>Country</th><th>Status</th></tr>");
do
{
$myrow = pg_fetch_array($result,$row);
printf ("<tr><td><a href=view-rap.php?ID>%s</a></td>
<td align=right>%s</td>
<td>%s</td>
<td align=center>%s</td>
<td align=center>%s</td>
<td align=center>%s</td>
<td>%s</td>
<td align=center>%s</td></tr>",
$myrow['rid'], $myrow['rfname'], $myrow['rsname'],
$myrow['rcity'],
$myrow['rcountry'], $myrow['rstatus']");
$row++;
}
while ($row < $numrows);
printf ("<table>");
pg_close($db);
?>
Tia,
Andre
Andre,
The following code block is from a site I'm developing for a local museum.
The site is now located at www.ironorchid.com/museum/ but will move
eventually to its own site. In it, I have a list of the landmark trees,
with links to a map showing the location of the tree, a link to
maps.yahoo.com to get a detailed map of the location and or driving
directions, and links to show all the trees in an area of the city. In
other words, the table is link crazy--sounded enough like what you want to
do that I responded to your question. All of the data in the html table
comes from a mysql database with three database tables (heritage, trees,
sites).
If you use the mysql_fetch_array() command in a WHILE statement, you create
an array of the row or rows resultant from your query and have the mysql
column titles as your array keys. You can then use the <a href= html tag to
put a link under the words in your table cells and generate the html code to
go to the next row of data.
As I said earlier, I have the bad habit of writing everything in php once I
need it on a page, so the code block might be a bit hard to read. Let me
know if you need further details on what's provide.
Hope this helps,
Hugh
<?php
print "<table align=center bgcolor=white cellspacing=0 cellpadding=4
border=1 >";
print "<tr bgcolor=Cornsilk><td><h5><b>ID # <a href=list.php
title=\"scientific name\"><b>Common
Name</b></a></h5></td><td><h5><b>Address</b></h5></td><td><h5><b>District</b
></h5></td></tr>";
$db="some_database";
$pass="some_password";
$link=mysql_connect("localhost","","$pass");
if (! $link) die("Can't log in at this time");
mysql_select_db($db,$link) or die ("Can't log in at this time");
$query="select * from heritage where asset_num>'0' order by asset_num";
$result=mysql_query($query);
if (!$result) die(mysql_error());
while ($heritage=mysql_fetch_array($result))
{
$query2="select * from trees where
id='".$heritage['plant_num']."' ";
$result2=mysql_query($query2);
$trees=mysql_fetch_array($result2);
$query3="select * from sites where
plant_num='".$heritage['plant_num']."'
";
$result3=mysql_query($query3);
$num=0;
while ($sites=mysql_fetch_array($result3))
{
$links[$num]=$sites['link'];
$num=$num+1;
}
print "<tr><td valign=top align=left><p><a
href=mapmastr.php?list1=1&tree=1&coordinate_x=".$heritage['x']."&coordinate_
y=".$heritage['y']."
title=\"".stripslashes($trees['scientific_name'])."
native to ".$trees['native_to']."\">
".$heritage['asset_num']."
".stripslashes($trees['common_name'])."</a></p></td>
<td valign=top align=left><p><a
href=http://maps.yahoo.com/py/maps.py?BFCat=&Pyt=Tmap&newFL=Use+Address+Belo
w&addr=".ereg_replace (" ", "+",
stripslashes($heritage['address']))."&csz=".$heritage['zip']."&Country=us&Ge
t%A0Map=Get+Map title=\"go to maps.yahoo.com to get a map of this address\">
".stripslashes($heritage['address'])."</a></p></td>
<td valign=top align=left><p><a
href=mapmastr.php?district=".$heritage['town_name']." title=\"see the
location of all Landmark Trees in the ".$heritage['town_name']."
District\">
".$heritage['town_name']."</a></td></tr>";
}
mysql_close($link);
print "</table>";
?>
----- Original Message -----
From: "Andre Dubuc" <aajdubuc@webhart.net>
To: <php-general@lists.php.net>
Sent: Saturday, March 09, 2002 4:12 PM
Subject: [PHP] Selecting a Queried Row
> As a newbie at PHP (and relative newcomer to HTML and web design) I've
been
> wading through documentation trying to accomplish various tasks. However,
I'm
> stumped on how to proceed with the following:
>
> I would like a web vistor to be able to select a row from a table that has
> been generated from a query. The problem is I don't know how to code a
> paricular column (using the present <td> . . </td> syntax of the table) so
> that each cell would have a "clickable" element (perhaps the 'ID' number).
>
> Once that cell is clicked, I would like to code 'onclick=some_function()'
>
> Does this sound reasable way of approaching the problem, or is there a
better
> way. [Btw, at present, while learning PHP, I am using global_variables=on,
> but would like to try $PHP_SELF method to pick up session variables.]
>
> Any help would be greatly appreciated, as well as pointers of where to
look!
>
> Tia, Andre
>
>
> --
> Please pray the Holy Rosary to end the holocaust of abortion.
> Remember in your prayers the suffering souls in Purgatory.
>
> May God bless you abundantly in His love!
>
> For a free Cenacle Scriptural Rosary Booklet --
http://www.webhart.net/csrb/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>