Re: grab table row -readme.1st

From: Date: Thu, 06 Jul 2000 01:26:49 +0000
Subject: Re: grab table row -readme.1st
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-5137@lists.php.net to get a copy of this message
In article <LOBBLHLKHEOIBEPNHAIDKEIACIAA.rodneyg@magma.ca>, rodneyg@magma.ca ("Rod Goodwin") wrote: > I realize I should build the array and then print my table from it > rather than trying to grab from a parsed table, but it is not > clear to me how, and the link that references the index gives me great fear > :/ > > Essentially, I want to grab a row and create a hyperlink on the fly. This > last column's link should be bring up a new page with the full record > details. I am using > mysql/php3. > I have had trouble with building the array (a loop within a loop?) > and this sprinkling a link into a table utilizing that row) > > I have lurked, and scoured and can find nothing. > Thanks in advance! > > My code is as follows > > // create header row > > print("<TR>\n"); > print("<TD BGCOLOR=\"#CCCCCC\"><B>Chicken > breed</B></TD>\n"); > print("<TD > BGCOLOR=\"#CCCCCC\"><B>Weight</B></TD>\n"); > print("<TD > BGCOLOR=\"#CCCCCC\"><B>Colour</B></TD>\n"); > print("</TR>"); > > //start data printing to table format > > if ($row = mysql_fetch_array($query)) > { > > do { This if/do/while/else could much clearer with just: $anyrows = 0; while($row = mysql_fetch_array($query))} $anyrows = 1; //all that stuff in here... } if (!$anyrows){ echo "No chickens here.<BR>\n"; } > print ("<TR>"); // start row > print("<TD> <FONT SIZE=\"-4\">\n"); > print $row["CHICKEN"]; > print ("</TD>"); > print("<TD> <FONT SIZE=\"-4\">\n"); > print $row["WEIGHT"]; > print ("</TD>"); > print("<TD> <FONT SIZE=\"-4\">\n"); > print $row["COLOUR"]; > print ("</TD>"); echo "<TD><A HREF=details.php?id=", $row["ID"], ">Details</A></TD>\n"; This assumes you have an ID field for each record... Then you'd write a PHP page called 'details.php' that would retrieve everything about one record (the one "... where ID = $ID") and would show it all. > print ("</TR>"); // end row > > } while ($row = mysql_fetch_array($query)); > } > else {print "Sorry, no records were found!";} > print ("</TABLE>"); //end table -- Richard Lynch | If this was worth $$$ to you, buy a CD US Customer Support Director | from one of the artists listed here: Zend Technologies USA | http://www.L-I-E.com/artists.htm http://www.zend.com | (this has nothing to do with Zend, duh!)

« previous php.general (#5137) next »