Jump to content

Recommended Posts

My friend is helping me make a database where you go to a certain webpage of my site and the page will use code to pull information from a database and display it on the page in a formatted way.

 

<?
function parse($content){
$string = $content;
/* Use <b> to split the string  */
$tok = strtok($string, "<b>");

while ($tok !== false) {

$get = "SELECT Name FROM * WHERE Name = '$tok'";
$getsql = mysql_query($get);
if (!$getsql)
            {
            $type ="";
            }
		else {
$table = mysql_field_table($getsql);
$type = $table;
}
if (!$type){
$link = $tok;
}
elseif ($type == "quest"){
$link = "<a href='viewlocation.php?location_name=$tok'>$tok</a>";
}
elseif ($type == "item"){
$link = "<a href='viewlocation.php?location_name=$tok'>$tok</a>";
}
else {
$link = $tok;
}

echo $link;
$tok = strtok("</b>");
}} 
?>

 

My friend explains the issue as follows:

 

Basically the script uses the tok to split the string up, then im trying to get it to check the whole database name fields for the split.

Then if it finds it, its supposed to get the table name its in and passes it to the if statement.

 

It splits the string into sections then searches the database for the sections by looking in a specific field over all tables

 

Then when its found it takes the table it found it in and get the name of the table which gets passed to the if statement which decides which link it will give to the end of the code which gets returned.

But its not doing the search in the database properly and not getting the table name to pass to the if statement to work out the link to give it.

 

 

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/
Share on other sites

as far as i'm aware you cant do this (someone correct me if i'm wrong)

 SELECT Name FROM * WHERE Name = '$tok' 

in mysql (which i assume is what you are using??), you have to specify a table to select the data from.

 

and i dont think that searching the entire database for a particular value is a good idea either.

 

what is it specifically that you are trying to do? (i read your friends explanation - its more confusing than Microsoft documentation!)

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/#findComment-942643
Share on other sites

sorry for the lack of coherent explanation, was late at night for me when I gave it. im the one who wrote the script, borrowing the account to try and elaborate more on it..

 

the site its going on will basically have the contents of the database laid out for people to see and search through to help them. the site will be split into sections depending on the type of content with each section having its own section in the database. the main purpose of the script is to take the text and decide whether its another item in the database to link to it.

 

the database atm is just a test one that ive got to see if i can get it working, but works on the premise that each section has its own table in one database. the database does indeed use mysql

 

the script is supposed to run through the infomation outputted from the database and split it up as defined by the strtok - this as far as i can tell is working.

 

every time it splits the text it passes the result to the query which is supposed to check the entire database (not ideal but when i was working on that bit was the only way i could think of) for the text to find if it is a valid item in the database.

 

if its a valid result its supposed to do another query to find out the table its in which is used later on in the if statement to decide which link to pass back, if its not a valid result then it just passes a blank so no link is applied to it.

 

hope that better explains what going on if theres any more questions/suggestions, my friend will relay them on

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/#findComment-943086
Share on other sites

I am still quite confused.  What items are stored in the database, and why do you want the links?  All this information is relevant to making a suitable database design.

 

Databases are not designed to make "check the entire database" easy to do.  They are designed to make operations like "Check column X of table Y" easy and fast.  So if you could store all your items in a single table, with a column to identify what type they are, you might find it easier to search them.

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/#findComment-943348
Share on other sites

What items are stored in the database, and why do you want the links?  All this information is relevant to making a suitable database design.

 

Visitors that come to the site input data into textboxes such as the following:

 

Character Name: {textbox}

Character Level: {textbox}

 

The information inputted into the textboxes gets sent into the database and when visitors view the actual database, they can see the information that was submitted in a table-like display.  The database contains many categories such as quests, monsters, skills, items.  Each category is in is own database table, for instance fiesta_quests or fiesta_monsters.  Each category is split into sections such as "level 1-10 quests", "level 11-20 quest", and so forth.  When you browse through any of the database tables, you can sort through which item is in in which section.  The "sections", as you can assume, appear as a column in the table.  Links are generated to link people to certain parts of the database.  If they run a search, the appropriate link will appear to the item they are trying to look up in the database.

 

So if you could store all your items in a single table, with a column to identify what type they are, you might find it easier to search them.

 

My friend who is making the code for the database told me he was going to try that out today sine he got his laptop back :D

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/#findComment-943590
Share on other sites

Ok, from what you've told me now you've got several kinds of objects.  A quest, a monster, a skill, an item ... knowing that, having them all in one table is probably a bad idea :)

 

So I would keep each category in its own table.

 

I'm still too confused to give any useful advice though.  I'm imagining you want something like a table listing items, and along with each item you have links to other database objects (like quests or monsters) which are related to that item.  Is it something like that?

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/#findComment-944349
Share on other sites

I'm still too confused to give any useful advice though.  I'm imagining you want something like a table listing items, and along with each item you have links to other database objects (like quests or monsters) which are related to that item.  Is it something like that?

 

Exactly right! :)

 

By the way, here is an image of what our phpmyadmin looks like:

 

sparkonldb.jpg

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/#findComment-944547
Share on other sites

Ok, makes sense.. so then users can browser the database, following the links.

 

Is the tokenizing necessary because you have data stored as strings, such as "Rewards"?  If I was writing this I would store that data using the database structure itself.

 

Eg, table Items and table Quests, each with a primary key, would be linked by table "QuestItemRewards", which would have one column for the Quest ID and another column for the Item ID.  Presence of a Quest ID and Item ID pair in that table means that quest has that item as a reward.  This allows for multiple items as a quest reward, as well as a single item being rewarded for multiple quests.

Link to comment
https://forums.phpfreaks.com/topic/178668-phpdatabase-issue/#findComment-945176
Share on other sites

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.