Jump to content

Making an online dictionary


john010117
 Share

Recommended Posts

Hi.
First of all, don't get me wrong by reading the title. I'm [b][u]not[/u][/b] trying to make a dictionary with alll the words in it. I just wanted to make a SEARCHABLE dictionary with some terms coming from a game. I know that MySQL is involved, and I know that i'll take me a while. Can somebody start me off? Thanks.

PS: If this is in the wrong forum, please move it. Thanks.
Link to comment
Share on other sites

There is a bunch of basic knowledge that you must gain before you can just start this project... First you need to make the database that you want to pull information from... Then you have to tell your server in php of course what information to pull by making "queries"... I dont know how much you know so im starting at the beginning... There are a bunch of great tutorials out there on this matter... a few on phpfreaks.com of course but the most basic ones I've found are on this site: http://preview.arutha.co.uk/tutorials/PHP/All/1/1/... As i said earlier the first thing is making a database so do that first... I hope that gave you a direction to head in...
Link to comment
Share on other sites

I've created a database a long time ago. :D I'm not very familiar with PHP, nor MySQL. I'm on a free web hosting account that [i]has[/i] PHPMyAdmin enabled, but the [i]coding function is disabled[/i]. The website you've gave me doesn't work for me, because it requires you to code things into the db, which I'm unable to do.
Link to comment
Share on other sites

[quote author=thorpe link=topic=118259.msg483156#msg483156 date=1165903349]
[quote]The website you've gave me doesn't work for me, because it requires you to code things into the db, which I'm unable to do[/quote]

What are you talking about?
[/quote]

I meant that the codes on that website require you to put those codes into PHPMyAdmin (right?), which I'm unable to do. And [b]wattsup88[/b], which tuturiol do you want me to look at? There are 3 pages of tutorials...
Link to comment
Share on other sites

No you do NOT put those "codes" into PHPMyAdmin. PHPMyAdmin is just a front-end tool for administrating your database. You would write database queries into your PHP page to pull the appropriate data from the database to display on your page. If you cannot do THAT then there is no point in your host providing a database!
Link to comment
Share on other sites

[quote author=mjdamato link=topic=118259.msg483652#msg483652 date=1165965825]
No you do NOT put those "codes" into PHPMyAdmin. PHPMyAdmin is just a front-end tool for administrating your database. You would write database queries into your PHP page to pull the appropriate data from the database to display on your page. If you cannot do THAT then there is no point in your host providing a database!
[/quote]

Ok, I can do that. Now I need a code that can start me in the right direction... :D
Link to comment
Share on other sites

It only showed an error...

[quote][b]SQL Query:[/b]
$result = @mysql_query (

"SELECT * FROM `phpbb` WHERE `word`='$word'", $cn
) OR die(
mysql_error(
)
)

[b]MySQL said:[/b]
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$result=@mysql_query("SELECT * FROM `words` WHERE `word`='$word'[/quote]

Is there something I have to change in that code? (Yes, I know. I know NOTHING  about MySQL.
Link to comment
Share on other sites

you might want to look into reading a book on this area, a really good one is "PHP & MySQL For Dummies, 2nd Edition (2004)" it will get you started in the right direction, it did for me. This book and similar eons will start you off from nothing and teach you the basics you'll need.
Link to comment
Share on other sites

[color=red]Edit:[/color] I've just gotten this code from the website. I've sucessfully installed it, and no error messages appear. But something seems to be wrong. Let me show you the code first.

This goes into the db.
[code]
CREATE TABLE `search` (
`id` int(5) NOT NULL auto_increment,
`name` varchar(50) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;

--
-- Dumping data for table `search`
--

INSERT INTO `search` VALUES (1, 'Arutha', 'Arutha is a talented coder and designer who runs http://arutha.co.uk');
INSERT INTO `search` VALUES (2, 'Psycho_Phrog', 'A freind off arutha writes the occasional ps tutorial');
INSERT INTO `search` VALUES (3, 'Djc123', 'another freind of arutha, he''s currently doing the photography side of photoshop with promising results');
INSERT INTO `search` VALUES (4, 'Stu', 'Moderator at p2l, provides critisim and advice on arutha.co.uk to arutha');
INSERT INTO `search` VALUES (5, 'you', 'are reading this tutorial and hopefully finding it usefull');
[/code]

I'll show you the other part of the code later (but I seriously think the above code has something wrong in it).

So, when I search the word "Arutha", it has to give me results, right? But it doesn't. What seems to be the problem with this?
Link to comment
Share on other sites

Ok then.

[code]
<?php
// Search Tutorial Code
// Arutha.co.uk

// Standard Connection Data.
$db_host = "****.awardspace.com";
$db_user = "****_db1";
$db_pass = "********";
$db_name = "****_db1";
$dbac = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");

if (!$_POST['search']){
// Breaking out of php to display the form.
?>
<form name="Search Tutorial" method="post" action="">
  Search Words:<br>
  <label>
  <input name="swords" type="text" size="30" maxlength="30">
  </label> 
  <br>
  <label>
  <input name="search" type="submit" id="search" value="Search">
  </label>
</form>
<?php
}else{
// Adding slashes and changing tags so that people trying to take advantage of the system can't
$searchwords = addslashes(htmlspecialchars($_POST['swords']));
// Checking the length of string to make sure its more than 3 characters long
if (strlen($searchwords) < 3){
echo "The word you have inputted is too short, please enter another one.";
}else{
$words = explode(' ',$searchwords);
$totalwords = count($words);
$i = 0;
$searchstring = "";
// Now we are looping to get the search string, however we could use a for loop.
// But i think while loops are much easier to teach with/edit
while ($i != $totalwords){
if ($i != 0 and $i != $wordcount){
$searchstring .= " and ";;
}
$searchstring .= "description LIKE '%$words[$i]%' or name LIKE '%$words[$i]%'";
// Incrementing the value
$i = $i + 1;
}
// Now we are gong to execute the query with the search string we have just created.
$query = mysql_query("SELECT DISTINCT * FROM Search where $searchstring");
// Want to check that we got something 
if (mysql_unbuffered_query($query) == 0){
echo "No results where found sorry :(";
}else{
while ($fet = mysql_fetch_array($query)){
echo "<p>Name: {$fet['name']}<br />
      Description: {$fet['description']}</p>";
}// End While
}// End Else
}// End Else
}// End Else
?>
[/code]

[color=red]Note:[/color] I've double checked to see that the MySQL entries are correct (I put those stars to prevent anyone from seeing sensitive information).

Can you please figure out what's wrong? I always get the same result: "No results were found sorry :(".
Link to comment
Share on other sites

I would love to try and help you but you need to display the current code you are having problems with... and what your trying to do with it... I'm sorry arutha wasn't of much help... it did help me tho so i thought id pass that along... The code arutha puts out tho is not incorrect... at least i cant find anything wrong with it...
Link to comment
Share on other sites

i just cleaned up your code and removed the while loop to replace it with a for loop.

[code=php:0]
<?php
// Search Tutorial Code
// Arutha.co.uk

// Standard Connection Data.
$db_host = "****.awardspace.com";
$db_user = "****_db1";
$db_pass = "********";
$db_name = "****_db1";
$dbac = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");

if (!$_POST['search']){
// Breaking out of php to display the form.
?>
<form name="Search Tutorial" method="post" action="">
  Search Words:<br>
  <label>
  <input name="swords" type="text" size="30" maxlength="30">
  </label> 
  <br>
  <label>
  <input name="search" type="submit" id="search" value="Search">
  </label>
</form>
<?php
}else{
// Adding slashes and changing tags so that people trying to take advantage of the system can't
$searchwords = addslashes(htmlspecialchars($_POST['swords']));
// Checking the length of string to make sure its more than 3 characters long
if (strlen($searchwords) < 3){
echo "The word you have inputted is too short, please enter another one.";
}else{
$words = explode(" ",$searchwords);
$searchstring = "";
// Now we are looping to get the search string, however we could use a for loop.
// But i think while loops are much easier to teach with/edit
for($i = 0; $i <= count($totalwords); $i++)
if ($i != 0 and $i != $wordcount){
$searchstring .= " and ";;
}
$searchstring .= "description LIKE '%{$words[$i]}%' or name LIKE '%{$words[$i]}%'";
}
// Now we are gong to execute the query with the search string we have just created.
$query = mysql_query("SELECT DISTINCT * FROM Search where $searchstring");
// Want to check that we got something 
if (mysql_num_rows($query) == 0){
echo "No results where found sorry :(";
}else{
while ($fet = mysql_fetch_array($query)){
echo "<p>Name: {$fet['name']}<br />
      Description: {$fet['description']}</p>";
}// End While
}// End Else
}// End Else
}// End Else
?>
[/code]

i also changed the mysql_unbuffered_query($query) == 0 to mysql_num_rows($query) == 0. This counts all the found rows, if its 0 then it will display no search results, else display them..

that might've been the problem anyway. good luck...
Link to comment
Share on other sites

[b]ProjectFear[/b], I've used your code, but when I load the page, it says the following message:
[quote]
[b]Parse error[/b]: parse error, unexpected '}' in [b]/****/****/****.awardspace.com/test5.php[/b] on line [b]56[/b]
[/quote]

Ok, so then I removed the "}"s in front of the "//End While" and "// End Else" tags. Now, it says this:
[quote]
[b]Parse error[/b]: parse error, unexpected $ in [b]/****/****/****.awardspace.com/test5.php[/b] on line [b]58[/b]
[/quote]

The problem is... there is no "$" tag in line 58 (or anywhere near that). Please help.

PS: [b]wattsup88[/b], if you look on top of this page, and the near bottom of the previous page, you'll see that I've posted both of the codes.
Link to comment
Share on other sites

Ok, I've gotten rid of [i]that[/i] error. Now, it's saying something like this:
[quote]
[b]Warning[/b]: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /****/****/****.awardspace.com/test5.php on line [b]47[/b]
No results where found sorry :(
[/quote]

[color=red]Note[/color] That last line is supposed to be there when no results are found.

I've searched the [url=http://us3.php.net/manual/en/function.mysql-num-rows.php]MySQL manual for that code[/url], but it said that it should be used this way... anyone care to help please?  ???
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

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