-1

Hello ive made a loop for abc chars

But the problem now is, that the # dont select all the titles with special chars/numbers.

<?PHP
$page_nav = array();
$r = 35;
$rr = chr($r);
for($i = 97; $i <= 122; ++$i )
{ 
    $l = chr($i);
    $page_nav[] = ($l == mysql_real_escape_string($_GET['order'])) ? "<li class='aktiv'>".$l."</li>" : "<li><a href='index.php?s=all-movies&order=".$l."&site=1'>".$l."</a></li>"; 
} 
echo implode(' ', $page_nav);
echo ($rr == mysql_real_escape_string($_GET['order'])) ? "<li class='aktiv'>".$rr."</li>" : "<li><a href='index.php?s=all-movies&order=".$rr."&site=1'>".$rr."</a></li>"; 
?>

My Query:

$sqlCmdSearch="SELECT id,name,title,countryyear,type,hoster,cover,picturequality,language,rating,date FROM topmovies.movies WHERE status='online' AND type='movie' AND title LIKE '".mysql_real_escape_string($_GET['order'])."%' GROUP BY title ORDER BY title";
4

2 回答 2

1

Like i said in my comment, index.php?s=all-movies&order=#&site=1 is equal to index.php?s=all-movies&order=.

Try urlencode and if $order is # just remove title LIKE expression from your query
To get all title with special chars use REGEXP expression

See this answer

<?php
  $order    = ( isset( $_GET["order"] ) ) ? strtolower( mysql_real_escape_string( trim( $_GET["order"] ) ) ) : "#";
  $order    = ( !$order ) ? chr( 35 ) : $order;

  $page_nav = array();
  $chars    = array_merge( range( "a", "z" ), array( chr( 35 ) ) );

  foreach( $chars as $chr ) {
    $page_nav[] = ( $chr === $order ) ? "<li class='aktiv'>".$chr."</li>" : "<li><a href='index.php?s=all-movies&order=".urlencode( $chr )."&site=1'>".$chr."</a></li>"; 
  }
  echo implode( "\n", $page_nav );

  $sqlCmdSearch = "
    SELECT `id`, `name`, `title`, `countryyear`, `type`, `hoster`, `cover`, `picturequality`, `language`, `rating`, `date`
    FROM `topmovies`.`movies`
    WHERE
      `status` = 'online'
      AND
      `type` = 'movie'
      AND
      %s
    GROUP BY `title`
    ORDER BY `title`
  ";

  if ( $order === chr( 35 ) ) {
    // This query will return all rows where title contains any non-alphanumeric characters.
    $sqlCmdSearch = sprintf( $sqlCmdSearch, "NOT `title` REGEXP '[A-Za-z]'" );
  }
  else {
    $sqlCmdSearch = sprintf( $sqlCmdSearch, "`title` LIKE '%{$order}%'" );
  }

  // now do your db query here
?>
于 2013-08-20T06:25:31.067 回答
0

With the way you are looping through the chars it can't access special chars. This is, because the special chars have higher numbers on the utf-8 table. The first 255 are all the same as the ASCII table, and this doesn't know any special chars (e.g. no ö/ä/...)
A solution would be that you create an array and wirte all the chars you want to loop over into it, and then create an foreach overt that array.

于 2013-08-20T05:24:07.910 回答