help with php listing

a web page that users can upload pdf, doc on it with entering title, keywords, category with it.
Also there is a search page that user cansearch them.

A search page and listingthe result.
every row has 1 checkbox .
what i want to do i want to if user will check the checkbox ( if only 1 selected that file will be - if more than 1, they willbe zip or rar(archive) ) they will be downloaded with pressing download button.

There will be select all button ( for result of the search ) also which i coulnt add it here.

<?php
mysql_connect ("localhost", "root","1")  or die (mysql_error());
mysql_select_db ("publisher");
 
$term = $_POST['term'];
?>
 
<html>
<body>
<p>&nbsp;</p>
<p>Search results for 
  <?php $term ?>
</p>
<table border=1>
  <tr>
   <td><p>&nbsp; </p>
   </td>
   <th>ID</th>
    <th>Title</th>
   <th>Keyword</th>
   <th> Author</th>
    <th> Category</th>
	<th> FileName</th>
  </tr>
 
<?php
$term = $_POST['term'];
$sql = mysql_query("select * from paper where category like '%$term%' or title like '%$term%' or keyword like '%$term%' or author like '%$term%' ");
 
//return the array and loop through each row
while ($row = mysql_fetch_array($sql)){
 
    $id = $row['id'];
    $title = $row['title'];
    $keyword = $row['keyword'];
    $author = $row['author'];
	$category = $row['category'];
	$fname = $row['fname'];
     
?>
 
  <tr>
  <td><input type='checkbox' name='checkboxvar[]' value='<?php echo $value->fname ?>'></td>
   <th><?php echo $id;?></th>
   <th><?php echo $title;?></th>
   <th><?php echo $keyword;?></th>
   <th><?php echo $author;?></th>
   <th><?php echo $category;?></th>
   <th><?php echo $fname;?></th>
  </tr>
   
<?php }  ?>
 
</table>
</html>

So, which part are you having trouble with? The code you showed is to show the titles and data.
You need to add a form around all of the table so the data is “postable”! You need to post it back to
the same page. Inside the PHP code at the top of the page before your HTML code, you need to handle
the checkboxes sent back in the post. You use a simple “foreach” loop to go thru all of the filenames
that the user selected.

Now to create a zipped file of PDF’s and DOC’s is a bit more tricky. First, you need to have code to pull
each name from the for-each loop and load each file into one large zip file. Here is a tutorial page on how
to create the zipped file. There is one spot where the “valid-files” array is created. that is where you would
use your for-each loop to pull each filename and place it into this array.
http://davidwalsh.name/create-zip-php

Once you finish that part, you can use a simple download button or place it into the creation code to send
the file automatically. The way I do it is to send the finished product when they press the button. So, the
button would post to the page and the PHP code at the top of the page would create the zip and send it.
(No need for two buttons…)

So, there are some ideas how to start. Once you get it working, let us know if you have other issues…

Sponsor our Newsletter | Privacy Policy | Terms of Service