1
rpclarke
Dev: Database access
  • 2004/11/29 21:20

  • rpclarke

  • Just popping in

  • Posts: 28

  • Since: 2004/11/6


I am making a module similar to Mith's team module, which I have been combing through for a guild website for Final Fantasy XI.

I have created a table in the database with 1 line of information, and now I am trying to pull that information out of the database for display on a template.

Using the functions I have found, I should be able to pull information out of the database for display, but I am not getting any result.

Do I have to put information in somewhere before XOOPS will use that table in the database?

in my functions.php I have this;

function getMembers() {
global $xoopsDB;
$value = array();
$sql = "SELECT ID, character FROM ".$xoopsDB->prefix("ffxi_manager")." WHERE ID = 1";
$dbresult = $xoopsDB->query($sql);
$member = $xoopsDB->fetchArray($dbresult);
$value["ID"] = $member["ID"];
$value["character"] = $member["character"];
return $value;
}

And in my index.php I use this;

$roster = getMembers();
echo "||X:".$roster["character"]; // Testing Purposes

Of course the echo is just a temporary thing just to see if its retrieving database information, which it is not..

In the database the field character is a VARCHAR field, and ID is a INT field with auto_increment on.

I hope thats all the info you need... Thanks for the advice..

2
Mithrandir
Re: Dev: Database access

If you turn on php debug in system admin -> preferences -> general settings, do you get any errors when loading the test page?

If not, try turning on MySQL debug instead and see if the popup-window (when loading the test page) has any SQL statements marked in red to indicate an error.

3
rpclarke
Re: Dev: Database access
  • 2004/11/29 21:46

  • rpclarke

  • Just popping in

  • Posts: 28

  • Since: 2004/11/6


I get this error:
Warning [PHP]: opendir(/srv/www/htdocs/cod/modules/myMembers/images/imagesets/): failed to open dir: No such file or directory in file modules/newbb/include/vars.php line 45
Notice [PHP]: Undefined variable: xoopsModuleConfig in file modules/newbb/include/vars.php line 46

But seems unrelated;

On the SQL:

There was an error with the SQL so I fixed the SQL query:

$sql = "SELECT 'ID', 'character' FROM ".$xoopsDB->prefix("ffxi_manager")." WHERE 'ID' = 1";

Just had to add the single quotations around the fields.

No errors on SQL now, but still no data being output...

Thanks for the info on the debug modes.. very useful that.

4
Mithrandir
Re: Dev: Database access

You shouldn't have to enclose the field names in quotes.

Just a thought - could you try renaming the ID field in the database as well as in the code? Call it charid or something like that. It may be that ID is a protected name in MySQL.

5
rpclarke
Re: Dev: Database access
  • 2004/11/29 22:07

  • rpclarke

  • Just popping in

  • Posts: 28

  • Since: 2004/11/6


Tried that... Still nada... heres the code so far..

functions.php

<?php

// FFXI Linkshell manager Functions.php File

function getMembers() {
global $xoopsDB;
$value = array();
$member = array();
$sql = "SELECT * FROM ".$xoopsDB->prefix("ffxi_manager")." WHERE 'charid' = 1";
$dbresult = $xoopsDB->query($sql);
$member = $xoopsDB->fetchArray($dbresult);
$value["charid"] == $member["charid"];
$value["character"] == $member["character"];
echo "value is=".$member["character"];
return $value;
}

?>

index.php - portion of;

$roster = getMembers();
echo "||X:".$roster["character"];

the echo in both php files doesnt output the array contents.

I ran the SQL statement in phpmyadmin and it pulls the right info there...... Its just not getting to the array or not pulling it out of the database.. but the debug shows it working..

Heres the output from the popup window;

SELECT * FROM xoops_ffxi_manager WHERE 'charid' = 1

6
Mithrandir
Re: Dev: Database access

A couple of things:
$value["charid"] == $member["charid"];
$value["character"] == $member["character"];

== is a boolean expression - not a value assignment. Only use one = sign.

If that is not the cause of the problem (you only had one = in the first copy-paste so it may be a mis-pasting) try this:
function getMembers() {
global 
$xoopsDB;
$value = array();
$member = array();
$sql "SELECT * FROM ".$xoopsDB->prefix("ffxi_manager")." WHERE 'charid' = 1";
$dbresult $xoopsDB->query($sql);
$member $xoopsDB->fetchArray($dbresult);
var_dump('member'$member);
}


and if that doesn't do anything, try this:
function getMembers() {
global 
$xoopsDB;
$value = array();
$member = array();
$sql "SELECT * FROM ".$xoopsDB->prefix("ffxi_manager")." WHERE 'charid' = 1";
$dbresult $xoopsDB->query($sql);
var_dump($dbresult);
$member $xoopsDB->fetchArray($dbresult);
}

7
rpclarke
Re: Dev: Database access
  • 2004/11/29 22:16

  • rpclarke

  • Just popping in

  • Posts: 28

  • Since: 2004/11/6


One thing to note, I manually put the table in the database if that makes any difference. Trying different things, I know that the function call works, I can put a dummy value in no problem..... And a dummy value in that array position works as well. So its definately something database related.. bleh.

8
rpclarke
Re: Dev: Database access
  • 2004/11/29 22:20

  • rpclarke

  • Just popping in

  • Posts: 28

  • Since: 2004/11/6


Yeah I put the == in there as part of testing things... I have it removed still doesnt work.

Put in your first function, I get

string(6) "member" bool(false)

I put in your second functino, I get

resource(132) of type (mysql result)

9
rpclarke
Re: Dev: Database access
  • 2004/11/29 23:21

  • rpclarke

  • Just popping in

  • Posts: 28

  • Since: 2004/11/6


I just made the table XOOPS installable using .sql files and editing the version file for the module. So the table installs itself now in the module administration. Still no data coming from the array....

10
m0nty
Re: Dev: Database access
  • 2004/11/29 23:29

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


i'm not a coder or anything.. and probably can't help you as such, but as i have always presumed and thought from reading and learning that integer values need to be quoted??

ie. $sql = "SELECT * FROM ".$xoopsDB->prefix("ffxi_manager")." WHERE 'charid' = 1";


wouldn't it need to be done as:

$sql = "SELECT * FROM ".$xoopsDB->prefix("ffxi_manager")." WHERE charid = '1'";

just a thought, i maybe wrong..

Login

Who's Online

122 user(s) are online (79 user(s) are browsing Support Forums)


Members: 0


Guests: 122


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits