|
Posted by David Haynes on 07/14/06 10:34
IchBin wrote:
> David, thank you so much for helping me out. I do not have much more
> hair to pull out. I am a Java person. Anyway, I understand a lot more
> after you sample code.
>
> As an aside, this is my own little project to learn php and etc. I
> already have a complete Java\swing application written around this DB so
> I figure I could lean away from J2EE and try PHP. It is a different animal.
>
> This DB is a Quotes DB. I have been building over the last few years.
> Just a personal interest. I have around 1300 authors and over 32,000
> quotes along with detail\quote like external Links and references for
> each quote. And naturally detail information about the author.
>
> I did mix your code with mine. The only problem I am having is with the
> dropdown object. When I run the program the following displays: on and
> on and not in the dropdown..
>
> , , , , , Abbey, Edward, , , Abbott, William, Alexander, , Abelard,
> Pete, , , Accius, Lucius, , , Acheson, Dean, , , Ackerman, Diane, , ,
> Adams, Abigail, Smith, , Adams, Ansel, , , Adams, Bryan, , , Adams,
> Douglas, , , Adams, Franklin, Pierce, , Adams, Henry, , , Adams, Joey,
> Lauren, , Adams, John, , , Adams, John, Quincy, , Adams, Scott, , ,
> Addison, Joseph, , , Ade, George, , , Adler, Alfred, , , Adler,
> Mortimer, Jerome, , Adorno, Theodor, , , Aeschylus, , , , Aesop, , , ,
> Afer, Publius, Terentius, , Agathon, , , , Agesilaus, , , II , Aiken,
> George, , , Aiken, Howard, , , Alcott, Amos, Bronson, , Alcott, Louisa,
> May, , Alcuinus or Ealhwine, Flaccus, Albinu, , Alda, Alan, , ,
> Alexander, Shana, , , Ali-Haj, Muhammad, , , Allen, Fred, , , Allen,
> Woody, , , Alzado, Lyle, , , Amiel, Henri-Frédéric, , , Amory,
> Cleveland, , , Anaxagoras, , , , Ancient Chinese Curse, , , , Andersen,
> Hans, Christian, , Angell, George, Thorndike, , Angelou, Maya, , The
> Princess, Anne, , , , Princess Royal , Anonymous, , , , Anouilh, Jean, ,
> Saint, Anselm, , , of Canterbury , Anthony, Susan, B., , Antiphanes, , ,
> , Antisthenes,
>
> Here is the code but I guess the concern is the dropdown.
>
> <?php
> //
> // Open DB
> include 'library/opendb.php';
>
> // This form uses the POST method, so process any post selections here
> if( isset($_POST['author_pk']) ) {
> // do whatever you need to do with the author_pk
> // $sql = "select * from book_detail where author_pk =
> {$_POST['author_pk']}";
> // $detail = mysql_query($sql);
> }
> //
> // main form query
> $sqlcmd = 'select id, TITLE, lastname, firstname, middlename, SUFFIX
> from author_detail order by lastname, firstname, middlename';
> $result = mysql_query($sqlcmd);
> if (!$result) {
> die('Database Error: ' . mysql_error());
> exit;
> }
> //
> // Close DB
> include 'library/closedb.php';
> ?>
>
> <FORM NAME="author" method="post" action="<?php echo
> $_SERVER['PHP_SELF'];?>"
> <SELECT NAME="author_pk" SIZE="20" COLS="20">
>
> <?php
> // a loop to populate the select options
> while( $row = mysql_fetch_object($result) ) {
> printf("<option value=\"%d\">%s, %s, %s, %s, %s</option>\n",
> $row->id, $row->TITLE, $row->lastname,
> $row->firstname, $row->middlename, $row->SUFFIX);
> }
>
> mysql_free_result($result);
>
> // display any book details based on the user's selection
> if( isset($detail) ) {
> // while( $row = mysql_fetch_assoc($detail) ) {
> // printf("Title: %s<br>\n", $row['title']);
> // }
> }
> ?>
> </SELECT>
> </FORM>
IchBin:
1. I made a mistake in the sample code I sent you in that the <FORM>
tag is not properly terminated. The line should read:
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF']'?>">
The last '>' was missing.
2. if you run the SQL query from the mysql command line, do you get
what you expect?
Hint:
Add 'echo $sqlcmd;exit;' after the $sqlcmd= line and then cut and
paste into a mysql command session
3. Adjust the sqlcmd and add 'limit 1' so that only one row is returned
while debugging. If it is still not right, post the code and the output
and I'm sure folks here will be all over it offering advice.
-david-
Navigation:
[Reply to this message]
|