GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Jun-2003, 06:50
norok norok is offline
New Member
 
Join Date: Jun 2003
Posts: 23
norok is an unknown quantity at this point

Add a tool to a yet written code-help would be great!


Hi,
I' ve the following problem:
Out of several pieces of code(not mine), I've made a library.
Now it works, but I want to add another feature and don't
kno how to do.
The following:If PHP has found a book in my mysql database,
it reports me the results listed one book after the other.
Now I want a checkbox below every result->(book).
If you want to borough this book from the schoollibrary,you
just mark it. At the end of the page should be a rollout
with the pupils' names, where you can choose your name.
Then the submitbutton should deliver the IDs of the before marked books and register the bookID-userid combination into the user tablelooking like this:

relation_user_book :
table user,
userID,int,not null
bookID(in my table titleId),int,not null,


user table:
userid,
name,
prename,

Here is the code of the "show results ",It's long but perhaps
you can handle withit, because in the german forums they
werentable to help me.
PHP Code:

// show search results
if(!empty($sql)) {
  if($sqlType=="author") {

    // show authors
    $result = mysql_query($sql);
    if(!$result or !mysql_num_rows($result))
      echo "<p>No results.\n";
    else {
      echo "<hr><ul>\n";
      while($row = mysql_fetch_object($result)) {
        echo "<li>", 
          build_href("./find.php", 
                     "sqlType=title&authID=$row->authID", 
                     last_name_last($row->authName)), 
          "</li>\n";
      }
      echo "</ul>\n";
    }  
  }

  // show titles
  elseif($sqlType=="title") {
    // just in case it is still here: drop tmpTitleIDs
    mysql_query("DROP TABLE IF EXISTS tmpTitleIDs");
    // create new table with title IDs
    mysql_query($sql);
    if(!mysql_affected_rows()) {
      echo "<p>No results.\n";
    }
    else {
      // querys for complete title data
      $result1 = mysql_query
        ("SELECT titles.titleID AS titleID, " .
         "       titles.title AS title, " .
         "       titles.subtitle AS subtitle, " .
         "       titles.edition AS edition, " .
         "       titles.year, " .
         "       titles.isbn, " .
         "       titles.comment, " .
         "       publishers.publName AS publisher, " .
         "       publishers.publID, " .
         "       categories.catName AS category, " .
         "       languages.langName AS language " .
         "FROM titles JOIN tmpTitleIDs" .
         "     LEFT JOIN categories ON titles.catID = categories.catID " .
         "     LEFT JOIN languages ON titles.langID = languages.langID " .
         "     LEFT JOIN publishers ON titles.publID = publishers.publID " .
         "WHERE titles.titleID = tmpTitleIDs.titleID");

      // query for authors
      $result2 = mysql_query
        ("SELECT tmpTitleIDs.titleID, rel_title_author.authID, " .
         "       authName AS author " .
         "FROM authors, rel_title_author, tmpTitleIDs " .
         "WHERE authors.authID = rel_title_author.authID " .
         "  AND rel_title_author.titleID = tmpTitleIDs.titleID " .
         "ORDER BY rel_title_author.authNr, authName");

      // copy authors into array
      while($row = mysql_fetch_object($result2)) {
        // seperate authors by a comma
        if($authors[$row->titleID]) 
          $authors[$row->titleID] .= ", ";
        // add author to author's list; because of ORDER BY clause
        // in the SQL statement the authors are ordered correctly
        $tmp = build_href("./find.php", 
                          "sqlType=title&authID=$row->authID", 
                          last_name_last($row->author));
        $authors[$row->titleID] .= $tmp;
      }

      // show title list
      echo "<hr><ul>\n";
      $titlecount=0;
      while($row = mysql_fetch_object($result1)) {
        $titlecount++;
        if($titlecount<=$pagesize) {
          if($row->publisher)
            $publref = build_href("./find.php", 
                                  "sqlType=title&publID=$row->publID", 
                                  $row->publisher);
          // title
          echo "<p><li>", $authors[$row->titleID], ": ",
            "<b>", htmlentities($row->title), "</b>",
            $row->subtitle ? ", " . htmlentities($row->subtitle) . " " : "",
            $row->publisher || $row->year ? "<br>" : "", 
            $row->publisher ? $publref : "",
            $row->year ? ", " . htmlentities($row->year) . " " : "",
            $row->edition ? "<br>Edition: " . htmlentities($row->edition) ." " : "",
            $row->isbn ? "<br>ISBN: " . htmlentities($row->isbn) . " " : "",
            $row->language ? "<br>Language: <i>" . htmlentities($row->language) . "</i> " : "",
            $row->category ? "<br>Category: <i>" . htmlentities($row->category) . "</i> " : "",
            $row->comment ? "<br>Comment: <i>" . htmlentities($row->comment) . "</i> " : "",
            "</li>\n";
        }
      }
      echo "</ul>\n";
    
    } // else block for if(!mysql_affected_rows())
    // drop temporary database
    mysql_query("DROP TABLE IF EXISTS tmpTitleIDs");

    // show links to other pages
    if((isset($page) and $page>1) or $titlecount>$pagesize) {
      echo "<hr>\n";
      $query = "sqlType=title";
      $query .= isset($authID) ? "&authID=$authID" : "";
      $query .= isset($publID) ? "&publID=$publID" : "";
      $query .= isset($search) ? "&search=" . urlencode($search) : "";
      echo "<p>More results: ";
      // links to previous pages
      if(isset($page) and $page>1) {
        echo build_href("./find.php", 
                        $query . "&page=" . ($page-1), 
                        "Previous page");
        echo " / Page ";
        for($i=1; $i<$page; $i++) {
          if($i>1) echo " ";
          echo " ", 
            build_href("./find.php", $query . "&page=" . $i, $i);
        }
      }
      // current page
      if($page>1) 
        echo " ";
      else
        echo "Page ";
      echo "<b>($page)</b> ";
      if($titlecount>$pagesize) {
        if(isset($page)) 
          echo " ";
        else
          $page=1;
        echo build_href("./find.php", $query . "&page=" . ($page+1), ($page+1));
        echo " / ";
        echo build_href("./find.php", 
                        $query . "&page=" . ($page+1), 
                        "Next page");

      }
      echo "\n";
    }
  }
}

// link back to search form

if(!$QUERYSTRING)
  echo "<p><a href=\"./find.php\">Back to search form.</a>\n"; 


Thank you all,

Matthias
  #2  
Old 25-Jun-2003, 08:13
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
The ids of the 'marked' books should be passed along in a session?

When the user id is 'checking out' just pass the values off the session to the table relation_user_book.

I am sorry, I ignored your code - I have been coding for a bit these past few days and I have had about enough of PHP code for now...
  #3  
Old 14-Jul-2003, 11:30
Mary Mary is offline
New Member
 
Join Date: Jul 2003
Posts: 3
Mary is an unknown quantity at this point
Smile

When you loop through the db, having it spit out the books and their information, have the loop echo an input box with the name of "checkout[]" ([]makes it an array), and give it the value corresponding to the book's id.

Code:
<input type="checkbox" name="checkout[]" value="your db inserted id here">

That should create an array called "checkout" of all the books "checked", which will contain all the ids of the books to be loaned out.

I'm still a newbie with arrays so I could be wrong, so feel free anyone to correct me if I am.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Save code option BobbyDouglas GIDForums™ 3 09-Nov-2003 00:48
something wrong with this code loon MySQL / PHP Forum 5 07-Jul-2003 06:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:56.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.