Jump to content

Dictionary script


The Praetorian

Recommended Posts

I'm using the script someone gave me for a dictionary/encyclopedia of sorts. One page has a list of all the links matching that letter while the other page is where it goes to show the entry for the link they click. What I can't figure out is how to make the page that I point those links at work properly. At the moment all it does is spit out all the entries in the database. Here's the script for that page.

<?php						ob_start(); $dbh=mysql_connect ("localhost", "author_author", "****") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("author_localhost");  $result = mysql_query ("SELECT * FROM dictionary WHERE word LIKE '$_GET[word]%'") or die(mysql_error());  $r = mysql_fetch_array($result);  while($r = mysql_fetch_array($result))  {	echo '<h2>'.$r['word'].'</h2>';	if ($r['category'] != "")	  echo '<span class="blue">Category</span> <b>:</b> '.$r['category'].'<br />';	if ($r['pronounce'] != "")	  echo '<span class="blue">Pronunciation</span> <b>:</b> '.$r['pronounce'].'<br />';	if ($r['definition'] != "")	  echo ''.$r['definition'].'<br />';	if ($r['definitiontwo'] != "")	  echo ''.$r['definitiontwo'].'<br />';	if ($r['related'] != "")	  echo '<span class="blue">Related Entries</span> <b>:</b> '.$r['related'].'<br />';	  echo "<br />";	  echo "<title>The Shattered Realms ~ Search: $r[word]</title>";  }?>

The problem I'm having with the other script is that, although the links all come out fine, when I click one and it switches pages, the php?s= part doesn't show the whole entry for multiple word entries. Instead of doing the+something it only shows "the" in the link. Here's the code for that one.

<?php$dbh=mysql_connect ("localhost", "author_author", "*****") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("author_localhost");$letter = $_GET["letter"];$q = mysql_query("SELECT * FROM dictionary WHERE word LIKE '$_GET[letter]%'");while($row = mysql_fetch_array($q)) {	 echo "<a href=dictionary.php?s=$row[word]>$row[word]</a> <br /> ";}?>

Link to comment
Share on other sites

Your PHP to generate the links is:

echo "<a href=dictionary.php?s=$row[word]>$row[word]</a> <br /> ";

This will render HTML that looks like this:

<a href=dictionary.php?s=the something>the something</a> <br />

Where it'd need to be more like this:

<a href="dictionary.php?s=the something">the something</a> <br />

So try adding quotes around the href parameter in the PHP like so:

echo "<a href=\"dictionary.php?s=$row[word]\">$row[word]</a> <br /> ";

You may also look into URL encoding the "$row[word]" so that the spaces are converted to plusses in case the browsers don't do that automatically.I hope this helps!

Link to comment
Share on other sites

Hmm, if you are passing the query to that page using an "s" parameter, then wouldn't you need to change:

SELECT * FROM dictionary WHERE word LIKE '$_GET[word]%'

To:

SELECT * FROM dictionary WHERE word LIKE '$_GET[s]%'

I think it was returning all results because $_GET[word] was empty and the query looked like this:

SELECT * FROM dictionary WHERE word LIKE '%'

Link to comment
Share on other sites

Hmm, if you are passing the query to that page using an "s" parameter, then wouldn't you need to change:
SELECT * FROM dictionary WHERE word LIKE '$_GET[word]%'

To:

SELECT * FROM dictionary WHERE word LIKE '$_GET[s]%'

I think it was returning all results because $_GET[word] was empty and the query looked like this:

SELECT * FROM dictionary WHERE word LIKE '%'

It's more like
query = "SELECT * FROM dictionary WHERE word LIKE '" . $_GET['s']% . "'"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...