PDA

View Full Version : Ok, this is gonna be tough to explain


Fou-Lu
12-27-2002, 05:56 AM
Ok, so this will be quite tough to explain.
I have a table, in which information: 3:10, 4:6, 5:14
etc. etc. is stored in a single mediumtext field.
So, I am extracting those number into seperate rows, so it shows like so:
3 10
4 6
5 14
etc.
That isn't a problem, I got those easily. However, in a completely different table, I am saving similar numbers like so: 3:17 7:14 5:6
each as their own set of numbers, x:y. How do I go about comparing the first digit of the second table's numbers, to the first digit of the first table's numbers, and then using the second digit of the second tables numbers?
I know that doesn't make a lot of sense, but if anyone is willing to help me out, I would gladly let you take a look at the code and examples of what I am trying to do with them.

Fou-Lu
12-29-2002, 11:12 AM
Ok, I almost have this one, just a little bit of help.

Now, its showing like so:
Row 1
Row 1
Row 2
Row 2
Row 3
Row 3

etc, etc. Obviously, I only want one row for each to show. Is there any cheap way of fixing this, like substr?

mordred
12-29-2002, 04:42 PM
You lost me somewhere in the middle, but I think that SELECT DISTINCT could be of any help to you.

Fou-Lu
12-29-2002, 09:03 PM
I don't think that will help me too much. See, I am running a loop within the loop. So, it attempts to loop the first loop, however many times the second loop is looped.
That doesn't make sense either...

SYP}{ER
12-29-2002, 11:13 PM
Something tells me there's an easier way...

Can you explain what this thing is for and what it's supposed to be accomplishing? I think we'll be much more helpful with that information :)

Fou-Lu
12-30-2002, 12:45 AM
Sure!
And I'm sure there is an easier way, usually it takes me a few times to get there though ;)

I'm trying to add something unique to my forum, which is RPG based. So I got this great idea of having espers like in FF VI, and requiring to learn the spells from them through posting and battling. Here is a link:
http://www.gamers-forums.com/vb/esperteach.php?s=&id=1
You can log in as "Jins Testing Ghost" password: "none"

So with my testing ghost there, I have set it so that he has learned 15% of Cure1, 10% of Cure 2, and 5% of ice. You will notice that it repeates one row for every spell learned / learning. Since he has three, it appears like row1, row1, row1, row2, row2, row2 etc.
The information for the espers is held in a table in the DB, with its name, and spells, which are in a mediumtext field set up like so:
spell1:ratelearned, spell2:ratelearned2, etc.
Then, same kinda thing in the users table:
spell:learned spell:learned2 etc.
As you can see, I do have it working, just not as I want it to. Obviously it is just a simple loop problem that I cannot see. Here is the code that I have to go with it so far:

if ($action=="espers"){

if (isset($id)){

$getspells = $DB_site->query_first("SELECT * FROM shop_espers WHERE id='$id'");
$splitem = explode(", ",$getspells[spells]);
while (list($key,$val)=each($splitem)){
if ($background=="#F5F5F5"){
$background = "#EBEBEB";
}else{
$background = "#F5F5F5";
}
$value = "$val";
list($magic,$rate)=split(":",$value);
//Add a post comment here. This seems to be where the trouble begins, which causes the looping.
$getknown = split(" ", $bbuserinfo[magic]);
while (list($newkey,$newval)=each($getknown)){
$newvalue = "$newval";
list($knownmag,$knownpercent) = split(":",$newvalue);
$knownmagic = "$knownmag";
$knownper ="$knownpercent";

if ($knownmagic == $magic){
$percentlearned = "$knownper %";
}else{
$percentlearned = "0 %";
}


$getthename = $DB_site->query_first("SELECT * FROM shop_magics WHERE id='$magic'");
$name = $getthename[name];
$showrow .="<tr bgcolor=\"$background\"><td>$name</td><td>x $rate</td><td align=right>$percentlearned</tr>";
}
}



What do you think? Any idea? I was kinda hoping to leftjoin the two tables together, but I don't know how to do that with all of the explodes and splits. If you can help out, that would be great!

Also thought that I would quickly mention, that I have moved that last closed bracket to other places, but that is the only one that shows all of the spells up at a time. Otherwise, only Ice would show for you. However, if I do it that way, I also don't get any additional rows, if that helps you any ;)