DBookatay Posted January 19, 2008 Share Posted January 19, 2008 I am creating a glossary of terms, and need help to execute the query. In the dB there are 4 cells, 'id', 'term', 'deffination', and 'status'. I have a nav with <a href="text.php?category=Glossary&Lrt=A">A</a> - <a href="text.php?category=Glossary&Lrt=Z">Z</a>, and want to make it if a user clicks a specific letter, all the terms that begin with that letter. Pretty simple right. I though so... Heres what I came up with: if($_GET['category'] == "Glossary") { $Ltr = ($_GET['Ltr']); $glossLtr = substr($row['term'], 0, 1); $WHERE = "glossLtr = '{$_GET['Ltr']}'"; $query = "SELECT * FROM News_Articles $WHERE"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $class = ($row_count % 2) ? $class2 : $class1; $id = $row['id']; $icon = '<img src="images/Common/Icons/new_Red.gif" />'; $glossTitle = stripslashes($row['title']); $content = stripslashes($row['content']); $pageContent .= $content; } } All I keep getting is a parse error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/.phillipina/dbookatay/carcityofdanbury.com/text.php on line 42 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.phillipina/dbookatay/carcityofdanbury.com/text.php on line 43 What to do, what to do..? Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/ Share on other sites More sharing options...
gardenrose Posted January 19, 2008 Share Posted January 19, 2008 Try with this SELECT * FROM News_Articles WHERE '$WHERE' Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/#findComment-443130 Share on other sites More sharing options...
DBookatay Posted January 19, 2008 Author Share Posted January 19, 2008 Try with this SELECT * FROM News_Articles WHERE '$WHERE' No good! http://www.carcityofdanbury.com/text.php?category=Glossary&Ltr=A Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/#findComment-443134 Share on other sites More sharing options...
AndyB Posted January 19, 2008 Share Posted January 19, 2008 Change $result = mysql_query($query); to $result = mysql_query($query) or die("error ". mysql_error(). " with query ". $query); Then you'll see the actual query that fails, and probably the solution will be obvious. Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/#findComment-443139 Share on other sites More sharing options...
ratcateme Posted January 19, 2008 Share Posted January 19, 2008 Try putting a wildcard search into your where clause. [s]$WHERE = "glossLtr = '{$_GET['Ltr']}'";[/s] $WHERE = "glossLtr LIKE('{$_GET['Ltr']}%')"; and i think you need to say Where on this line [s]$query = "SELECT * FROM News_Articles $WHERE";[/s] $query = "SELECT * FROM News_Articles WHERE $WHERE"; if($_GET['category'] == "Glossary") { $Ltr = ($_GET['Ltr']); $glossLtr = substr($row['term'], 0, 1); $WHERE = "glossLtr LIKE('{$_GET['Ltr']}%')"; $query = "SELECT * FROM News_Articles WHERE $WHERE"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $class = ($row_count % 2) ? $class2 : $class1; $id = $row['id']; $icon = '<img src="images/Common/Icons/new_Red.gif" />'; $glossTitle = stripslashes($row['title']); $content = stripslashes($row['content']); $pageContent .= $content; } } Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/#findComment-443140 Share on other sites More sharing options...
DBookatay Posted January 19, 2008 Author Share Posted January 19, 2008 Where getting there... I combined both AndyB and Scott's posts, and got this "error Unknown column 'glossLtr' in 'where clause' with query SELECT * FROM Glossary WHERE glossLtr LIKE('A%') " Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/#findComment-443142 Share on other sites More sharing options...
ratcateme Posted January 19, 2008 Share Posted January 19, 2008 You need to change the line to search the "term" Collum so $WHERE = "glossLtr LIKE('{$_GET['Ltr']}%')"; Becomes $WHERE = "term LIKE('{$_GET['Ltr']}%')"; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/#findComment-443144 Share on other sites More sharing options...
DBookatay Posted January 19, 2008 Author Share Posted January 19, 2008 You need to change the line to search the "term" Collum so $WHERE = "glossLtr LIKE('{$_GET['Ltr']}%')"; Becomes $WHERE = "term LIKE('{$_GET['Ltr']}%')"; Scott. Thats it, thanks Scott! Quote Link to comment https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/#findComment-443145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.