1
tigums
Problem getting info from sql database
  • 2004/5/31 20:56

  • tigums

  • Just popping in

  • Posts: 8

  • Since: 2004/5/30


I am making a module. Right now it's based off the sample module from jan304. It works fine. To the xoops_version, I added a SQL entry to create a database with columns of "cid" and "owner" and some other columns, but right now I dont care about them.

$modversion['sqlfile']['mysql'] = "sql/mysql.sql";

$modversion['tables'][0] = "charsheet_core";


I manually added entries to the table via phpadmin

which is something like:

cid =1
owner = bob



I've edited the index.php and the sample_html.html(the template) to reflect what I am trying todo

my index changes is:

$username = !empty($xoopsUser) ? $xoopsUser->getVar('uname') : $xoopsConfig['anonymous'];
$userid = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
//$sq = ".$xoopsDB->prefix("charsheet_core").";
$sq "sql2";
$result $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("charsheet_core")." WHERE 'owner' = '$username' ORDER BY 'cid' ASC");

while ( 
$myrow $xoopsDB->fetchArray($result) )
    {
        
$cid=$myrow["cid"];
   
    }
    
$xoopsTpl->assign('uname'$username);
$xoopsTpl->assign('theid'$userid);
$xoopsTpl->assign('charid'$cid);
$xoopsTpl->assign('sqtest'$sq);


and my sample_html chages are:

Greetings <{$uname}> and <{$theid}>

<
br>hi1
<br><{$sqtest}><br>
<{
$charid}>

<
br><br>

hi3


Note: These are just the changes I added to the otherwise perfectly working



When I am logged in as the user 'bob',the output of the module is:

Quote:

Greetings bob and 1
hi1
sql2


hi3


So I know that I did the getting the username part right, getting the userid part right. Then assigning those values to be used in the template.

However the database part is I fudged on, I should be getting a "1" for the cid, since that row is owned by bob.

The module is updated, and I am running debugging with mysql/blocks set to on with no errors being reported.

What am I doing wrong here?



2
Mithrandir
Re: Problem getting info from sql database

First off, you should make it a habit referencing users by userid in relational tables - usernames can change, userids do not

Secondly, you should not put quotes around field names in the query. Basically you are asking for rows where the string 'owner' equals the string 'bob' - which will never happen.

Thirdly, MySQL debug does not report errors on the page, but shows all SQL queries in a popup window (which may be blocked by a popup-blocker) - failed queries in red. I'm saying this because it is not apparent to me, whether you know this or if you were looking for debug errors on the actual page.

3
tigums
Re: Problem getting info from sql database
  • 2004/5/31 21:14

  • tigums

  • Just popping in

  • Posts: 8

  • Since: 2004/5/30


Firstly, appreciate your help and the quick reply

Quote:

you should make it a habit referencing users by userid in relational tables - usernames can change, userids do not


Ah, didn't know that. Good to know.

Quote:

Secondly, you should not put quotes around field names in the query. Basically you are asking for rows where the string 'owner' equals the string 'bob' - which will never happen.


Ah, you're right, that was it. Always the small things that get me


Quote:

... failed queries in red. I'm saying this because it is not apparent to me, whether you know this or if you were looking for debug errors on the actual page.


Yea I was staring at the page... ha!





Also, another question, everytime I edit a page, be it the index.php or the sample_html.html or whatnot, do I have to update the module everytime thereafter editing? Or only certain files need it?

4
Mithrandir
Re: Problem getting info from sql database

if you change module templates, you will need to update the module.

Changing php files (except xoops_version.php) will not require this.

Login

Who's Online

124 user(s) are online (73 user(s) are browsing Support Forums)


Members: 0


Guests: 124


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