IF ($error = Fixable) { echo "reply!"}

This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

IF ($error = Fixable) { echo "reply!"}

Postby Choseal on Thu Apr 01, 2010 3:23 pm

Dear forum, (=P)

I've got a little problem with one of my scripts:

  1.             $result = mysql_query("SELECT * FROM achievement ORDER BY achnr ASC");
  2.            
  3.             $charqry = mysql_query('SELECT * FROM characters WHERE char_name = "'.$_SESSION['charname'].'"');
  4.             $return = mysql_fetch_array($charqry);
  5.            
  6.             while($row = mysql_fetch_array($result))
  7.                 {                        
  8.                     if($row['conditie'])
  9.                        etc.etc.

The if function is not working, it will always run the script, even if the condition is FALSE.

I was debugging this script and turns out if($row['conditie']) returns the right piece of information, but it adds a \ at the start, so for example it will return:

if(\$return['level'] >= 100)

I guess that's why it's not working? -if so, how do I solve it?
Choseal
Electric Ghost
Electric Ghost
 
Posts: 837
Joined: Fri Jan 09, 2009 6:40 pm

Re: IF ($error = Fixable) { echo "reply!"}

Postby xPrend on Thu Apr 01, 2010 3:32 pm

Did you add pieces of PHP in mysql? If yes, give it up make it PHP sided i tried alot of things to do that but no succes make a function script search PHP Function and you will see whate i meant it's even easier then the mysql way.

Whate if you have to get something out of the character table? Like quests or something, how would you do that with mysql that easy, it will be corupted alot of times.

Edit: http://www.w3schools.com/PHP/php_functions.asp
User avatar
xPrend
Antares
Antares
 
Posts: 346
Joined: Fri Jul 17, 2009 9:22 am

Re: IF ($error = Fixable) { echo "reply!"}

Postby lmame on Thu Apr 01, 2010 7:31 pm

Choseal wrote:Dear forum, (=P)

I've got a little problem with one of my scripts:

  1.             $result = mysql_query("SELECT * FROM achievement ORDER BY achnr ASC");
  2.            
  3.             $charqry = mysql_query('SELECT * FROM characters WHERE char_name = "'.$_SESSION['charname'].'"');
  4.             $return = mysql_fetch_array($charqry);
  5.            
  6.             while($row = mysql_fetch_array($result))
  7.                 {                        
  8.                     if($row['conditie'])
  9.                        etc.etc.

The if function is not working, it will always run the script, even if the condition is FALSE.

I was debugging this script and turns out if($row['conditie']) returns the right piece of information, but it adds a \ at the start, so for example it will return:

if(\$return['level'] >= 100)

I guess that's why it's not working? -if so, how do I solve it?


Do this:
echo("<pre>");
print_r($return);
echo("</pre>");

It should display all values from $return, and show the result of this here.

Do the same for $row (just the first one).
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: IF ($error = Fixable) { echo "reply!"}

Postby Choseal on Thu Apr 01, 2010 8:52 pm

Although I apreciate everone's help, a friend helped me fix it by doing this:

  1. $sql = "SELECT * FROM characters WHERE char_name = '$charname' and {$row['conditie']}";
  2. $sqlresult = mysql_query($sql);


and then make another while in the while function:

  1. while($acharray = mysql_fetch_array($sqlresult))


But thanks either way! =3
Choseal
Electric Ghost
Electric Ghost
 
Posts: 837
Joined: Fri Jan 09, 2009 6:40 pm

Re: IF ($error = Fixable) { echo "reply!"}

Postby Choseal on Tue Apr 13, 2010 3:59 pm

One more question, my brain is falling apart:
I am using the explode() function at the moment, and it's working as it should.

But I want to make a function that will check if the $explode result contains $boolres['id'] if you know what I mean, so something like this: (This example will, obviously, not work)

  1. if($explode contains $boolres['id'])
  2. {
  3.   echo ("It contains the ID!");
  4. }
  5. else
  6. {
  7.   echo ("It does not contain the ID!");
  8. }


Ofcourse $explode contains an array, so how would one go around doing something like this?

Edit:
The main problem is, I got it to work a couple of times, the only problem was, it wouldn't actually compair the id with the results from destroy(), so if it's supposed to check for ID 11 in Destroy(), it will say "It does not contain the ID!" -at first, then I refresh the page, then it says "It does contain the ID!". (Because if it doesn't have the ID it adds it to the data cell)

Then I go to my database, and change 11 to 12, and refresh the page, but then it will still say "It contains the ID!", which means it just checks if there is sómething in the data cell, even if it does not match the ID.

I tried using:
  1. if(!array_key_exists($boolres['id'], $explode))

-But I guess that doesn't work. =P
Choseal
Electric Ghost
Electric Ghost
 
Posts: 837
Joined: Fri Jan 09, 2009 6:40 pm

Re: IF ($error = Fixable) { echo "reply!"}

Postby Choseal on Wed Apr 14, 2010 9:23 am

Fixed, forgot to use the implode function to put it back in the data cell as a whole. :D
Choseal
Electric Ghost
Electric Ghost
 
Posts: 837
Joined: Fri Jan 09, 2009 6:40 pm

Re: IF ($error = Fixable) { echo "reply!"}

Postby Rifke on Tue Apr 20, 2010 5:19 pm

To be honest why don't you use a JOIN in your query or a Subquery?

I don't know how your achievement table is set up, but if your achievement table is something in the order of

achvnr, charid, date [table to store a users achievements (achievement)]

achvnr, achvname, achvdesc, acvhsomthing [table to store all achievements (achievement_list) ]

than you can link the achievements to a users easly for example

  1.  
  2. SELECT c.char_name,
  3.        ac.date AS 'Achievement Earned',
  4.        a.achvname
  5. FROM characters AS c
  6. INNER JOIN achievement AS ac ON (  ac.charid = c.charid )
  7. INNER JOIN achievement_list AS a ON ( a.achvnr = ac.achvnr )
  8. WHERE
  9.     c.char_name = 'MyCharName'
  10.  
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium


Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 4 guests