Jump to content

[SOLVED] Help with a simple query...


DBookatay

Recommended Posts

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..?

Link to comment
https://forums.phpfreaks.com/topic/86712-solved-help-with-a-simple-query/
Share on other sites

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.

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.