Need Help with data sorting

--000e0cd1383afd1027047e7327ac
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

I have a database of MP3s in mysql and I have created a php search engine.
Now I want to sort it in ascending or descending order if user clicks on th=
e
title of the table. For example if user want to arrange the table in
ascending or descending order by Name, Size, or by any other field. Also, I
am unable to arrange the table properly. Please help me....?? Below is the
code.

Type =3D Rock, Pop etc.
Url =3D file url
Name=3D Name of the song
Size =3D size

************************************************************ ***************=
************************************************************ *****

<?php


//get data
$button =3D $_GET['submit'];
$search =3D $_GET['search'];


$s =3D $_GET['s'];
if (!$s)
$s =3D 0;


$e =3D 30; // Just change to how many results you want per page


$next =3D $s + $e;
$prev =3D $s - $e;




if (strlen($search)<=3D2)
echo "Must be greater then 3 chars";
else
{
echo "
<table><tr><td><font face=3D'sana-serif' size=3D'10'><font
color=3D'blue'> <b>Mymp3</b></b><font face=3D'sana-serif'
size=3D'3'>®</td><td><form action=3D'search.php' method=3D'GET'><input
type=3D'text' onclick=3Dvalue=3D'' size=3D'50' name=3D'search' value=3D'$se=
arch'> <input
type=3D'submit' name=3D'submit' value=3D'Search'></form></td></tr></table>"=
;

//connect to database
mysql_connect("localhost","root","");
mysql_select_db("mp3");

//explode out search term
$search_exploded =3D explode(" ",$search);

foreach($search_exploded as $search_each)
{

//construct query
$x++;
if ($x=3D=3D1)
$construct .=3D "name LIKE '%$search_each%'";
else
$construct .=3D " OR name LIKE '%$search_each%'";

}

//echo outconstruct
$constructx =3D "SELECT * FROM mp3 WHERE $construct";

$construct =3D "SELECT * FROM mp3 WHERE $construct ORDER BY se DESC LIMIT
$s,$e ";
$run =3D mysql_query($constructx);

$foundnum =3D mysql_num_rows($run);


$run_two =3D mysql_query("$construct");

if ($foundnum=3D=3D0)
echo "No results found for <b>$search</b>";
else
{
echo "<table bgcolor=3D'#0000FF' width=3D'100%' height=3D'1px'><br
/></table><table bgcolor=3D'#f0f7f9' width=3D'100%' height=3D'10px'><tr><td=
><div
align=3D'right'>Showing 1-20 of <b>$foundnum</b> results found for
<b>$search.</b></div></td></tr></table><p>";

echo "<table bgcolor=3D'#0000FF' width=3D'100%' height=3D'1px'><br
/></table><table bgcolor=3D'#f0f7f9' width=3D'100%' height=3D'10px'><tr><td=
><font
face=3D'sana-serif' size=3D'3'>
            &nb=
sp;            =
      Type
<b>            =
            &nb=
sp;      
Name</b>
            &nb=
sp;            =
            &nb=
sp;            =
            
            &nb=
sp;            =
            &nb=
sp; 
          Size
</div></td></tr></table><p>";

while ($runrows =3D mysql_fetch_assoc($run_two))
{
//get data
$type =3D $runrows['type'];
$date =3D $runrows['date'];
$url =3D $runrows['url'];
$name =3D $runrows['name'];
$size =3D $runrows['size'];


print '<table width=3D"800" border=3D"0" align=3D"center" >';

print '<td><font color=3D"blue">'."$type".'</font></td>';


//print '<td><font color=3D"blue">'."http://localhost/mymp3/"."<a
herf=3D'$url'>$name".'</font></td>';


print '<td><font color=3D"blue">'."<a href=3D'$url'>$name".'</font></td=
>';


print '<td><font color=3D"blue">'."$size".'</font></td>';



print '</tr>';

print '</tr>';
print '</table>';

/* echo "<table width=3D'300px' height=3D'10px'>
<h4> <font color=3D'blue'>$type --> $name</font><b><br>Size: $size
</b></a>

<font color=3D'00CC00'>Date Added: $date</font></table></h4>
"; */
}
?>

<table width=3D'100%'>
<tr>
<td>
<div align=3D"center">
<br><br>
<?php
if (!$s<=3D0)
echo "<a href=3D'search.php?search=3D$search&s=3D$prev'>Prev</a>";

$i =3D1;
for ($x=3D0;$x<$foundnum;$x=3D$x+$e)
{


echo " <a href=3D'search.php?search=3D$search&s=3D$x'>$i</a> ";


$i++;


}

if ($s<$foundnum-$e)
echo "<a href=3D'search.php?search=3D$search&s=3D$next'>Next</a>";

}
}


?>
</div>
</td>
</tr>
</table>

--
Guru Prasad
Ubuntu Voice GTK+ Forum

--000e0cd1383afd1027047e7327ac--
Nagendra Prasad [ So, 31 Januar 2010 11:15 ] [ ID #2030731 ]

Re: Need Help with data sorting

--001636b14603f69e49047e76cfbe
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hello,

I a not clear why are u using so many tables, and also div's within the
table. Either use tableless (css tables ) or simply use table(preferably
one) without divs in it
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
regds
amit

"The difference between fiction and reality? Fiction has to make sense."


On Sun, Jan 31, 2010 at 3:45 PM, nagendra prasad
<nagendra802000 [at] gmail.com>wrote:

> Hi,
>
> I have a database of MP3s in mysql and I have created a php search engine=
..
> Now I want to sort it in ascending or descending order if user clicks on
> the
> title of the table. For example if user want to arrange the table in
> ascending or descending order by Name, Size, or by any other field. Also,=
I
> am unable to arrange the table properly. Please help me....?? Below is th=
e
> code.
>
> Type =3D Rock, Pop etc.
> Url =3D file url
> Name=3D Name of the song
> Size =3D size
>
>
> ************************************************************ *************=
************************************************************ *******
>
> <?php
>
>
> //get data
> $button =3D $_GET['submit'];
> $search =3D $_GET['search'];
>
>
> $s =3D $_GET['s'];
> if (!$s)
> $s =3D 0;
>
>
> $e =3D 30; // Just change to how many results you want per page
>
>
> $next =3D $s + $e;
> $prev =3D $s - $e;
>
>
>
>
> if (strlen($search)<=3D2)
> echo "Must be greater then 3 chars";
> else
> {
> echo "
<table><tr><td><font face=3D'sana-serif' size=3D'10'><font
> color=3D'blue'> <b>Mymp3</b></b><font face=3D'sana-serif'
> size=3D'3'>®</td><td><form action=3D'search.php' method=3D'GET'><inpu=
t
> type=3D'text' onclick=3Dvalue=3D'' size=3D'50' name=3D'search' value=3D'$=
search'>
> <input
> type=3D'submit' name=3D'submit' value=3D'Search'></form></td></tr></table=
>";
>
> //connect to database
> mysql_connect("localhost","root","");
> mysql_select_db("mp3");
>
> //explode out search term
> $search_exploded =3D explode(" ",$search);
>
> foreach($search_exploded as $search_each)
> {
>
> //construct query
> $x++;
> if ($x=3D=3D1)
> $construct .=3D "name LIKE '%$search_each%'";
> else
> $construct .=3D " OR name LIKE '%$search_each%'";
>
> }
>
> //echo outconstruct
> $constructx =3D "SELECT * FROM mp3 WHERE $construct";
>
> $construct =3D "SELECT * FROM mp3 WHERE $construct ORDER BY se DESC LIMI=
T
> $s,$e ";
> $run =3D mysql_query($constructx);
>
> $foundnum =3D mysql_num_rows($run);
>
>
> $run_two =3D mysql_query("$construct");
>
> if ($foundnum=3D=3D0)
> echo "No results found for <b>$search</b>";
> else
> {
> echo "<table bgcolor=3D'#0000FF' width=3D'100%' height=3D'1px'><br
> /></table><table bgcolor=3D'#f0f7f9' width=3D'100%' height=3D'10px'><tr><=
td><div
> align=3D'right'>Showing 1-20 of <b>$foundnum</b> results found for
> <b>$search.</b></div></td></tr></table><p>";
>
> echo "<table bgcolor=3D'#0000FF' width=3D'100%' height=3D'1px'><br
> /></table><table bgcolor=3D'#f0f7f9' width=3D'100%' height=3D'10px'><tr><=
td><font
> face=3D'sana-serif' size=3D'3'>
>
>             &=
nbsp;           &nbs=
p;      Type
>
> <b>           &nbs=
p;            &=
nbsp;      
> Name</b>
>
>             &=
nbsp;           &nbs=
p;            &=
nbsp;           &nbs=
p;            
>
>             &=
nbsp;           &nbs=
p;            &=
nbsp; 
>           Size
> </div></td></tr></table><p>";
>
> while ($runrows =3D mysql_fetch_assoc($run_two))
> {
> //get data
> $type =3D $runrows['type'];
> $date =3D $runrows['date'];
> $url =3D $runrows['url'];
> $name =3D $runrows['name'];
> $size =3D $runrows['size'];
>
>
> print '<table width=3D"800" border=3D"0" align=3D"center" >';
>
> print '<td><font color=3D"blue">'."$type".'</font></td>';
>
>
> //print '<td><font color=3D"blue">'."http://localhost/mymp3/"."<a
> herf=3D'$url'>$name".'</font></td>';
>
>
> print '<td><font color=3D"blue">'."<a href=3D'$url'>$name".'</font></t=
d>';
>
>
> print '<td><font color=3D"blue">'."$size".'</font></td>';
>
>
>
> print '</tr>';
>
> print '</tr>';
> print '</table>';
>
> /* echo "<table width=3D'300px' height=3D'10px'>
> <h4> <font color=3D'blue'>$type --> $name</font><b><br>Size: $size
> </b></a>

> <font color=3D'00CC00'>Date Added: $date</font></table></h4>
> "; */
> }
> ?>
>
> <table width=3D'100%'>
> <tr>
> <td>
> <div align=3D"center">
> <br><br>
> <?php
> if (!$s<=3D0)
> echo "<a href=3D'search.php?search=3D$search&s=3D$prev'>Prev</a>";
>
> $i =3D1;
> for ($x=3D0;$x<$foundnum;$x=3D$x+$e)
> {
>
>
> echo " <a href=3D'search.php?search=3D$search&s=3D$x'>$i</a> ";
>
>
> $i++;
>
>
> }
>
> if ($s<$foundnum-$e)
> echo "<a href=3D'search.php?search=3D$search&s=3D$next'>Next</a>";
>
> }
> }
>
>
> ?>
> </div>
> </td>
> </tr>
> </table>
>
> --
> Guru Prasad
> Ubuntu Voice GTK+ Forum
>

--001636b14603f69e49047e76cfbe--
Amit Tandon [ So, 31 Januar 2010 15:37 ] [ ID #2030732 ]
PHP » gmane.comp.php.database » Need Help with data sorting

Vorheriges Thema: Storing images
Nächstes Thema: MIME Alternatimve Emails