user4fun Posted June 28, 2007 Share Posted June 28, 2007 $Letter= c ;i need a statment that would look in table Main column 'names' and the records that have the fifith letter to match the $Letter.or if there is any other ideasAll the records in the 'names' column start with www.i want to find all the names that i have listed ( obviously websites) to match the $Letter ( hence the fifth letter )how can i do that.examplewww.charleybrown.comwould come up if $Letter = c Link to comment Share on other sites More sharing options...
vijay Posted June 28, 2007 Share Posted June 28, 2007 Hi... You can check 5th letter='c' in column 'name' via following query:Query1: "select if (substring(name,5,1)='c',1,0) as cThere from tblName;" this query will return 1 if c present as 5th and 0 if not. and for starting name with 'www' for that Query2: select * from tblName where name='www%' suppose this will help you..Regards,Vijay Link to comment Share on other sites More sharing options...
user4fun Posted June 28, 2007 Author Share Posted June 28, 2007 this is what i have so far.not working thoughconfimred = the table that has the infromation $result = mysql_query("SELECT Website,Email FROM confirmed"); echo "<table border='1'><tr><th>Website</th><th>Email</th></tr>";while($row = mysql_fetch_array($result)) { $rest = substr($row['Website'], 5, 1); if ($rest == c) { echo "<td>" . $row['Website'] . "</td>"; echo "<td>" . $row['Email'] . "</td>"; } else { echo " "; }echo "</tr>"; }echo "</table>"; Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2007 Share Posted June 28, 2007 This query will return all records where the first 5 characters are "www.<letter>": $sql = "SELECT Website, Email FROM confirmed WHERE Website LIKE 'www.{$letter}%'"; You don't need to do any additional checking with PHP. Link to comment Share on other sites More sharing options...
user4fun Posted June 28, 2007 Author Share Posted June 28, 2007 $letter= "o"; $sql = "SELECT Website, Email FROM confirmed WHERE Website LIKE 'www.{$letter}%'";echo "<table border='1'><tr><th>Website</th><th>Email</th></tr>";while($row = mysql_fetch_array($result)) { echo "<td>" . $row['Website'] . "</td>"; echo "<td>" . $row['Email'] . "</td>"; echo "</tr>"; }echo "</table>";I am not getting any results back, the table shows up but it is empty?i know there are entries starting with letter o Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2007 Share Posted June 28, 2007 Well you never sent the query to the database, that will probably help. Link to comment Share on other sites More sharing options...
user4fun Posted June 28, 2007 Author Share Posted June 28, 2007 it is a good idea, but unfortunatly i did. That part is skipped out because it has username, password information. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2007 Share Posted June 28, 2007 Between this:$sql = "SELECT Website, Email FROM confirmed WHERE Website LIKE 'www.{$letter}%'";and this:while($row = mysql_fetch_array($result))you don't do anything with the database. If you are actually doing that and just decided not to include it, run the query on the database server and see what it is doing. Link to comment Share on other sites More sharing options...
user4fun Posted June 29, 2007 Author Share Posted June 29, 2007 What is it that need to be done, here is the full code $link = mysql_connect("mysql", " ", " ") or die ("No connection"); mysql_select_db("business") or die ("no database"); $letter= "o"; $result = "SELECT Website, Email FROM confirmed WHERE Website LIKE 'www.{$letter}%'";echo "<table border='1'><tr><th>Website</th><th>Email</th></tr>";while($row = mysql_fetch_array($result)) { echo "<td>" . $row['Website'] . "</td>"; echo "<td>" . $row['Email'] . "</td>"; echo "</tr>"; }echo "</table>";?>more stuff</td> </tr> </table> </center></div><?include ("../main_btm1.php");?> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 29, 2007 Share Posted June 29, 2007 You need to use the mysql_query function to send the query to the database and get the result back. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.