Jump to content

query by 1st letter of lastname str_split??


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.