I'm attempting to "print" to the client's browser a list of book titles found in a MYSqL table, each with a checkbox on its "printed" line so that the client can click on the checkboxes to retrieve selected books.

The php script below is included after verification of the fields in an HTML form.
Global variable $books is the name of the books table in the connected database. Variable $title contains the string to be used to search for matching book titles in the books table of the library.

I was hoping that the checkboxes printed would have different array indexes when script "booksretrieve" is posted.

There must be a much better way than the following old mainframe style of scripting I've done.

After the php scripts there is a sample of what was "printed" by the client browser.

Help please.

Mike

<? php

# Show details of BOOKS

# Performing SQL query

$query = "SELECT * FROM `$books` WHERE `title` LIKE '$title' LIMIT 99";
$result = mysql_query($query) or die("Query failed");
$count = 1; $bookslist = "";
while ($rowarray = mysql_fetch_array($result, MYSQL_ASSOC))
{
$booksid = $rowarray["booksid"];
$title = $rowarray["title"]; print '<html>';
print '<head>';
print '<meta http-equiv="Content-Language" content="en-us">';
print '<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">';
print '<title>Library Search results</title>';
print '<body>';
############################## NOTE php script to run #########################
print '<form method="post" action="booksretrieve.php">';
print '<font face='Courier New' size='2'>';
############ $bookslist to be used by ###
if ($bookslist == "") $bookslist = $booksid;
else $bookslist = $bookslist. ",". $booksid;
print "<br><b>Book number: $booksid in bookslist $bookslist .<br>";
print '<p>Click box get following book retrieved. <input type="checkbox" name="book[1][$booksid]" value ="ON" ><br>';
print "<br>";
print "title:. <b>" .$title. " </b><br>";
print "-----------------------------</b><br>";
$count = $count + 1;
}
# Free resultset */
mysql_free_result($result);

print "<p>Click 'Clear all fields' if you do <b>NOT</b> want us to do this. ";
print '<p><input type="submit" value="Submit request">&nbsp;<input type="reset" value="Clear all fields" name="B2"> <br>';
print "</body>";
print "</html>";

return;
?>

<?php
#################
#BOOKSRETRIEVE : Retrieve library books selected by clicked checkboxes.
#################

echo "BOOKSRETRIEVE. Array contents print as:<p>";
$result = $_POST['book'];
print_r($result);

return;
?>

Sample of what was "printed" by the client browser (checkboxes shown as #):


Book number: 0 in bookslist 0 .

Click box get following book retrieved. #

title:. Book title A

-----------------------------

Book number: 3 in bookslist 0,3 .

Click box get following book retrieved. #

title:. Book title C

-----------------------------

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to