PHP - Quick Question About Class Variables
I'm confused as to why assigning these variables in the class causes the page not to load...
var $RootFolder = '/shyid/'; var $PagePath = str_replace($this->RootFolder, '', dirname($_SERVER['PHP_SELF'])); var $PageSections = explode('/', $this->PagePath); but when i set them on the page, everything works correctly? $head->RootFolder = '/shyid/'; $head->PagePath = str_replace($head->RootFolder, '', dirname($_SERVER['PHP_SELF'])); $head->PageSections = explode('/', $head->PagePath); Insight? Thanks. Similar TutorialsApologies for such a silly question.... Been away from php for a long time... How can i call a variable from a position above where the variable is set? I need a variable to echo out near the top of my page but its defined near the bottom of my script. As you can see i am tryin to echo the amount of rows found from the query below. Code: [Select] <?php echo $num_rows; $query = "SELECT Name, FROM table"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $num_rows = mysql_num_rows( $result ); } ?> Thanks in advance Hi, I need to be able to call a class based on variables. E.G. I would normally do: Code: [Select] $action = new pattern1() but i would like to be able to do it dynamicaly: Code: [Select] $patNum = 1; $action = new pattern.$patNum.() Im wondering if that's possible? If so what would the correct syntax be? Many Thanks. I am getting the following error: Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /Library/WebServer/Dev/classtest/lib/class_userdata.php on line 5 on this class code: Code: [Select] class userdata { public $name = ""; public $city = ""; public $phone = ""; function setData($n, $c, $p) { $name = $n; $city = $c; $phone = $p; } function getData() { $userdata=array('name'=>$name, 'city'=>$city, 'phone'=>$phone); return $userdata; } } I thought that was a proper way to set up some class variables. (http://www.victorchen.info/accessing-php-class-variables-and-functions/). Thanks. I am starting to learn PDO by re-writing one of my existing scripts. Do I still need to validate $_GET or does PDO do the work for me? Currently I am using: Code: [Select] $id = $_GET['id']; $sth = $dbh->prepare('DELETE FROM van_reservations WHERE id = :id'); $sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->execute(); I used to validate by using this: Code: [Select] $id = isset($_GET['id']) && is_numeric($_GET['id'])?(int) $_GET['id']:0; hey guys i have a script that creates a cookie named "MyLoginPage" now everything works well the cookie is saved and it keeps the user logged in The Question ok so im wanting to create a link that will delete the cookie so when the user clicks the link it will delete the cookie is this possible?? if so, how?? many thanks hey! I have a site where I want to use multiple issets at the same time, like if I have four buttons and four issets: if(isset($_POST['one'])) { echo '<div class="example_box">one</div>'; } if(isset($_POST['two'])) { echo '<div class="example_box">two</div>'; } if(isset($_POST['three'])) { echo '<div class="example_box">three</div>'; } if(isset($_POST['four'])) { echo '<div class="example_box">four</div>'; } but for some reason it seems like only one isset can be activate at a time, is there any way to work this out or something :s? I've tried some variants of elseif stuff and such, but yeah, I'm pretty new at this stuff how to open a site with curl that has frames ? when ive tried it gives "your broswer does not support frames" ... code <?php //storecodefound.php v1.0 //purpose is to store the http refer and the code associated with the site to a db to be collected and verified by submitcode.php $code = $_GET['code']; $site = $_SERVER['HTTP_HOST']; //check to see if the code already present $connect = mysql_connect("localhost","root","") or die (mysql_error()); $check = mysql_query("SELECT code FROM hunter.codes WHERE code='$code'") or die (mysql_error()); $row = mysql_num_rows($check); echo "result of \$row is ".$row; echo "<br />"; if ($row = 0) { //insert into db cause it's not there mysql_query("INSERT INTO hunter.codes (id, code, site) VALUES ('','$code','$site')") or die (mysql_error()); } else { //echo it's already here echo "Code already found on server!"; } ?> my question is the result of $row is infact 0 and the if statement says if $row is 0 to insert into db and instead it's given me the code is already found? Does storing multiple values in 1 database field with a varchar let's say set at 150, all separated by "|'s" so I don't have to create a field name for each one is it better performance wise or no? (storing 6-7 different |'s that will be outputted with a array ofc) ? What is the difference between these two lines Code: [Select] !isset($_POST[$requiredField]) and Code: [Select] !$_POST[$requiredField] hi. when i get into some function manual and there is a note says. Quote This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. . is that meaning that after 5.3.0 version this function will not be supported? thanks , Mor. Is there a way to only output the first, say, 30 words of a variable? I have a way to do it in mind, but seems like it's messy and not practical. Any suggestions? E.g: WITHOUT LIMIT: Welcome to my store. Would you like to buy something? We have really good noodles and fishes in doodle pools. WITH LIMIT: Welcome to my store. Would you like... Sort of like a short preview. Hi, I've seen code like this multiple times, but I don't really know what it means. function funcName(&$something) { // whatever } What exactly does the "&" do before the variable? I keep running into a bunch of error when I declare the page variable in my model. What syntax do I need to use throughout the class? Code: [Select] <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Header_Model extends CI_Model{ var $page = substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4); function get_page_name() { $this->load->library('common'); $page_names = $this->common->page_names(); $title = (array_key_exists($page, $page_names) !== false) ? $page_names[$page]: ''; if (array_key_exists($page, $page_names) !== false) { $title .= " | Jason Biondo"; } return $title; } function get_js_page_file() { if (file_exists("./assets/js/pages/${page}.js")) { $javascript = "<script type=\"text/javascript\" src=\"./js/pages/${page}.js\"></script>"; } return $javascript; } } I think I need to use $this, but I need to be able to add the two values returned from both of my functions. How would I do that? Code: [Select] public function get_users_edge($uid) { $users_primary->get_users_primary_edge($uid); $users_dynamic->get_users_dynamic_edge($uid); echo $users_primary + $users_dynamic; } Does anyone know if it's possible to call a class with an arbitrary number of variables? I'll explain what I mean. Here is my class construct definition: Code: [Select] function __construct($file, $outFile = 'newpdf.pdf', $fontSize = 70, $alpha=0.6, $overlayMsg = 'N O T F O R S H O P', $degrees = 45) { I know that I have to pass over the $file variable for it to work now. But can I create the class passing just the $file var and the $overlayMsg var? Everything else I would want to leave as default. How would I do that? Thanks Mike Long story short i'm paginating database results. So pages = results / res-per-page-limit but 28 / 10 will be 2.8 should i use round() or ceil()? Say, Code: [Select] $ok = 'ABCDEFG' What is the command to check whether $ok contains 'C'? Hi guys/girls, any pointers on this would be greatly appreciated. basically i have a table called HORSES with 2 fields: HORSE_ID and HORSE_NAME. I want to create a page which dynamically shows all the horse ID's, then a checkbox, then the horse names which can be edited. You can then edit a horse name, click the edit checkbox, and post the form to edit the database. The Form shows the fields easily enough, but doesnt update the database for some reason. Anyone got any ideas? <?php include("..\connection\connection.php"); $conn = oci_connect($UName,$PWord,$DB) or die("Couldn't logon."); if(empty($_POST["check"])) { $query = "SELECT * FROM HORSE ORDER BY HORSE_NAME"; $stmt = oci_parse($conn,$query); oci_execute($stmt); ?> <form method="post" action="horsemultiple.php"> <table border="1" cellpadding="5"> <tr> <th>Horse_ID</th> <th>Edit</th> <th>Horse Name</th> </tr> <?php while ($namearray = oci_fetch_array ($stmt)) { ?> <tr> <td><?php echo $namearray["HORSE_ID"]; ?></td> <td align="center"> <input type="checkbox" name="check[]" value="<?php echo $namearray["HORSE_ID"]; ?>"> </td> <td align="center"> <input type="text" size="5" name="<?php echo $namearray["HORSE_ID"]; ?>" value="<?php echo $namearray["HORSE_NAME"]; ?>"> </td> </tr> <?php } ?> </table><p /> <center> <input type="submit" value="Update Selected Horses"> </center> </form> <?php oci_free_statement($stmt); } else { foreach($_POST["check"] as $id) { $query = "UPDATE HORSE set HORSE_NAME = ".$_POST[$id]. " WHERE HORSE_ID ='".$id."'"; $stmt = oci_parse($conn,$query); oci_execute($stmt); header("location: ../horse.php"); } } oci_close($conn); ?> Can I replace the set message text for $body and $subject with $_POST['message']; $_POST['subject']; so I can get a users input from a html form via php as the action. Instead of the set text in the script. As seen http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm |