Jump to content

Need Some PHP Advice


The Praetorian

Recommended Posts

Right. So I'm using this php/sql script for a dictionary/search engine. I'm doing all the tables from mysql. Here's what it looks like now. Search EngineAs you can see, I've inserted html for each of the fields that I've created on phpmyadmin. What I want to do (or at least find out if it's possible) is insert some more php to make it so that, if the field is blank, the html associated with that field won't appear.Again, not sure if that's possible. Or I may need to use javascript.Other question. Can I even use html in the actual sql script that makes up the entry? (The stuff that appears when $s[item] is processed into a block of text/int/varchar.) Right now I'm just inserting the html in between and around the $s[item] stuff, but it would be much easier if I could insert it straight in when I'm putting the information into that table.Thanks ahead of time for any help. Let me know if you need to see the php I'm using.

Link to comment
Share on other sites

if the field is blank, the html associated with that field won't appear.
Use an if control statement to check whether the contents of $s['item'] is NOT empty or "blank" and bypass the html creation code. If you post the code-block, someone might be able to guide you further if neccesary.
if ( !empty($s['item'])) {// -- add html creation code here} // <!-- end !empty() if -->// -- this code gets acted upon regardless

Can I even use html in the actual sql script that makes up the entry? (The stuff that appears when $s[item] is processed into a block of text/int/varchar.) Right now I'm just inserting the html in between and around the $s[item] stuff, but it would be much easier if I could insert it straight in when I'm putting the information into that table.
If I understand you correctly, you want the data in your database to include the HTML? Allowing for HTML in the data can be done, but you would need to 'massage' the data before placing it into a Database and again when it was retreived and output to the Browser. Security of the code might be an issue. Consider the implications carefully.
Link to comment
Share on other sites

Hm. Right. First things first. Code.

<?php$db = mysql_connect("dbname", "username", "password");mysql_select_db("localhost",$db);$search_string = $_GET['s'];$result = mysql_query ("SELECT * FROM dictionary WHERE word LIKE '%$search_string%' ORDER BY word ASC") or die(mysql_error());while ($r = mysql_fetch_array($result)){echo "<h2>$r[word]</h2><br /><span class='blue'>Class:</span> $r[class]<br /><span class='blue'>Pronunciation:</span> $r[pronounce]<br />$r[definition]<br /><span class='blue'>Related Entries:</span> $r[related]";}?>

As far as security is concerned it's not that much of an issue for this project. I'm only using this code for a dictionary type application for an rpg, and I keep the stuff backed up all the time. But yea. I'd prefer to do it with an if statement if I could, that would output the desired html if the field had something in it and nothing if not.

Link to comment
Share on other sites

the way i've been doing this is to use an if statement to put the HTML in the code AFTER it's out of the database. is that what you meant?

if ( !empty($r)){  $word = '<h2>'.$r['word'].'</h2><br/>';  $class = '<span class='blue'>Class:</span>'.$r['class'].'<br />';//etc, etc...}echo $word.$class.$pronounce;

you can put additional "if" statements in to allow for an item to be blank, like your "related terms" section. you can have that variable contain nothing so it won't output a blank span...

$word = '';//query the databaseif( !empty($r['word'])){  $word = '<h2>'.$r['word'].'</h2><br/>';}

i hope i'm on the same page as you are. i think this is what you were asking...love,jason

Link to comment
Share on other sites

you could just addelse{ $word = ''; }...i'm not sure if you need it. i run several of these in my scripts without problems, and i don't have the else statement in there. i believe if the condition doesn't exist, it just passes over the code associated with the if......however, there is the possibility that an error is occurring that simply doesn't break the script. does anyone know for sure?love,jason

Link to comment
Share on other sites

Hm. Something about that has to be wrong. I added the code, but it's giving me a parse error. "Unexpected t_string". Here's the code as I edited it.

<?php$db = mysql_connect("localhost", "username", "password");mysql_select_db("localhost",$db);$search_string = $_GET['s'];$result = mysql_query ("SELECT * FROM dictionary WHERE word LIKE '%$search_string%' ORDER BY word ASC") or die(mysql_error());while ($r = mysql_fetch_array($result))if ( !empty($r)){  $word = '<h2>'.$r['word'].'</h2><br />';  $category = '<span class='blue'>Class:</span> '.$r['category'].'<br />';  $pronounce = '<span class='blue'>Pronunciation:</span> '.$['pronounce'].'<br />';  $definition = '<span class='blue'>Definition:</span> '.$['definition'].'<br />';  $related = '<span class='blue'>Related Entries:</span> '.$['related'].'<br />';  }echo "{$r[word]$r[class]$r[pronounce]$r[definition]$r[related]";}?>

Link to comment
Share on other sites

if ( !empty($r)){  $word = '<h2>'.$r['word'].'</h2><br />';  $category = '<span class="blue">Class:</span> '.$r['category'].'<br />';  $pronounce = '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';  $definition = '<span class="blue">Definition:</span> '.$r['definition'].'<br />';  $related = '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';}else  $word = $class = $pronounce = $definition = $related = "";echo "$word$class$pronounce$definition$related";?>

You left out several 'r's in the top block (check your code), and had some unnecessary brackets near the echo. You also were using the same quotes in the top block to enclose the string, and also inside the string. Either use different quotes (I changed the inside quotes to double quotes), or escape the quotes in the string.

Link to comment
Share on other sites

Okay. Now I'm getting some different results. Before, when I hit search with nothing in the search field, all the entries in the table would output in alphabetical order. Now, hitting search only outputs the very last item in the table. Before, if I hit search with just a single letter (a, b and so on) all the entries that start with that letter would output. Not now. In fact, if I just enter a single letter, again only the last entry outputs.

Link to comment
Share on other sites

Oh yeah, you have a while loop there don't you? You're only seeing the last one because it only executes the echo once, and the last thing to get set was the last item in the database result. I wrapped what I did inside your while loop, so this should do it:

while ($r = mysql_fetch_array($result)){  if ( !empty($r))  {	$word = '<h2>'.$r['word'].'</h2><br />';	$category = '<span class="blue">Class:</span> '.$r['category'].'<br />';	$pronounce = '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';	$definition = '<span class="blue">Definition:</span> '.$r['definition'].'<br />';	$related = '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';  }  else	$word = $class = $pronounce = $definition = $related = "";    echo "  $word  $class  $pronounce  $definition  $related  ";}

But that can be shortened to just this:

while ($r = mysql_fetch_array($result)){  $word = '<h2>'.$r['word'].'</h2><br />';  $category = '<span class="blue">Class:</span> '.$r['category'].'<br />';  $pronounce = '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';  $definition = '<span class="blue">Definition:</span> '.$r['definition'].'<br />';  $related = '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';    echo $word . $category . $pronounce . $definition . $related;}

Link to comment
Share on other sites

Okay. So that fixed that. Back to the main reason I wanted all the extra stuff though. heh. How can I make it so that, if one of the fields ([word][definition] and so on) is blank, the html won't show up? Because as of now the html is still showing up even though there's nothing in those fields.Or would it make it easier if I made it so that, when it queries the db, if there's a certain entry ("blank" or whatever) it won't output that particular field and its associated html?

Link to comment
Share on other sites

You can either do it in the PHP or SQL. This would be the SQL:

"SELECT * FROM dictionary WHERE word LIKE '%$search_string%' AND class != '' AND pronounce != '' AND definition != '' AND related != '' ORDER BY word ASC"

And this is how you would do it in PHP:

while ($r = mysql_fetch_array($result)){  foreach ($r as $val)  {	if ($val == "")	  continue 2;  }  $word = '<h2>'.$r['word'].'</h2><br />';  $category = '<span class="blue">Class:</span> '.$r['category'].'<br />';  $pronounce = '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';  $definition = '<span class="blue">Definition:</span> '.$r['definition'].'<br />';  $related = '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';    echo $word . $category . $pronounce . $definition . $related;}

Link to comment
Share on other sites

Okay. I tried the different sql query. That didn't work. It only produced the latter half (s's on) of the entries. Even entering exact words didn't bring out the earlier entries. On the other hand, it did do what I was looking for. (Making the sections without anything in them invisible.)The second code didn't work at all. Gave me a parse error."Parse error: parse error, unexpected $end in C:\Program Files\xampp\htdocs\dictionary.php on line 99" Line 99 is my </html>..

Link to comment
Share on other sites

<?php$db = mysql_connect("localhost", "****", "****");mysql_select_db("localhost",$db);$search_string = $_GET['s'];$result = mysql_query ("SELECT * FROM dictionary WHERE word LIKE '%$search_string%' AND category != '' AND pronounce != '' AND definition != '' AND related != '' ORDER BY word ASC") or die(mysql_error());while ($r = mysql_fetch_array($result)){  foreach ($r as $val)  {	if ($val == "")	  continue 2;  }  $word = '<h2>'.$r['word'].'</h2><br />';  $category = '<span class="blue">Category:</span> '.$r['category'].'<br />';  $pronounce = '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';  $definition = '<span class="blue">Definition:</span> '.$r['definition'].'<br />';  $related = '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';    echo $word . $category . $pronounce . $definition . $related;?>

Link to comment
Share on other sites

OK, let's debug.

$db = mysql_connect("localhost", "****", "****");mysql_select_db("localhost",$db);$search_string = $_GET['s'];echo "search string: '$s'<br>";$result = mysql_query ("SELECT * FROM dictionary WHERE word LIKE '%$search_string%' ORDER BY word ASC") or die(mysql_error());echo mysql_num_rows($result) . " results from db<br>";while ($r = mysql_fetch_array($result)){  echo "checking {$r['word']}<br>";  foreach ($r as $key => $val)  {	if ($val == "")	{	  echo "blank key found: {$key}, moving on<br>";	  continue 2;	}  }  $word = '<h2>'.$r['word'].'</h2><br />';  $category = '<span class="blue">Category:</span> '.$r['category'].'<br />';  $pronounce = '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';  $definition = '<span class="blue">Definition:</span> '.$r['definition'].'<br />';  $related = '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';    echo $word . $category . $pronounce . $definition . $related;}

Try that. I also changed the SQL statment to remove the extra conditions, that might have been messing it up and returning no results. The check for blanks is in the while loop though.

Link to comment
Share on other sites

Okay. This is what I got when I hit enter on a blank field with that script. Hopefully you can make sense of it...search string: ''38 results from dbchecking Anchoringblank key found: 3, moving onchecking Bloodsportblank key found: 3, moving onchecking Burstblank key found: 3, moving onchecking Cadcblank key found: 5, moving onchecking Cadc Textsblank key found: 3, moving onchecking Cadmn Delosblank key found: 5, moving onchecking Cadmnian Accordblank key found: 3, moving onchecking Culture Warsblank key found: 3, moving onchecking Deep, theblank key found: 3, moving onchecking First Handblank key found: 3, moving onchecking Golden Circle, theblank key found: 3, moving onchecking Guide(s), theblank key found: 3, moving onchecking Iken, theblank key found: 5, moving onchecking Imhalaneblank key found: 5, moving onchecking Kaduin Seablank key found: 5, moving onchecking Kiil, theblank key found: 5, moving onchecking Koran'ga Jiblank key found: 5, moving onchecking Kua Niiblank key found: 5, moving onchecking Pathfinder(s)blank key found: 3, moving onchecking Pocketblank key found: 3, moving onchecking Quiltingblank key found: 3, moving onchecking Seekers, Theblank key found: 3, moving onchecking Senthk Sea, theblank key found: 5, moving onchecking Shallowsblank key found: 3, moving onchecking Shapers, Theblank key found: 3, moving onchecking Shapingblank key found: 3, moving onchecking Shard/Shard-worldblank key found: 3, moving onchecking Siymehablank key found: 5, moving onchecking Spanblank key found: 3, moving onchecking Sundered City, Theblank key found: 3, moving onchecking Tempestblank key found: 3, moving onchecking Tii alblank key found: 5, moving onchecking Tii alublank key found: 5, moving onchecking Ush'enblank key found: 5, moving onchecking Ush'iiblank key found: 5, moving onchecking Veilblank key found: 3, moving onchecking Walking shallowblank key found: 3, moving onchecking Yi al Wonblank key found: 5, moving on

Link to comment
Share on other sites

I screwed up and outputted the wrong search string, so it doesn't even say what is being search for. But it looks like everything is failing because of a blank item. Let's try this one more time, printing the correct search variable, and using print_r to just show each entire record. I'm also using mysql_fetch_assoc to get the row so it leaves out the numbered columns, and output buffering to make sure the print_r output gets displayed with html linebreaks, but that is just for testing.

ob_start();$db = mysql_connect("localhost", "****", "****");mysql_select_db("localhost",$db);$search_string = $_GET['s'];echo "search string: '$search_string'\n";$result = mysql_query ("SELECT * FROM dictionary WHERE word LIKE '%$search_string%' ORDER BY word ASC") or die(mysql_error());echo mysql_num_rows($result) . " results from db\n\n====================================\n\n";while ($r = mysql_fetch_array($result)){  print_r($r);  foreach ($r as $key => $val)  {	if ($val == "")	{	  echo "blank key found: {$key}, moving on\n";	  echo "===========================\n";	  continue 2;	}  }  $word = '<h2>'.$r['word'].'</h2><br />';  $category = '<span class="blue">Category:</span> '.$r['category'].'<br />';  $pronounce = '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';  $definition = '<span class="blue">Definition:</span> '.$r['definition'].'<br />';  $related = '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';    echo $word . $category . $pronounce . $definition . $related;  echo "===========================\n";}$output = ob_get_contents();ob_end_clean();echo nl2br($output);

Link to comment
Share on other sites

Okay. This one came with a really long output, but it did what you said it would.

search string: ''38 results from db====================================Array([0] => 4[id] => 4[1] => Anchoring[word] => Anchoring[2] => Term[category] => Term[3] =>[pronounce] =>[4] => A term to describe the process by which a Shard is tethered to another Shard. Anchoring is a secret of the Pathfinders that native shapers and Seekers have been unable to master, though not for lack of trying.[definition] => A term to describe the process by which a Shard is tethered to another Shard. Anchoring is a secret of the Pathfinders that native shapers and Seekers have been unable to master, though not for lack of trying.[5] =>[definitiontwo] =>[6] => Quilting.[related] => Quilting.)blank key found: 3, moving on===========================Array([0] => 5[id] => 5[1] => Bloodsport[word] => Bloodsport[2] => Term[category] => Term[3] =>[pronounce] =>[4] => A collection of horrifically violent sports that are popular amongst the Tii alu. Among the most prevalent is the knife-fighting sport called Kua Nii, or Short Knife.[definition] => A collection of horrifically violent sports that are popular amongst the Tii alu. Among the most prevalent is the knife-fighting sport called Kua Nii, or Short Knife.[5] =>[definitiontwo] =>[6] => Kua Nii.[related] => Kua Nii.)blank key found: 3, moving on===========================Array([0] => 6[id] => 6[1] => Burst[word] => Burst[2] => Term/Occurrence[category] => Term/Occurrence[3] =>[pronounce] =>[4] => A sudden, violent shift in the Deep. A burst can happen anywhere, even near the Veil. They can vary in power, depending on how unstable the Deep is, from mildly uncomfortable to deadly. Some bursts have been known to rearrange people walking shallow. Very rarely, a burst can even collapse a Shaper's pocket.[definition] => A sudden, violent shift in the Deep. A burst can happen anywhere, even near the Veil. They can vary in power, depending on how unstable the Deep is, from mildly uncomfortable to deadly. Some bursts have been known to rearrange people walking shallow. Very rarely, a burst can even collapse a Shaper's pocket.[5] =>[definitiontwo] =>[6] => Tempest.[related] => Tempest.)blank key found: 3, moving on===========================Array([0] => 7[id] => 7[1] => Cadc[word] => Cadc[2] => Language/Coin[category] => Language/Coin[3] => (kay-######)[pronounce] => (kay-######)[4] => Both a language and a system of money. The Cadc tongue is the traders tongue spoken throughout the Circle. The Cadc coin is the most widely used form of currency.[definition] => Both a language and a system of money. The Cadc tongue is the traders tongue spoken throughout the Circle. The Cadc coin is the most widely used form of currency.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 5, moving on===========================Array([0] => 8[id] => 8[1] => Cadc Texts[word] => Cadc Texts[2] => Historical Documents[category] => Historical Documents[3] =>[pronounce] =>[4] => A large collection of unpublished books and documents written by Cadmn Delos. Including original drafts of the Cadmnian Accord, detailed notes on the Deep and on Shaping, and intricate maps of the Sundered City as well as the parts of each Shard that he visited. While a few of these documents have been released for public viewing and copied for libraries, a good portion of these texts are considered classified by the Pathfinders, and are kept under heavy guard within the Sundered City.[definition] => A large collection of unpublished books and documents written by Cadmn Delos. Including original drafts of the Cadmnian Accord, detailed notes on the Deep and on Shaping, and intricate maps of the Sundered City as well as the parts of each Shard that he visited. While a few of these documents have been released for public viewing and copied for libraries, a good portion of these texts are considered classified by the Pathfinders, and are kept under heavy guard within the Sundered City.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 3, moving on===========================Array([0] => 9[id] => 9[1] => Cadmn Delos[word] => Cadmn Delos[2] => Historical Figure (Pathfinder)[category] => Historical Figure (Pathfinder)[3] => (kade-min dell-ohs)[pronounce] => (kade-min dell-ohs)[4] => Undoubtedly the most influential person of the last 600 years. Cadmn Delos was the First Hand of the Order, an accomplished writer and historian, an avid anthropologist, and the man who wrote the treaty which would, after his death, come to be known as the Cadmnian Accord. His effigy adorns not only the Cadc Gold Eagle, but almost a thousand statues and paintings throughout the Golden Circle.[definition] => Undoubtedly the most influential person of the last 600 years. Cadmn Delos was the First Hand of the Order, an accomplished writer and historian, an avid anthropologist, and the man who wrote the treaty which would, after his death, come to be known as the Cadmnian Accord. His effigy adorns not only the Cadc Gold Eagle, but almost a thousand statues and paintings throughout the Golden Circle.[5] =>[definitiontwo] =>[6] => Golden Circle ~ Cadmnian Accord ~ First Hand ~ Cadc Texts.[related] => Golden Circle ~ Cadmnian Accord ~ First Hand ~ Cadc Texts.)blank key found: 5, moving on===========================Array([0] => 10[id] => 10[1] => Cadmnian Accord[word] => Cadmnian Accord[2] => Historical Document/Treaty[category] => Historical Document/Treaty[3] =>[pronounce] =>[4] => The treaty and set of laws which bind the nations of the Golden Circle.[definition] => The treaty and set of laws which bind the nations of the Golden Circle.[5] =>[definitiontwo] =>[6] => Cadmn Delos ~ Golden Circle.[related] => Cadmn Delos ~ Golden Circle.)blank key found: 3, moving on===========================Array([0] => 11[id] => 11[1] => Culture Wars[word] => Culture Wars[2] => Historical Period[category] => Historical Period[3] =>[pronounce] =>[4] => A series of protracted wars between the Shard-worlds. Specifically between the nations of Tii al and Ush'en.[definition] => A series of protracted wars between the Shard-worlds. Specifically between the nations of Tii al and Ush'en.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 3, moving on===========================Array([0] => 12[id] => 12[1] => Deep, the[word] => Deep, the[2] => Term[category] => Term[3] =>[pronounce] =>[4] => A blanket term for the chaotic plane that exists outside the stability of the Shards.[definition] => A blanket term for the chaotic plane that exists outside the stability of the Shards.[5] =>[definitiontwo] =>[6] => Shallows ~ "walking shallow".[related] => Shallows ~ "walking shallow".)blank key found: 3, moving on===========================Array([0] => 13[id] => 13[1] => First Hand[word] => First Hand[2] => Rank (Pathfinders)[category] => Rank (Pathfinders)[3] =>[pronounce] =>[4] => The highest rank amongst the Pathfinders.[definition] => The highest rank amongst the Pathfinders.[5] =>[definitiontwo] =>[6] => The Seekers ~ The Shapers ~ The Guides.[related] => The Seekers ~ The Shapers ~ The Guides.)blank key found: 3, moving on===========================Array([0] => 14[id] => 14[1] => Golden Circle, the[word] => Golden Circle, the[2] => Cities, Nations & Geography[category] => Cities, Nations & Geography[3] =>[pronounce] =>[4] => The group of nations and Shard-worlds allied under the Cadmnian Accord.[definition] => The group of nations and Shard-worlds allied under the Cadmnian Accord.[5] =>[definitiontwo] =>[6] => Cadmnian Accord.[related] => Cadmnian Accord.)blank key found: 3, moving on===========================Array([0] => 15[id] => 15[1] => Guide(s), the[word] => Guide(s), the[2] => Sect (Pathfinders)[category] => Sect (Pathfinders)[3] =>[pronounce] =>[4] => A sect of the Pathfinders devoted to research and teaching.[definition] => A sect of the Pathfinders devoted to research and teaching.[5] =>[definitiontwo] =>[6] => The Pathfinders ~ The Seekers ~ The Shapers.[related] => The Pathfinders ~ The Seekers ~ The Shapers.)blank key found: 3, moving on===========================Array([0] => 16[id] => 16[1] => Iken, the[word] => Iken, the[2] => Race (Tii al)[category] => Race (Tii al)[3] => (eye - ken)[pronounce] => (eye - ken)[4] => The Iken are the ruling race in the Shard-world of Tii al.[definition] => The Iken are the ruling race in the Shard-world of Tii al.[5] =>[definitiontwo] =>[6] => The Kiil ~ The Tii Alu ~ Tii Al.[related] => The Kiil ~ The Tii Alu ~ Tii Al.)blank key found: 5, moving on===========================Array([0] => 17[id] => 17[1] => Imhalane[word] => Imhalane[2] => City (Siymeha)[category] => City (Siymeha)[3] => (im-uh-lawn)[pronounce] => (im-uh-lawn)[4] => The capitol-city of Siymeha.[definition] => The capitol-city of Siymeha.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 5, moving on===========================Array([0] => 18[id] => 18[1] => Kaduin Sea[word] => Kaduin Sea[2] => Geography[category] => Geography[3] => ( kad-wine )[pronounce] => ( kad-wine )[4] => The ocean that fills the eastern arc of Tii al.[definition] => The ocean that fills the eastern arc of Tii al.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 5, moving on===========================Array([0] => 19[id] => 19[1] => Kiil, the[word] => Kiil, the[2] => Race (Tii al)[category] => Race (Tii al)[3] => ( keel )[pronounce] => ( keel )[4] => A slave class within the Tii alu.[definition] => A slave class within the Tii alu.[5] =>[definitiontwo] =>[6] => The Iken ~ Tii al ~ The Tii alu.[related] => The Iken ~ Tii al ~ The Tii alu.)blank key found: 5, moving on===========================Array([0] => 20[id] => 20[1] => Koran'ga Ji[word] => Koran'ga Ji[2] => Structure (Tii al)[category] => Structure (Tii al)[3] => ( ko-ran guh jie )[pronounce] => ( ko-ran guh jie )[4] => The first and largest coliseum in Ti al, localed in the city of Ki Ran.[definition] => The first and largest coliseum in Ti al, localed in the city of Ki Ran.[5] =>[definitiontwo] =>[6] => Kua Nii ~ Bloodsport.[related] => Kua Nii ~ Bloodsport.)blank key found: 5, moving on===========================Array([0] => 21[id] => 21[1] => Kua Nii[word] => Kua Nii[2] => Sport/Weapon (Tii al)[category] => Sport/Weapon (Tii al)[3] => ( kwa-nee )[pronounce] => ( kwa-nee )[4] => A popular sporting event in Tii al, named for the small knife which is used during the fight.[definition] => A popular sporting event in Tii al, named for the small knife which is used during the fight.[5] =>[definitiontwo] =>[6] => Bloodsport.[related] => Bloodsport.)blank key found: 5, moving on===========================Array([0] => 22[id] => 22[1] => Pathfinder(s)[word] => Pathfinder(s)[2] => Species/Guild[category] => Species/Guild[3] =>[pronounce] =>[4] => The extremely secretive order that polices the Deep and acts as an impartial peace-keeping force for the Golden Circle. Immensely powerful and knowledgeable in the ways of the Deep.[definition] => The extremely secretive order that polices the Deep and acts as an impartial peace-keeping force for the Golden Circle. Immensely powerful and knowledgeable in the ways of the Deep.[5] =>[definitiontwo] =>[6] => The Seekers ~ The Shapers ~ The Guides ~ The Sundered City.[related] => The Seekers ~ The Shapers ~ The Guides ~ The Sundered City.)blank key found: 3, moving on===========================Array([0] => 23[id] => 23[1] => Pocket[word] => Pocket[2] => Term[category] => Term[3] =>[pronounce] =>[4] => A pocket is a small piece of stable reality, similar to a Shard, that a shaper projects around themselves while traveling in the Deep.[definition] => A pocket is a small piece of stable reality, similar to a Shard, that a shaper projects around themselves while traveling in the Deep.[5] =>[definitiontwo] =>[6] => Shaping.[related] => Shaping.)blank key found: 3, moving on===========================Array([0] => 24[id] => 24[1] => Quilting[word] => Quilting[2] => Term[category] => Term[3] =>[pronounce] =>[4] => A term to describe the process by which two Shards of the same reality are blended into one.[definition] => A term to describe the process by which two Shards of the same reality are blended into one.[5] =>[definitiontwo] =>[6] => Absolute Quilting ~ Anchor Quilting.[related] => Absolute Quilting ~ Anchor Quilting.)blank key found: 3, moving on===========================Array([0] => 25[id] => 25[1] => Seekers, The[word] => Seekers, The[2] => Sect (Pathfinders)[category] => Sect (Pathfinders)[3] =>[pronounce] =>[4] => A sect of the Pathfinders for those of the Golden Circle that have the ability to Shape.[definition] => A sect of the Pathfinders for those of the Golden Circle that have the ability to Shape.[5] =>[definitiontwo] =>[6] => The Pathfinders ~ The Shapers ~ The Guides[related] => The Pathfinders ~ The Shapers ~ The Guides)blank key found: 3, moving on===========================Array([0] => 26[id] => 26[1] => Senthk Sea, the[word] => Senthk Sea, the[2] => Geography[category] => Geography[3] => ( sen-thuck )[pronounce] => ( sen-thuck )[4] => The ocean that fills the Shard-world of Ush'en.[definition] => The ocean that fills the Shard-world of Ush'en.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 5, moving on===========================Array([0] => 27[id] => 27[1] => Shallows[word] => Shallows[2] => Term/Location[category] => Term/Location[3] =>[pronounce] =>[4] => To a Pathfinder, the "shallows" stretch from the edge of the Veil to the Deep. If emphasized as The Shallows, then it refers to the muddled area at the center of the circle formed by the Shards.[definition] => To a Pathfinder, the "shallows" stretch from the edge of the Veil to the Deep. If emphasized as The Shallows, then it refers to the muddled area at the center of the circle formed by the Shards.[5] =>[definitiontwo] =>[6] => "..walking shallow".[related] => "..walking shallow".)blank key found: 3, moving on===========================Array([0] => 28[id] => 28[1] => Shapers, The[word] => Shapers, The[2] => Common term/Sect (Pathfinders)[category] => Common term/Sect (Pathfinders)[3] =>[pronounce] =>[4] => In general usage, this is a term for anyone with the ability to Shape. Within the Pathfinders the Shapers are the largest and most influential sect.[definition] => In general usage, this is a term for anyone with the ability to Shape. Within the Pathfinders the Shapers are the largest and most influential sect.[5] =>[definitiontwo] =>[6] => The Seekers ~ The Guides ~ The Pathfinders ~ Shaping.[related] => The Seekers ~ The Guides ~ The Pathfinders ~ Shaping.)blank key found: 3, moving on===========================Array([0] => 29[id] => 29[1] => Shaping[word] => Shaping[2] => Term[category] => Term[3] =>[pronounce] =>[4] => The process by which a Shaper guides the flow of the Deep to suit their purposes.[definition] => The process by which a Shaper guides the flow of the Deep to suit their purposes.[5] =>[definitiontwo] =>[6] => Pocket.[related] => Pocket.)blank key found: 3, moving on===========================Array([0] => 30[id] => 30[1] => Shard/Shard-world[word] => Shard/Shard-world[2] => Term[category] => Term[3] =>[pronounce] =>[4] => A general term for a stable piece of reality that was once part of a whole world. In common usage, Shard-world usually refers to a nation that controls or fills an entire Shard.[definition] => A general term for a stable piece of reality that was once part of a whole world. In common usage, Shard-world usually refers to a nation that controls or fills an entire Shard.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 3, moving on===========================Array([0] => 31[id] => 31[1] => Siymeha[word] => Siymeha[2] => Cities, Nations & Geography[category] => Cities, Nations & Geography[3] => ( see-ih-may-uh )[pronounce] => ( see-ih-may-uh )[4] => The home of the Siyk. The most heavily populated of the Shard-worlds. Although Siymeha has over 70 cities, a good deal of its landscape is given to agriculture.[definition] => The home of the Siyk. The most heavily populated of the Shard-worlds. Although Siymeha has over 70 cities, a good deal of its landscape is given to agriculture.[5] =>[definitiontwo] =>[6] => Siyk ~ Imhalane.[related] => Siyk ~ Imhalane.)blank key found: 5, moving on===========================Array([0] => 32[id] => 32[1] => Span[word] => Span[2] => Construct[category] => Construct[3] =>[pronounce] =>[4] => Created by the Pathfinders, the Spans are a series of "roads" that run through the Deep, connecting the Shard-worlds of the Golden circle. These roads are stable pieces of reality, hundreds of miles long.[definition] => Created by the Pathfinders, the Spans are a series of "roads" that run through the Deep, connecting the Shard-worlds of the Golden circle. These roads are stable pieces of reality, hundreds of miles long.[5] =>[definitiontwo] =>[6] => Anchoring[related] => Anchoring)blank key found: 3, moving on===========================Array([0] => 33[id] => 33[1] => Sundered City, The[word] => Sundered City, The[2] => City/Shard-world[category] => City/Shard-world[3] =>[pronounce] =>[4] => The mysterious home of the Pathfinders. No one but the Pathfinders know the exact location of the Sundered City. All that is known is that it drifts somewhere in The Shallows at the heart of the Golden Circle.[definition] => The mysterious home of the Pathfinders. No one but the Pathfinders know the exact location of the Sundered City. All that is known is that it drifts somewhere in The Shallows at the heart of the Golden Circle.[5] =>[definitiontwo] =>[6] =>[related] =>)blank key found: 3, moving on===========================Array([0] => 34[id] => 34[1] => Tempest[word] => Tempest[2] => Term/Occurrence[category] => Term/Occurrence[3] =>[pronounce] =>[4] => A violent upheaval within the Deep, which moves like a storm.[definition] => A violent upheaval within the Deep, which moves like a storm.[5] =>[definitiontwo] =>[6] => Burst.[related] => Burst.)blank key found: 3, moving on===========================Array([0] => 35[id] => 35[1] => Tii al[word] => Tii al[2] => Shard-world[category] => Shard-world[3] => ( tee-al )[pronounce] => ( tee-al )[4] => The home of the Tii alu (both Iken and Kiil). Tii al has two suns and most of the Shard is dominated by jungle. There is an ocean to the east, and to the north there is an open expanse of high plateau and ore rich mountains.[definition] => The home of the Tii alu (both Iken and Kiil). Tii al has two suns and most of the Shard is dominated by jungle. There is an ocean to the east, and to the north there is an open expanse of high plateau and ore rich mountains.[5] =>[definitiontwo] =>[6] => Tii alu ~ The Kiil ~ The Iken.[related] => Tii alu ~ The Kiil ~ The Iken.)blank key found: 5, moving on===========================Array([0] => 36[id] => 36[1] => Tii alu[word] => Tii alu[2] => Species (Tii al)[category] => Species (Tii al)[3] => ( tee-al-oo )[pronounce] => ( tee-al-oo )[4] => The inhabitants of the Shard-world of Tii al. There are two unique races amongst the Tii alu: the Iken and the Kiil.[definition] => The inhabitants of the Shard-world of Tii al. There are two unique races amongst the Tii alu: the Iken and the Kiil.[5] =>[definitiontwo] =>[6] => The Iken ~ The Kiil ~ Tii al.[related] => The Iken ~ The Kiil ~ Tii al.)blank key found: 5, moving on===========================Array([0] => 37[id] => 37[1] => Ush'en[word] => Ush'en[2] => Shard-world[category] => Shard-world[3] => ( oosh-enn )[pronounce] => ( oosh-enn )[4] => Home to the Ush'ii. Ush'en is dominated by its ocean, which cover more than 3/4's of the Shard-world. There are hundreds of islands scattered throughout the Shard, many of which are volcanic. The Senthk Sea which fills the shard is also frequently battered by violent storms.[definition] => Home to the Ush'ii. Ush'en is dominated by its ocean, which cover more than 3/4's of the Shard-world. There are hundreds of islands scattered throughout the Shard, many of which are volcanic. The Senthk Sea which fills the shard is also frequently battered by violent storms.[5] =>[definitiontwo] =>[6] => Ush'ii ~ The Senthk Sea.[related] => Ush'ii ~ The Senthk Sea.)blank key found: 5, moving on===========================Array([0] => 38[id] => 38[1] => Ush'ii[word] => Ush'ii[2] => Race (Ush'en)[category] => Race (Ush'en)[3] => ( oosh-eye )[pronounce] => ( oosh-eye )[4] => The tribal society that inhabits the world of Ush'en. The Ush'ii spend most of their lives on their ships and only live on land when married or old.[definition] => The tribal society that inhabits the world of Ush'en. The Ush'ii spend most of their lives on their ships and only live on land when married or old.[5] =>[definitiontwo] =>[6] => Ush'en[related] => Ush'en)blank key found: 5, moving on===========================Array([0] => 39[id] => 39[1] => Veil[word] => Veil[2] => Term[category] => Term[3] =>[pronounce] =>[4] => The veil is a term that describes the point of separation between stable matter and the Deep. In common usage it is the edge of a Shard, and in the context of shaping it is the edge of a Shaper's pocket.[definition] => The veil is a term that describes the point of separation between stable matter and the Deep. In common usage it is the edge of a Shard, and in the context of shaping it is the edge of a Shaper's pocket.[5] =>[definitiontwo] =>[6] => Pocket ~ Shaping.[related] => Pocket ~ Shaping.)blank key found: 3, moving on===========================Array([0] => 40[id] => 40[1] => Walking shallow[word] => Walking shallow[2] => Term[category] => Term[3] =>[pronounce] =>[4] => A term used when a shaper is walking near enough to a Shard that, in calm conditions, they cannot be altered or unmade.[definition] => A term used when a shaper is walking near enough to a Shard that, in calm conditions, they cannot be altered or unmade.[5] =>[definitiontwo] =>[6] => Burst ~ Tempest ~ Shallows[related] => Burst ~ Tempest ~ Shallows)blank key found: 3, moving on===========================Array([0] => 41[id] => 41[1] => Yi al Won[word] => Yi al Won[2] => Historical Figure (Tii alu)[category] => Historical Figure (Tii alu)[3] => ( yie - al - wan )[pronounce] => ( yie - al - wan )[4] => The pen name for the author of the Secret History, which was written in Tii al during the Culture Wars.[definition] => The pen name for the author of the Secret History, which was written in Tii al during the Culture Wars.[5] =>[definitiontwo] =>[6] => The Secret History ~ Lau Ni Ar.[related] => The Secret History ~ Lau Ni Ar.)blank key found: 5, moving on===========================

Link to comment
Share on other sites

OK, well this script checks all of the fields in each row, and only displays the row if none of the fields are blank. So it looks like in some cases, the pronounce field is empty, and in other cases the definitiontwo field is empty. So I guess the question is what do you want to do, when do you want to display a record or not display a record?

Link to comment
Share on other sites

I always want to display every record. What I want the script to do is, when it's pulling an entry (word, class, pronunciation and all the other fields) from the database, I want it to first check and see which fields are empty. If any field is empty, I want it not to display the html associated. Basically make that field invisible.In all other cases (when there actually is text in that given field) I want it to display the proper html.

Link to comment
Share on other sites

OH!Ok then, I was under assumption for whatever reason that if any of the fields were blank, to skip the row. OK, this should do it then:

$db = mysql_connect("localhost", "****", "****");mysql_select_db("localhost",$db);$search_string = $_GET['s'];$result = mysql_query ("SELECT * FROM dictionary WHERE word LIKE '%" . mysql_real_escape_string($search_string) . "%' ORDER BY word ASC") or die(mysql_error());while ($r = mysql_fetch_array($result)){  if ($r['word'] != "")  {	echo '<h2>'.$r['word'].'</h2><br />';	if ($r['category'] != "")	  echo '<span class="blue">Category:</span> '.$r['category'].'<br />';	if ($r['pronounce'] != "")	  echo '<span class="blue">Pronunciation:</span> '.$r['pronounce'].'<br />';	if ($r['definition'] != "")	  echo '<span class="blue">Definition:</span> '.$r['definition'].'<br />';	if ($r['related'] != "")	  echo '<span class="blue">Related Entries:</span> '.$r['related'].'<br />';  }}

Link to comment
Share on other sites

Aha. Brilliant. That works great. Thanks.Okay. Few more random questions. When these results are printing, there's no space between each entry, and I can't get padding to work either, since in essence the results are printing the same block over and over with different text.How can I get some space between each entry if more than one prints?

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