Jump to content

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.

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.