chriscloyd Posted March 28, 2007 Share Posted March 28, 2007 i wanna select all the rows in my table starting with A would I do this <?php $get_teams = mysql_query("SELECT * FROM cegl_teams WHERE name LIKE 'a' ORDER BY name ASC"); ?> Link to comment https://forums.phpfreaks.com/topic/44594-solved-select-all-rows-starting-with-a/ Share on other sites More sharing options...
spamoom Posted March 28, 2007 Share Posted March 28, 2007 Nearly there! <?php $get_teams = mysql_query("SELECT * FROM cegl_teams WHERE name LIKE 'a%' ORDER BY name ASC"); ?> You add the % as a wild card, otherwize it will only select rows where the name just equals a Link to comment https://forums.phpfreaks.com/topic/44594-solved-select-all-rows-starting-with-a/#findComment-216591 Share on other sites More sharing options...
jitesh Posted March 28, 2007 Share Posted March 28, 2007 SELECT * FROM cegl_teams WHERE name LIKE 'a%' ORDER BY name ASC" Link to comment https://forums.phpfreaks.com/topic/44594-solved-select-all-rows-starting-with-a/#findComment-216593 Share on other sites More sharing options...
chriscloyd Posted March 28, 2007 Author Share Posted March 28, 2007 i got this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/www5965/public_html/CEGL-Work/newsite/adminfiles/viewteams.php on line 12 here all the code <?php //get teams //switch on type switch($_GET['type']) { case "1": $name = $_GET['name'].'%'; $get_teams = mysql_query("SELECT * FROM cegl_teams WHERE name LIKE '$name' ORDER BY name ASC"); break; case "2": break; } while ($teams = mysql_fetch_array($get_teams)) { echo $teams['name'].'<br>'; } ?> Link to comment https://forums.phpfreaks.com/topic/44594-solved-select-all-rows-starting-with-a/#findComment-216594 Share on other sites More sharing options...
spamoom Posted March 28, 2007 Share Posted March 28, 2007 <?php //get teams //switch on type switch($_GET['type']) { case "1": $name = $_GET['name'].'%'; $get_teams = mysql_query("SELECT * FROM cegl_teams WHERE name LIKE '{$name}' ORDER BY name ASC"); break; case "2": break; } while ($teams = mysql_fetch_array($get_teams)) { echo $teams['name'].'<br>'; } ?> You need to add the { } around $name Link to comment https://forums.phpfreaks.com/topic/44594-solved-select-all-rows-starting-with-a/#findComment-216595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.