
Spring
-
Posts
224 -
Joined
-
Last visited
Posts posted by Spring
-
-
It's a little difficult for me to explain but, when a website loads another site (For example with Curl or something) How is the site able to keep a header or some part of original site 'attached' to the site they loaded..for example, say you're redirected, the site you redirected to loads, but you still see the site you redirected from header on at the top of the page. How is this done? What is it called? Do you need me to clear it up a bit better? I can try to find an example.
-
You need to send the actual data.
$(document).ready(function() { $('#pika').click(function() { $.post('earn.php', { pika:$('pika') }, function(data) { alert(data); }); return false; }); });
If it's not to troubling could you explain to me how this works?
pika:$('pika')
I know it's JSON, but am I basically saying that I want to set the value 'pika' to $('pika')? So my PHP would still look the same correct? I couldn't find any tutorials on this that was understandable for me. Could you explain to me what's going on? I don't need a whole run down, just a summary of what everything is doing, I'd appreciate it!! It would help me understand.
Also, when I run this , my page uses too much data, any more tips?
<?php define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); // Start session management $user->session_begin(); $auth->acl($user->data); $user->setup(); //logged on? if ($user->data['user_id'] == ANONYMOUS){ login_box('', $user->lang['LOGIN']); } //User vars $username = $user->data['username']; $user_id = $user->data['user_id']; //Does the user have an egg? $sql = "SELECT * FROM phpbb_user_pets WHERE owner_id = $user_id"; $result = $db->sql_query($sql); //if($pet = $db->sql_fetchrow($result)){ // trigger_error($user->lang['ERR_EGG']); // $db->sql_freeresult($result); //} $attitudes = array('Angry', 'Happy', 'Grumpy', 'Estatic', 'Loving', 'Herp', 'Selfish', 'Emo'); $random_atti = array_rand($attitudes, 1); if( isset($_POST['pika']) ){ //$sql = "INSERT INTO phpbb_user_pets (pet_id, owner_id, clicks, name, nickname, level, frozen, atti) // VALUES(1,$user_id, 0, 'Pikachu', 'Default', 0, 0, '" . $attitudes[$random_atti] . "')"; //$db->sql_query($sql); $template->assign_var('GRATS','You have earned your first pet!'); } page_header('Earn your egg'); $template->set_filenames(array( 'body' => 'earn.html', )); make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx")); page_footer(); ?>
-
I want to UPDATE the database once a button is pressed, how do I do this? I've tried, but I'm new with Ajax and I'm having trouble with the Data param. What do I need to do with this $.post function?
earn.html
$(document).ready(function() { $('#pika').click(function() { $.post('earn.php', { pika:pika }, function(data) { alert(data); }); return false; }); });
Here's my HTML
earn.html
<div id = "wraper" > <form action = "" method = "POST" id = "form"> <input type = "submit" id = "pika" name = "pika" value = "" /> </form> </div>
And here's what I want to do.
earn.php
if( isset($_POST['pika']) ){ $sql = "INSERT INTO phpbb_user_pets (pet_id, owner_id, clicks, name, nickname, level, frozen, atti) VALUES(1,$user_id, 0, 'Pikachu', 'Default', 0, 0, '" . $attitudes[$random_atti] . "')"; $db->sql_query($sql); $template->assign_var('GRATS','You have earned your first pet!'); }
-
Hey, I'm new to Jquery and I'm wondering what my mistake is here, it's working fine with JS!
Js code:
function mouseOver(){ var oWrap = document.getElementById('wrap'); oWrap.style.backgroundColor = "#FFFFFF"; oWrap.style.filter = "alpha(opacity=100)"; oWrap.style.opacity = 1.0; }
And here's the Jquery:
$('#wrap').mouseover(function (){ $(this).css({ 'background-color':'#FFFFFF', 'filter':'alpha(opacity=100)', 'opacity ':'1.0' }); });
-
Could someone please show me how to properly use a join please? Here's the code I'm looking to make.
$sql = "SELECT * FROM phpbb_pets where id = phpbb_user_pets.petid AND phpbb_user_pets.username = '$username'";
-
So i have this:
#wrap { background-color:#FFFFFF;filter:alpha(opacity=80);opacity:.6; }
And with javascript I want to basically, make the opacity normal, so i tried this:
function mouseOver() { document.getElementById('wrap').style.background-color = #FFFFFF; }
Though it's not working, can anyone help me?
-
want something like:
date('F j, Y, g:i a')
but in central timezone, how do I change the timezone to central?
-
Oh yeah! I keep forgetting the damn quotes. I'll make sure to remember next time.
-
$sql = "INSERT INTO phpbb_user_comments (`person_id`,`from`,`to`,`subject`,`time`) VALUES(" . $user->data['user_id'] . "," . $user->data['username'] . ",3,4,5)";
Unknown column 'Tony' in 'field list' [1054]
SQL
INSERT INTO phpbb_user_comments (`person_id`,`from`,`to`,`subject`,`time`) VALUES(2,Tony,3,4,5)
-
might have it nevermind.
-
How could I do something like this?
$sql = "SELECT post_text from posts WHERE poster_id = users.userid";
-
I'm have an if statement and I want to do something like this.
if($post == 5 - 10)) //five through ten {then do this}
Is there a function or different method to do this?
If not, I'm guessing I'll have to make the function.
-
Sigh. I tend to make myself looker stupider by the day. I should quit php.
-
I've tried the PHPBB help forum and no one has answered.
I thought i'd try here.
For some reason i'm getting this weird error when I attempt to post.
SQL ERROR [ mysqli ]
Unknown column 'Tony' in 'where clause' [1054]
SQL
UPDATE phpbb_users SET user_gold = 50 WHERE username =Tony
Tony is in the username row. What am I doing wrong? here's the code I'm using.
if (($mode == 'reply' || $mode == 'quote' || $mode == 'post')) { $sql = "UPDATE phpbb_users SET user_gold = 50 WHERE username =" . $user->data['username'] . ""; $db->sql_query($sql); }
-
$sql="SELECT body FROM rpg_announcements ORDER BY id desc"; $result = $db->query($sql); $row = $db->fetch($result); echo $row['body'];
I copied your code, and changed the 0 to body and it worked thanks a bunch!
-
replace
->fetch_array()
with
->fetch()
Okay, i did that and it just comes out blank.
-
OH!! fetch is array is also querying it?
Da hell?
I didn't see that..
Ok! I fixed that, so how would I output the data?
-
The problem is because your ->fetch_array() method is calling your ->query() method. Why are you doing that? You have already executed the query and your fetch_array() method should just fetch the data.
So it should be this?
$sql="SELECT * FROM rpg_announcements ORDER BY id desc"; $result = $db->query($sql); $row = $db->fetch_array($sql); echo $row[1];
When i run this it works, but only shows
"array"
-
the error means your trying to call an array var that hasn't been initialized try:
echo $row[0];
thats the Notice: Undefined offset: 1 error neways
Yeah, i've tried that and it still throws the error..
When i redo this the same way in procedural php it works fine.
-
here's the class im using
<?php # Name: Database.singleton.php # File Description: MySQL Singleton Class to allow easy and clean access to common mysql commands # Author: ricocheting # Web: http://www.ricocheting.com/ # Update: 2010-07-19 # Version: 3.1.4 # Copyright 2003 ricocheting.com /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ //require("config.inc.php"); //$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); //$db = Database::obtain(); ################################################################################################### ################################################################################################### ################################################################################################### class Database{ // debug flag for showing error messages public $debug = true; // Store the single instance of Database private static $instance; private $server = ""; //database server private $user = ""; //database login name private $pass = ""; //database login password private $database = ""; //database name private $error = ""; ####################### //number of rows affected by SQL query public $affected_rows = 0; private $link_id = 0; private $query_id = 0; #-############################################# # desc: constructor private function __construct($server=null, $user=null, $pass=null, $database=null){ // error catching if not passed in if($server==null || $user==null || $database==null){ $this->oops("Database information must be passed in when the object is first created."); } $this->server=$server; $this->user=$user; $this->pass=$pass; $this->database=$database; }#-#constructor() #-############################################# # desc: singleton declaration public static function obtain($server=null, $user=null, $pass=null, $database=null){ if (!self::$instance){ self::$instance = new Database($server, $user, $pass, $database); } return self::$instance; }#-#obtain() #-############################################# # desc: connect and select database using vars above # Param: $new_link can force connect() to open a new link, even if mysql_connect() was called before with the same parameters public function connect($new_link=false){ $this->link_id=@mysql_connect($this->server,$this->user,$this->pass,$new_link); if (!$this->link_id){//open failed $this->oops("Could not connect to server: <b>$this->server</b>."); } if(!@mysql_select_db($this->database, $this->link_id)){//no database $this->oops("Could not open database: <b>$this->database</b>."); } // unset the data so it can't be dumped $this->server=''; $this->user=''; $this->pass=''; $this->database=''; }#-#connect() #-############################################# # desc: close the connection public function close(){ if(!@mysql_close($this->link_id)){ $this->oops("Connection close failed."); } }#-#close() #-############################################# # Desc: escapes characters to be mysql ready # Param: string # returns: string public function escape($string){ if(get_magic_quotes_runtime()) $string = stripslashes($string); return @mysql_real_escape_string($string,$this->link_id); }#-#escape() #-############################################# # Desc: executes SQL query to an open connection # Param: (MySQL query) to execute # returns: (query_id) for fetching results etc public function query($sql){ // do query $this->query_id = @mysql_query($sql, $this->link_id); if (!$this->query_id){ $this->oops("<b>MySQL Query fail:</b> $sql"); return 0; } $this->affected_rows = @mysql_affected_rows($this->link_id); return $this->query_id; }#-#query() #-############################################# # desc: does a query, fetches the first row only, frees resultset # param: (MySQL query) the query to run on server # returns: array of fetched results public function query_first($query_string){ $query_id = $this->query($query_string); $out = $this->fetch($query_id); $this->free_result($query_id); return $out; }#-#query_first() #-############################################# # desc: fetches and returns results one line at a time # param: query_id for mysql run. if none specified, last used # return: (array) fetched record(s) public function fetch($query_id=-1){ // retrieve row if ($query_id!=-1){ $this->query_id=$query_id; } if (isset($this->query_id)){ $record = @mysql_fetch_assoc($this->query_id); }else{ $this->oops("Invalid query_id: <b>$this->query_id</b>. Records could not be fetched."); } return $record; }#-#fetch() #-############################################# # desc: returns all the results (not one row) # param: (MySQL query) the query to run on server # returns: assoc array of ALL fetched results public function fetch_array($sql){ $query_id = $this->query($sql); $out = array(); while ($row = $this->fetch($query_id)){ $out[] = $row; } $this->free_result($query_id); return $out; }#-#fetch_array() #-############################################# # desc: does an update query with an array # param: table, assoc array with data (not escaped), where condition (optional. if none given, all records updated) # returns: (query_id) for fetching results etc public function update($table, $data, $where='1'){ $q="UPDATE `$table` SET "; foreach($data as $key=>$val){ if(strtolower($val)=='null') $q.= "`$key` = NULL, "; elseif(strtolower($val)=='now()') $q.= "`$key` = NOW(), "; elseif(preg_match("/^increment\((\-?\d+)\)$/i",$val,$m)) $q.= "`$key` = `$key` + $m[1], "; else $q.= "`$key`='".$this->escape($val)."', "; } $q = rtrim($q, ', ') . ' WHERE '.$where.';'; return $this->query($q); }#-#update() #-############################################# # desc: does an insert query with an array # param: table, assoc array with data (not escaped) # returns: id of inserted record, false if error public function insert($table, $data){ $q="INSERT INTO `$table` "; $v=''; $n=''; foreach($data as $key=>$val){ $n.="`$key`, "; if(strtolower($val)=='null') $v.="NULL, "; elseif(strtolower($val)=='now()') $v.="NOW(), "; else $v.= "'".$this->escape($val)."', "; } $q .= "(". rtrim($n, ', ') .") VALUES (". rtrim($v, ', ') .");"; if($this->query($q)){ return mysql_insert_id($this->link_id); } else return false; }#-#insert() #-############################################# # desc: frees the resultset # param: query_id for mysql run. if none specified, last used private function free_result($query_id=-1){ if ($query_id!=-1){ $this->query_id=$query_id; } if($this->query_id!=0 && !@mysql_free_result($this->query_id)){ $this->oops("Result ID: <b>$this->query_id</b> could not be freed."); } }#-#free_result() #-############################################# # desc: throw an error message # param: [optional] any custom error to display private function oops($msg=''){ if(!empty($this->link_id)){ $this->error = mysql_error($this->link_id); } else{ $this->error = mysql_error(); $msg="<b>WARNING:</b> No link_id found. Likely not be connected to database.<br />$msg"; } // if no debug, done here if(!$this->debug) return; ?> <table align="center" border="1" cellspacing="0" style="background:white;color:black;width:80%;"> <tr><th colspan=2>Database Error</th></tr> <tr><td align="right" valign="top">Message:</td><td><?php echo $msg; ?></td></tr> <?php if(!empty($this->error)) echo '<tr><td align="right" valign="top" nowrap>MySQL Error:</td><td>'.$this->error.'</td></tr>'; ?> <tr><td align="right">Date:</td><td><?php echo date("l, F j, Y \a\\t g:i:s A"); ?></td></tr> <?php if(!empty($_SERVER['REQUEST_URI'])) echo '<tr><td align="right">Script:</td><td><a href="'.$_SERVER['REQUEST_URI'].'">'.$_SERVER['REQUEST_URI'].'</a></td></tr>'; ?> <?php if(!empty($_SERVER['HTTP_REFERER'])) echo '<tr><td align="right">Referer:</td><td><a href="'.$_SERVER['HTTP_REFERER'].'">'.$_SERVER['HTTP_REFERER'].'</a></td></tr>'; ?> </table> <?php }#-#oops() }//CLASS Database ################################################################################################### ?>
here's what im trying to do.
$sql="SELECT * FROM rpg_announcements ORDER BY id desc"; $result = $db->query($sql); $row = $db->fetch_array($result); echo $row[1];
here's my error:
Database Error
Message: MySQL Query fail: Resource id #7
Notice: Undefined offset: 1
What am i doing wrong?
-
nevermind just going to use the database
-
So I've been trying to work with OOP more lately and basically I have just some basic code.
class announce_manager { //I guess we'll start with setting the title. public function setTitle($title) { $this->title = $title; } public function getTitle() { return setTitle(); } }
Anyway, say I set the title on a page called announce.php would it still be set on index.php? Probably not right? Is there a way to make the value I set carry over to another page without using sessions?
example:
announce.php
if(isset($_GET['annsubmit'])) { $title = $_GET['title']; $ann = new announce_manager(); $ann->setTitle($title); }
index.php
echo getTitle(); <- make this equal to the value I set in announce, without using sessions.
I'm just asking if this is possible.
-
I've been looking for Curl tutorials and haven't really found any good ones. Can Curl take text from a website and store it in a variable? If so, can I get an example? If not, could someone please redirect me towards something it can?
Example:
A site has a list of items you've earned on a game, you want to store them and output them on your site.
If this isn't clear enough please let me know.
-
If I had the pattern:
$pattern = "/^[a-zA-Z0-9._-]{4,20}$/";
And I wanted to replace, 4, 20 with a variable, how would I go about doing so?
What is this called? Or how is it done?
in PHP Coding Help
Posted
Sorry meant to edit not quote..