Need Help with data sorting

Need Help with data sorting

am 31.01.2010 11:15:44 von Nagendra Prasad

--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

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



//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 "

color=3D'blue'> Mymp3 size=3D'3'>®
type=3D'text' onclick=3Dvalue=3D'' size=3D'50' name=3D'search' value=3D'$se=
arch'> type=3D'submit' name=3D'submit' value=3D'Search'>
"=
;

//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==1)
$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==0)
echo "No results found for $search";
else
{
echo " />
> align=3D'right'>Showing 1-20 of $foundnum results found for
$search.

";

echo "

/>
> face=3D'sana-serif' size=3D'3'>
            &nb=
sp;            =
      Type
            =
            &nb=
sp;      
Name

            &nb=
sp;            =
            &nb=
sp;            =
            
            &nb=
sp;            =
            &nb=
sp; 
          Size

";

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 '

';

print '';


//print '';


print '';



print '';

print '';
print '
'."$type".' '."http://localhost/mymp3/"." herf=3D'$url'>$name".' '."$name".' >';


print '
'."$size".'
';

/* echo "

$type --> $name
Size: $size


Date Added: $date


"; */
}
?>










if (!$s<=3D0)
echo "";

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


echo " ";


$i++;


}

if ($s<$foundnum-$e)
echo "";

}
}


?>



--=20
Guru Prasad
Ubuntu Voice GTK+ Forum

--000e0cd1383afd1027047e7327ac--

Re: Need Help with data sorting

am 31.01.2010 15:37:27 von Amit Tandon

--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
============
regds
amit

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


On Sun, Jan 31, 2010 at 3:45 PM, nagendra prasad
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
>
>
> ************************************************************ *************=
************************************************************ *******
>
> >
>
> //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 "

>";
>
> //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==1)
> $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==0)
> echo "No results found for $search";
> else
> {
> echo "
> color=3D'blue'> Mymp3 > size=3D'3'>®
t
> type=3D'text' onclick=3Dvalue=3D'' size=3D'50' name=3D'search' value=3D'$=
search'>
> > type=3D'submit' name=3D'submit' value=3D'Search'>
> />
<=
td> > align=3D'right'>Showing 1-20 of $foundnum results found for
> $search.

";
>
> echo "

> />
<=
td> > face=3D'sana-serif' size=3D'3'>
>
>             &=
nbsp;           &nbs=
p;      Type
>
>            &nbs=
p;            &=
nbsp;      
> Name

>
>             &=
nbsp;           &nbs=
p;            &=
nbsp;           &nbs=
p;            
>
>             &=
nbsp;           &nbs=
p;            &=
nbsp; 
>           Size
>

";
>
> 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 '

';
>
> print '';
>
>
> //print '';
>
>
> print '';
>
>
>
> print '';
>
> print '';
> print '
'."$type".''."http://localhost/mymp3/"." > herf=3D'$url'>$name".''."$name".' d>';
>
>
> print '
'."$size".'
';
>
> /* echo "
>

$type --> $name
Size: $size
>


> Date Added: $date


> "; */
> }
> ?>
>
>
>
>
>
>

>

>


> > if (!$s<=3D0)
> echo "";
>
> $i =3D1;
> for ($x=3D0;$x<$foundnum;$x=3D$x+$e)
> {
>
>
> echo " ";
>
>
> $i++;
>
>
> }
>
> if ($s<$foundnum-$e)
> echo "";
>
> }
> }
>
>
> ?>
>

>

>
> --
> Guru Prasad
> Ubuntu Voice GTK+ Forum
>

--001636b14603f69e49047e76cfbe--