Procode
-
Posts
18 -
Joined
-
Last visited
Never
Posts posted by Procode
-
-
Ok what i want to do is define one variable and use it throughout the whole class and it's functions.
Say it's smarty. How can i do[code]$smarty = new Smarty();[/code] once and use it regulary throughout my functions in the class without having to define it every time in every function?
Example:
Somehow i define smarty and then
[code]class MyClass{
function MyFunction(){
$smarty->define('var', $var);
}
}[/code] -
I used IPB many times before and never had any hacking problems. I think it's great software.
-
What am i missing?
My MySQL class code:
[code]function assoc_array($sql){
$this->do_connect();
$sql_result = mysql_query($sql) or die(mysql_error());
if (!$sql_result)
{
$sql_error = mysql_error();
echo "<br>";
echo "<p>".$this->mysql['gen_error']."</p>";
return(false);
}
else
{
$info = mysql_fetch_assoc($sql_result);
return ($info);
}
[/code]
And in my actual class the code is:
[code]function members_main(){
$smarty = new Smarty();
$mysql = new mysql();
$sql = "SELECT * FROM `user` WHERE username = '".$_SESSION['user']."' LIMIT 1";
$info = $mysql->assoc_array($sql);
$smarty->assign('full_name', $info['name']);
$smarty->assign('username', $info['username']);
$smarty->assign('email', $info['email']);
}
[/code]
it basicly shows up blank in smarty, means it doesnt work. Whats wrong?
The session does work i checked. -
It surely is. I doubt anyone is going to do it for free tho.
-
Guess not.
-
Anyone?
-
I dont understand, can you give an example?
-
Ok i am trying assign a var to smarty though my class.
Here is the code:
[code]function members_main(){
$smarty = new Smarty();
$sql = "SELECT * FROM `user` WHERE username = '".$_SESSION['user']."' LIMIT 1";
$mysql = new mysql();
$info = $mysql->assoc_array($sql);
$smarty->assign('name', $_SESSION['user']);
}
function member_page(){
$smarty = new Smarty();
switch($_GET['do']){
default:
$this->members_main();
$smarty->display('main.members.tpl');
break;[/code]
Where you see [code]$this->members_main();[/code] if i replace that with [code]$smarty->assign('name', $_SESSION['user']);[/code] It works fine. But if i do it through [code]$this->members_main();[/code] it doesn't work. What am i doing wrong? -
Sorry i didn't mention that before i started my class i have
[code]include("config.php");
//Global mysql variable.
global $mysql;[/code] -
Sorry if it's noobish but i am just learning classes and i just can't get this fixed.
Basicly i wrote a mysql class and now have hell of errors saying it does not let me connect to the database, is it me or am i doing something wrong. I use WAMP so i use root for username... no password, localhost and db name is correct as well.
Here is the MySQL class.(part of it)
[code]class mysql {
//MySQL var
var $mysql = array();
//MySQL settings.
function settings(){
//MySQL settings.
$this->mysql['host'] = $mysql['host'];
$this->mysql['user'] = $mysql['user'];
$this->mysql['pass'] = $mysql['pass'];
$this->mysql['dbname'] = $mysql['dbname'];
//MySQL errors.
$this -> mysql['con_error'] = "<b>MySQL encountered a severe error while trying to connect to the host</b>n";
$this -> mysql['db_error'] = "<b>MySQL encountered a severe error while trying to use the database</b>n";
$this -> mysql['gen_error'] = "<b>MySQL Error: <b>Due to a database error this page cannot be displayed</b>n";
}
//MySQL connect function.
function do_connect(){
$this->settings();
$connect = mysql_connect($this->mysql['host'], $this->mysql['user'], $this->mysql['pass']);
$db = mysql_select_db($this->mysql['dbname']);
if(!$connect){
echo "<br>";
echo $this->mysql['con_error'];
}elseif(!$db){
echo "<br>";
echo $this->mysql['db_error'];
}
}
//MySQL query function
function sql_run($sql){
$this->do_connect();
$res = mysql_query($sql);
if(!$res){
echo "<br>";
echo $this->mysql['db_error'];
}else{
return($res);
}
}
//MySQL mysq_num_rows function.
function num_rows($sql){
$this->do_connect();
$now = $this->sql_run($sql);
$res = mysql_num_rows($now);
if(!$res){
echo "<br>";
echo $this->mysql['db_error'];
}else{
return $res;
}
}[/code]
Please help, what am i doing wrong? -
Just everytime that page loads, check what banner it is and add +1 to it's views.
-
[quote author=ober link=topic=115268.msg469400#msg469400 date=1163736346]
www.ajaxfreaks.com would be a good place... other than that, read some of the threads around here and try a few things.
[/quote]
Thanks, i didnt think of that :P -
I am getting fairly good at php lately so i want to learn ajax/javascript as well. Where can i start? Any recomendations?
-
Okay someone helped me at the other forum, thank you tho.
-
If you are using html then it should be
[code]<a href="?action=1">Click here</a>[/code]
Try that, works for me. -
I want it to echo the contacts in rows. Okay i'll ask in the smarty forum after i figure out what to put in the class first.
-
I am coding a simple guest book and i haven't made classes related to Smarty yet so i need help.
My code is as follows:
[code]function show_contacts($user_id){
$this->mysql = new mysql();
$sql = "SELECT * FROM `contacts` WHERE 'owner' = '".$user_id.'"'";
$this->contacts = $mysql->assoc_aray($sql);
while($this->contacts){
//what here ?
}
}[/code]
That is the code inside a class, i also made a mysql class before that but what do i have to put where it says "what here?" and what do i put in a .tpl file in smarty in order for it to list the contacts? :)
Thank you. -
Hey my name is vlad, i am new at this forum. Been coding PHP for a year but haven't really in last 4 months or so, now decided to get back to it and go further and become good :) Hope you guys can help me on this forum :D
Help me with something newbish.
in PHP Coding Help
Posted
using define will make a constant which is available anywhere - so you don't need the $smarty->
once you have defined it you can access it anywhere. (good practice to use uppercase for constants - helps you identify them in your code)
[/quote]
Can you give an example please?
Do you mean do this
[code]
$smarty = new Smarty();
DEFINE('SMARTY', $smarty);
[/code]
Then inside a class function i do[code]SMARTY->blah();[/code]
Elaborate a little more please.