Jump to content

query by 1st letter of lastname str_split??


harkly

Recommended Posts

I want to have a query that pulls names by the 1st letter only. I have a table with 4000 names in it and I want to query the last names and have only the ones that start with "A" or even "Aa" pull up. I am pretty new to this php/mysql and not sure what approach to take. I know it can be done but not sure how. Can someone give me a bit of direction?

 

Should I use a str_split??

Can you explain that a bit further, not sure how "strtoupper" is being used? Very new at this.

 

Can I put it in a while?

 

Here's my code,

 

$search=$_GET["alphabet"];

$result = mysql_query("SELECT * FROM artist WHERE lastname like 'A'");

$count = count(0);

            while ($r=mysql_fetch_array($result))
              {	

   $fullName=$r["fullName"];

   $lastName=$r["lastName"];

   $dob=$r["dob"];

   $dod=$r["dod"];

   $nationality =$r["nationality"];

   $choosen_medium=$r["artForm"];
   $artid=$r["artid"];

   

   //display the row
                  echo $count++;

echo ". ".$fullName.", ".$dob."-".$dod."  <br><br>";
}

 

 

I was thinking I might need to split my list up further then A, B and use Aa - Am, An-Az

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.