Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Script error (http://www.mysidiaadoptables.com/forum/showthread.php?t=3646)

SilverDragonTears 04-29-2012 03:04 AM

Script error
 
I don't know how to get this to work with the new script. I've been trying since last night.

Code:

        $query = "SELECT * FROM ".$GLOBALS['prefix']."tabs WHERE username = '".$GLOBALS['username']."'";
        $result = runquery($query);
        $num = mysql_numrows($result);


SilverDragonTears 04-29-2012 08:17 PM

Ok here is what I have so far and it isn't working LOL

Code:

function gettabs() {
$formcontent = "";
$data = $adopts->select("tabs", array("username", "name"), "username = '{$username}'")->fetchObject();
$num = count($data);

        $i=0;
        while ($i < $num) {
                $tabname=@mysql_result($data, $i,"name");
                $formcontent = $formcontent."<option value='myadopts.php?tab=".$tabname."'>".$tabname."</option>";
                $i++;
        }
        return $formcontent;
}


fadillzzz 04-30-2012 02:32 AM

Don't mix the old mysql_* functions with PDO. The two are very different.

PHP Code:

$result $adopts->select(...);
while (
$row $result->fetchObject())
{
    echo 
$row->name;



SilverDragonTears 04-30-2012 02:56 AM

ok now I have this.. and still not working. Bear with me.
Code:

function gettabs() {
$formcontent = "";
$result = $adopts->select("tabs", array("username", "name"), "username = '{$username}'")->fetchObject();

        $i=0;
        while ($row = $result->fetchObject()) {
                $tabname=@mysql_result($data, $i,"name");
                $formcontent = $formcontent."<option value='myadopts.php?tab=".$tabname."'>".$tabname."</option>";
                $i++;
        }
        return $formcontent;
}


Hall of Famer 04-30-2012 03:28 AM

First of all, you are having an issue Id refer to as 'variable scope'. You are defining a function gettab() without passing any arguments, while the variable $username is undefined as a local variable inside your function. You either have to declare $username as global variable, or pass it as an argument to your function. Read this manual from PHP for reference:
http://php.net/manual/en/language.variables.scope.php

On the other hand, you still use mysql_result() which no longer works with this new script as we are incorporating PDO. I thought Fadillzzz already explained clearly to you not to use mysql functions anymore... Now change this line:

PHP Code:

$tabname=@mysql_result($data$i,"name"); 

to

PHP Code:

$tabname=$row->name

And now the $tabname will not be malfunctioning. However I strongly recommend you to remove all lines associated with $i since its totally unnecessary.

SilverDragonTears 04-30-2012 03:33 AM

Ok another thing. I'm suppose to add this...
Code:

AND ".constant("PREFIX")."owned_adoptables.tab = '{$tab}'
to the myadopts.php query... but when I do it still doesn't list the tabs.

Is this correct for functions.php?
Code:

function gettabs() {
$formcontent = "";
$result = $GLOBALS['adopts']->select("tabs", array("username", "name"), "username = '{$username}'");

        while ($row = $result->fetchObject()) {
                $tabname=$row->name;
                $formcontent = $formcontent."<option value='myadopts.php?tab=".$tabname."'>".$tabname."</option>";
        }
        return $formcontent;
}


Hall of Famer 04-30-2012 05:37 AM

Umm are you trying to select from multiple tables? If so, use the method join() before calling select().

SilverDragonTears 04-30-2012 06:04 AM

I figured it out :D Thank you for the help!

SilverDragonTears 04-30-2012 04:35 PM

Hmm... this pulls up everyone's tabs instead of just the logged in user

Code:

$result = $GLOBALS['adopts']->select("tabs", array("username", "name"), "username = '{$username}'");
i see why but I don't know how to fix it.


heh.
Code:

$result = $GLOBALS['adopts']->select("tabs", array("username", "name"), "username = '".$GLOBALS['username']."'");
Seems to do the trick ;)

Hall of Famer 05-01-2012 03:59 PM

Of course the old script wont work, didnt I tell you before that you need to worry about the variable scope issue? What is $username in your function? If you neither pass it as an argument to your function tab(), nor declare it as global variable, it will be considered an undefined variable.


All times are GMT -5. The time now is 10:08 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.