Hello, newbie here

I'm using PHP and mysql so when you click on a link that says A, you get all the titles that start with A and so on. my current code below is working properly for those started with alphabet. but as the data grows, some of them are started with numbers.

<a href="movie.php?id=A">A</a>
<a href="movie.php?id=B">B</a>
<a href="movie.php?id=C">C</a> and so on...


<?php 
include "global_var.php";
             
if (!isset($_REQUEST['id']))
{
$id = "A";
}

else
{
$id=$_REQUEST['id'];
}

$dbtabl = 'tbl_movie'; 
$conn = mysql_connect($db["host"], $db["user"], $db["password"]);
mysql_selectdb($db["database"]);

//query the database 
$query = "SELECT id_movie,ori_title,alt_title FROM tbl_movie where ori_title like '".$id."%' or alt_title like '".$id."%' order by ori_title asc";

$result = mysql_query($query, $conn) or die("Invalid query: " . mysql_error());
$i=0;
while ($row=mysql_fetch_row($result)) 
{
if (strtolower($id)==substr(strtolower($row[1]),0,1))
{
$title[$i]=$row[1].'|'.$row[0];

$i++;
}
else
{
$title[$i]=$row[2].'|'.$row[0];

$i++;
}
}
               
sort($title);
$n=0;

//if no title found
if ($i==0)
{
echo "Data not found<p>&nbsp;</p>";
}
        
//end no data
                      
foreach ($title as $key => $val)
{
list($strtitle,$strid)=split('[|]',$val);
        echo "<p><a href=\"movie_content.php?id=$strid\">";
        echo htmlspecialchars($strtitle);
        echo "</a></p>";
}

?>

I wanted the data to display those started with numbers when someone clicked "#" sign.

<a href="movie.php?id=#">#</a>

can anyone help me on this?
thanks

you mean i have to change all of that code or simply just change this line:

//query the database 
$query = "SELECT id_movie,ori_title,alt_title FROM tbl_movie where ori_title like '".$id."%' or alt_title like '".$id."%' order by ori_title asc";

with the one you suggested?

Add that one if you request numbers, otherwise use the one you have.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.