Gregg Posted September 25, 2008 Share Posted September 25, 2008 Ok, i created a new table in my database and i have built a form in php to submit to it and update sp on. But i cant seem to get the info from it. what i want to do is display it on my page under stats. Here is the new table: CREATE TABLE IF NOT EXISTS `se_donations` ( `active` int(1) NOT NULL default '1', `com_tokens` int(20) NOT NULL default '0', `com_donatids` int(20) NOT NULL default '0', PRIMARY KEY (`active`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `se_donations` -- INSERT INTO `se_donations` (`active`, `com_tokens`, `com_donatids`) VALUES (1,9044, 23); And in the .PHP file i have this code to get the info from it: ////// GET TOTAL DON ////// $total_tokens = $database->database_query("SELECT com_tokens FROM se_donations"); $smarty->assign('total_tokens', $total_tokens); ////// END ////// Just a heads up, the code is connecting but displaying ether a 1 or a name "resource id #37" not the value in the columm = 9044! More info: $database-> is the custom code that store my connect data: pass id db name so on... $smarty-> is part of my smarty .php that allows the code to run and print on the pages... BALANCE: {$total_tokens} is how i call it on my .tpl pages. Now my question is, how do i get it to call the data 9044 not the id or row count?? I cant seem to get it to call the info beside the id row count or resource name... arg lol ??? Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 25, 2008 Share Posted September 25, 2008 i'm not sure of your database class, but it looks like your not iterating through the results. This is how it's done the basic way: $s = "SELECT * FROM users"; $res = mysql_query($s, $conn) or die(mysql_error()); while ($a = mysql_fetch_array($res)) { print $a['id'].": ".$a['name']." - ".$a['pass']."<br>"; } Quote Link to comment Share on other sites More sharing options...
Gregg Posted September 25, 2008 Author Share Posted September 25, 2008 I am not sure what that has to do with mine, i am not to great at sql haha. I mean do i need to add anything to it like COUNT or GET to actually load the data inside it? I have no issue connecting to it thats all fine its getting the data i am stuck at... Quote Link to comment Share on other sites More sharing options...
xtopolis Posted September 25, 2008 Share Posted September 25, 2008 What rarebit is saying is that you are getting a correct value, but not the one you want. The steps of an SQL query: 1)Setup query $sql = "SELECT * FROM users"; 2)Send query to database, but assign a variable to the result of the query $result = $db->query($sql) 3)What is the 'result' of that query? var_dump($result) You see something like resource id#__... why? Because mysql assigns a resource id to the 'matches'[really: rows] of your query, and answers with the location of where you can retrieve them (resource id #__ in mysql) 4)Retrieve rows from mysql while ($row = mysql_fetch_array($result)){ echo $row['columnname'].$row['othercolumn'];//echo column values of each row found } What this does: $row is true until the last row/result of the mysql resource is passed which is 'false'... so the while loop runs from the beginning until the last row of the resource where it gets assigned 'false' and the loop stops. Your code might be something like this: (I have never used smarty!) <?php ////// GET TOTAL DON ////// $total_tokens = $database->database_query("SELECT com_tokens FROM se_donations"); while($row = mysql_fetch_array($result)){ $smarty->assign('total_tokens', $row['com_tokens']); } ////// END ////// ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.