Tuesday 24 March 2015

PHP _Script_ to_ select _multiple _ids _from _mysql database

(1)<?php


$coursename=$_POST['coursename'];


$semester=$_POST['semester'];

echo '<h3>';

echo '<table border=0>';

echo '<tr> <td>';
echo "CourseName&nbsp;=".$coursename;

echo '</td> <td>&nbsp;&nbsp;&nbsp;</td>';

echo '<td>';

echo "Semester&nbsp;=".$semester;

echo '</td></tr>';
echo '</table>';

echo '</h3>';

$con=mysql_connect("localhost","root","");



mysql_select_db("itexam",$con);


$sql="select * from   notes    where   coursename='$coursename'    AND semester='$semester'  order by subject";


$result=mysql_query($sql) or die(mysql_error());

echo '<h4>';
echo '<table border=0>';

echo '<tr><td>id</td><td><h2>Subject Name </h2></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><h2>Unit </h2></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td> <td> <h2>Download Link</h2></td></tr>';

;
echo '<form action="downloadall.php" method=post>';
while($row=mysql_fetch_array($result))

{


echo ' <tr><td><input type=checkbox  name=data[]  value="'.$row['id'].'"></td><td>"'.$row['subject'].'" </td><td>&nbsp;</td><td>"'.$row['unit'].'" </td><td>&nbsp;</td>
<td>
<button ><a href=../proudct_images/download1.php?download_file="'.$row['file'].'">
Download file</a></button> </td></tr>';










}
echo '</table>';


echo '

     <input type=submit  name=submit value=Download-all>

</form>';

?>

(2)



<?php



//$data=$_POST['data'];



//$test=implode(',',$data);

//echo $test;

include("connect.php");


//$sql="select  file from notes where id IN('$test')";




$ids=$_POST['data'];



$num_list=implode(',', $ids);







echo $sql = "select * FROM notes WHERE  id IN($num_list)";




$result=mysql_query($sql) or die(mysql_error());



while($row=mysql_fetch_array($result))

{



echo '<a href=../proudct_images/download1.php?download_file="'.$row['file'].'">

Download file</a>';










}





?>




No comments:

Post a Comment