PHP - Seeking Multiple Methods Or Options
Okay so I'm trying to come up with as many alternative methods to accomplish something. So I'm just seeking input from anyone who is willing to supply some.
After the user clicks on a match type it'll know HOW MANY sides to the match there are so say for a singles match it'd have 2 sides (1 vs. 1) for a Triple Threat Match it'd have 3 sides (1 vs. 1 vs. 1) and so on. All matches have a stored field in the database of how many sides they have. So I'm thinking that I could have it create 3 divs (or something) down in the competitors area of how many sides there are in the match (separated by a VS. text block) and when the user selects a character from the dropdown and adds a character the user can maybe drag and drop the character's name to whatever side they choose. Its one idea. If you think of an EASIER more EFFICIENT way to do something like this and have an idea say something please or even if you can't let me know that you think it's a worth while idea. Code: [Select] <label for="matchtypedrop<?php echo $i+1 ?>">Match Type:</label> <select class="dropdown" name="matchtypedrop<?php echo $i+1 ?>" id="matchtypedrop<?php echo $i+1 ?>" title="Match Type <?php echo $i+1 ?>"> <option value="0">- Select -</option> <?php $query = 'SELECT id, matchtype FROM matchtypes'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['matchtype']."</option>\r"; } ?> </select> <label for="competitors<?php echo $i+1 ?>">Competitors:</label><ul id="competitors<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul> <select class="dropdown" name="charactersdrop<?php echo $i+1 ?>" id="charactersdrop<?php echo $i+1 ?>" title="Characters Dropdown <?php echo $i+1 ?>" style="margin-left: 195px;"> <option value="0">- Select -</option> <?php $query = 'SELECT id, `character` FROM characters ORDER BY `character`'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['character']."</option>\r"; } ?> </select> <input type="button" value="Add Character" class="" onclick="Competitors(<?php echo $i+1 ?>)"/> Similar TutorialsThis seems to be a bit of a challenge but I am creating a multiple page form and on one of the pages I have a select field. I would like the user to have the ability to select multiple options but I am using some functions to move the data in hidden fields from page to page. I don't think my functions are jiving with my my foreach loop cause I keep getting an invalid argument error. Thanks in advance for any help. Here is my function: function setSelected($fieldName, $fieldValue) { if(isset($_POST[$fieldName]) && $_POST[$fieldName] == $fieldValue) { echo 'selected="selected"'; } } And here is my loop: $selections = ""; if(isset($_POST["selections"])) { foreach ($_POST["selections"] as $selection) { $selections .= $selection . ", "; } } Hi guys, I am just wondering if there is a proper method to streamline my codes, whenever I perform multiple INSERTs into tables? Probably like INNER JOIN method etc? Thanks $query = "INSERT INTO practice_user (name, email, password, dob, category, comments) VALUES ('$name', '$email', '$password', '$dob', '$category', '$comments')"; $result = mysqli_query($dbc, $query) or die(mysql_error()); $query2 = "INSERT INTO location (name) VALUES ('$location')"; $result = mysqli_query($dbc, $query2) or die(mysql_error()); I'm doing a site for a used vehicles company. I have a "searchbar" with the following select options: the first one is to search per vehicle manufacturer (ex. BMW). The second one is for a price range (ex. any - $1 000 000). the third is per mileage (ex. any - 150 000). and the last one is per model (ex. 320). All of them are structured as drop-down selectors except for the last one "model" which is has a input type text. Here is what I struggle with... When I choose a manufacturer and click search then I get the desired results. But as-soon as I choose a value from the price or mileage or model I get all the values from the manufacturer, but it doesn't filter what I have chosen. Can you please help me.... Thank you Here is the code for the searchbar.php: Code: [Select] <?php ?> <form name="searchForm" action="showroom.php" method="GET" class="search"> <table cellpadding="0" cellspacing="0"> <tr class="search_bar"> <td><b>Search</b></td> <td><select name="make"> <?php do { ?><option value="<?php echo $row_make['Make']?>"<?php if (!(strcmp($row_make['Make'], $row_make['Make']))) {echo "selected=\"selected\"";} ?>> <?php echo $row_make['Make']?></option> <?php } while ($row_make = mysql_fetch_assoc($make)); $rows = mysql_num_rows($make); if($rows > 0) { mysql_data_seek($make, 0); $row_make = mysql_fetch_assoc($make); } ?> </select> </td> <td><select style="height:20px;" name="price"> <option>Price</option> <option value="">Any</option> <option value="5000">R5,000 </option> <option value="10000">R10,000 </option> <option value="15000">R15,000 </option> <option value="20000">R20,000 </option> <option value="25000">R25,000 </option> <option value="30000">R30,000 </option> <option value="35000">R35,000 </option> <option value="40000">R40,000 </option> <option value="45000">R45,000 </option> <option value="50000">R50,000 </option> <option value="55000">R55,000 </option> <option value="60000">R60,000 </option> <option value="65000">R65,000 </option> <option value="70000">R70,000 </option> <option value="75000">R75,000 </option> <option value="80000">R80,000 </option> <option value="85000">R85,000 </option> <option value="90000">R90,000 </option> <option value="95000">R95,000 </option> <option value="100000">R100,000 </option> <option value="125000">R125,000 </option> <option value="150000">R150,000 </option> <option value="175000">R175,000 </option> <option value="200000">R200,000 </option> <option value="225000">R225,000 </option> <option value="250000">R250,000 </option> <option value="275000">R275,000 </option> <option value="300000">R300,000 </option> <option value="325000">R325,000 </option> <option value="350000">R350,000 </option> <option value="375000">R375,000 </option> <option value="400000">R400,000 </option> <option value="425000">R425,000 </option> <option value="450000">R450,000 </option> <option value="475000">R475,000 </option> <option value="500000">R500,000 </option> <option value="600000">R600,000 </option> <option value="700000">R700,000 </option> <option value="800000">R800,000 </option> <option value="900000">R900,000 </option> <option value="1000000">R1,000,000 </option> </select> </td> <td><select style="height:20px;" name="mileage"> <option>Mileage</option> <option value="0_10000">0-10 000 km</option> <option value="10001_20000">10 001-20 000 km</option> <option value="20001_30000">20 001-30 000 km</option> <option value="30001_40000">30 001-40 000 km</option> <option value="40001_50000">40 001-50 000 km</option> <option value="50001_60000">50 001-60 000 km</option> <option value="60001_70000">60 001-70 000 km</option> <option value="70001_80000">70 001-80 000 km</option> <option value="80001_90000">80 001-90 000 km</option> <option value="90001_100000">90 001-100 000 km</option> <option value="100001_110000">100 001-110 000 km</option> <option value="110001_120000">110 001-120 000 km</option> <option value="120001">120 000km and above</option> </select></td> <td align="right"><b>Model:</b></td> <td><input type="text" name="model" /></td> <td><input type="submit" value="Search" /></td> </tr> </table> </form> Well the title may seem a bit confusing, but heres an example: Code: [Select] <?php class User{ public $uid; public $username; protected $password; protected $email; public $usergroup; public $profile; public function __construct($id){ // constructor code inside } public function getemail(){ return $this->email; } public function getusergroup(){ return $this->usergroup; } public function getprofile(){ $this->profile = new UserProfile($this->uid); } } class UserProfile(){ protected $avatar; protected $bio; protected $gender; protected $favcolor; public function __construct($id){ // constructor code inside } public function formatavatar(){ // avatar formatting code inside } public function formatusername(){ // format username? } } ?> As you can see, the User class(an outer class) has a property called Profile, which can be instantiated as a UserProfile object(an inner class). The two objects have distinct functionalities, but there are times when the UserProfile object needs to access property and methods from the user object. I know its easy for outer class to access methods from inner class by using the single arrow access operator twice, but how about the other way around? Lets say from the above example the userprofile can format the username displayed to the screen by adding a sun to the left of the username if the usergroup is admin, a moon if the usergroup is mod, and nothing if its just a member. The usergroup property is stored in the outer class, and can be accessed with this $user->getusergroup() method only. I know I can always do the hard way by passing a user object to the method's argument, but is there an easier way for the inner class UserProfile to access properties/methods for outerclass User? If so, how can I achieve that? Hello: I am very new to PHP. I have done a few basic feedback forms, but that's it. I have done Classic ASP for years, and am trying to switch over to PHP. I wanted to see what it would take to make a basic CMS that would allow users to update page content from an admin panel. Very much like the attached .JPG demo. Is there existing code available like what I'm trying to do? I can post the ASP version code if it will help. I assume it would need a database, but I have only used DNS-less connections with Access - not anything PHP related. I know the site is hosted on justhost.com, and justhost.com uses unix servers. Any assistance would be appreciated! My website is http://www.infotechnologist.biz.
We handle Web Site Development, web app development, and mobile development. No project is too big, or too small.
Contact me today with details.
My number is 4049390637.
It appears that I have PHP 5.1.6 on my VPS and it is unstable when using filter_var($_POST['email'], FILTER_VALIDATE_EMAIL). Can someone recommend a reasonable Regular Expression to replace this faulty function? (Not looking for overly complicated, just something that will block out outrageous e-mails.) Thanks, Debbie Hello: I would like to know how I can add the option to upload JPGs and/or PDFs to the form I have. I believe I will need to allow 3 uploads once the whole form is done, but I'm trying to keep it small as I learn this. Currently, the form saves the data to the database, and emails the results to a contact. This is fine - just what I need to do most of the time. However, what I'm interesting in doing for this form is to allow the end user to upload/attached JPGs and/or PDFs and save then to the database (and I believe I will need to save the files in a folder on the server, I have one called "EmailedImages"), and then email the results to the contact, including links that will allow the contact to click and download the attached JPGs and/or PDFs. I haven't done this before, so can someone point me in the direction of how to do this, or should an example with the code I use: Code: [Select] <?php $error = NULL; $myDate = NULL; $FullName = NULL; $Email = NULL; if(isset($_POST['submit'])) { $myDate = $_POST['myDate']; $FullName = $_POST['FullName']; $Email = $_POST['Email']; if(empty($FullName)) { $error .= '-- Enter your Full Name. <br />'; } if(empty($Email)) { $error .= '-- Enter your Email. <br />'; } if($error == NULL) { $sql = sprintf("INSERT INTO myContactData(myDate,FullName,Email) VALUES ('%s','%s','%s')", mysql_real_escape_string($myDate), mysql_real_escape_string($FullName), mysql_real_escape_string($Email); if(mysql_query($sql)) { $error .= 'Thank you for contacting us.'; mail( "email@mywebsite.com", "Contact Request", "Date Sent: $myDate\n Full Name: $FullName\n Email: $Email\n", "From: $Email" ); } else { $error .= 'There was an error in our Database, please Try again!'; } } } echo '<span class="textError">' . $error . '</span>'; ?> <form name="myform" action="" method="post"> <input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" /> Full Name: <input type="text" name="FullName" size="45" maxlength="50" value="<?php echo $FullName; ?>" /> Email: <input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /> <input type="submit" name="submit" value="Submit" /> </form> Any help would be greatly appreciated! In <div id="chart_rt">%3$s</div> below, it is populated with a string that always begins with a number followed by a colon (from 1: to 25:). I see that ltrim removes characters from the beginning of a string but I don't see how to compensate for the extra character in 10: through 25: function wp_rss( $url, $num_items = -1 ) { if ( $rss = fetch_rss( $url ) ) { echo '<div id="charts">'; if ( $num_items !== -1 ) { $rss->items = array_slice( $rss->items, 0, $num_items ); } //start count $i = 1; foreach ( (array) $rss->items as $item ) { printf( '<div id="chart_lt">'.$i.'</div><div id="chart_rt">%3$s</div>', esc_url( $item['link'] ), esc_attr( strip_tags( $item['description'] ) ), htmlentities( $item['title'] ) ); //increment $i++; } echo '</div>'; } else { _e( 'An error has occurred, which probably means the feed is down. Try again later.' ); } } This has probably been asked a bunch of times , but : I only recently started to self learn PHP , and this small project i am making is quite a challange for me. The scripts below are not realy writen by me , but i wished to tie them together to get a fully working code. What is suppose to happen is : In the form i wish to put a special button that puts extra input fields in the form. After the form is submited ,with whatever amount of feilds in it, the data goes to a processing.php file that sorts all the info gathered and finaly sends all this data formated in to the last file that will be inluded in the index.php. i already have the code for increcing the amount of inputs but the problem is , all inputs have the same names. Coz of that i get a mess. What i need is each input to have a unique name or id , that way the processing file would receive different names(id's) with different values(what ever is writen in the inputs by users). for example: I have 2 enitial fields displayed on form.html , i click the button "add new" 5 times and add 5 more input fields. All this data must be sent to a process.php and on the output write all of this information formated in the last file in a row that will be displayed in the index by useing <?include("blablabla.php");?> The input increment is done by a java script. the problem is sending data with unique id(name) and receiving it. The form file : <?include("header.php");?> <?$i = 1; ?> <script type="text/javascript"> function validate(frm) { var ele = frm.elements['feedurl[]']; if (! ele.length) { alert(ele.value); } for(var i=0; i<ele.length; i++) { alert(ele[i].value); } return true; } function add_feed() { var div1 = document.createElement('div'); // Get template data div1.innerHTML = document.getElementById('newlinktpl').innerHTML; // append to our form, so that template data //become part of form document.getElementById('newlink').appendChild(div1); } var ct = 1; function new_link() { ct++; var div1 = document.createElement('div'); div1.id = ct; // link to delete extended form elements var delLink = '<div style="text-align:right;margin-right:65px"><a href="javascript:delIt('+ ct +')">Del</a></div>'; div1.innerHTML = document.getElementById('newlinktpl').innerHTML + delLink; document.getElementById('newlink').appendChild(div1); } // function to delete the newly added set of elements function delIt(eleId) { d = document; var ele = d.getElementById(eleId); var parentEle = d.getElementById('newlink'); parentEle.removeChild(ele); } </script> <TABLE> <style> #newlink {width:600px} </style> <form action='sendorder.php' method='post'> <div id="newlink"> <div> <table align="center" border=0> <TR><TD><B>Product:</B> </TD><TD><input type=text name=prodname1 value="<?=$_GET['prodname1'];?>"> </TD> <TD><B>Price:</B> </TD><TD><input type=text name=price1 value="<?=$_GET['price1'].$curency;?>"><b>%</b></TD></TR> </table> </div> </div> <p> <br> <input type="submit" name="submit1"> <input type="reset" name="reset1"> </p> <p id="addnew"></p> <FORM> <INPUT type="button" value="Add New" name="button2" onClick="javascript:new_link()"> </FORM> </form> <!-- Template --> <div id="newlinktpl" style="display:none"> <div> <table border=0> <TR><TD><B>Product:</B> </TD><TD><input type=text name=<?$_POST[++$i];?> value="<?$_GET[$i];?>"> </TD> <TD><B>Price:</B> </TD><TD><input type=text name=<?$_POST [++$i];?> value="<?$_GET[$i].$curency;?>"> </TD></TR> </form> </TABLE> <?include("footer.php");?> in the code above i tryed to make the programm POST the numbers in the name increcing it by 1. But when i click submit i get offset error. The processing file : <? $timestamp = strftime("%d-%m-%Y %H:%M:%S %Y"); // for later use (ignore it) $i =1; #################################################################################### if(($_POST['prodname']!="")&&($_POST['price']!="")){ ############################################################ $writetocsv = $_POST['prodname1'] . "," . $_POST['price1']"%" <BR> . $_POST[$i] . $_POST[$i]; $fp = fopen("data/data.csv", "a"); fwrite ($fp,$writetocsv); fclose ($fp); echo "<script>alert('Data sent.')</script>"; } else{ echo "<script>alert('Error! Please fill the form!')</script>"; } echo "<script>location.replace('index.php')</script>"; ?> Perhaps someone knows a easyer way , since i am not sure how to make stuff due to the lack of knowlage in php. I also tryed arrays but , as said before , too tough when you are a noob Please help. what are magic methods? when do we need to use magic methods? what are the advantages of using magic methods? thanks in advanced. hey guys im wdondering if there's a magic method which works like
__GET()but allows you to put a parameter in...thank you <?php class test { public function run() { $this->object->('string'); // __get with parameter? } public function __get($value) { return $this->{$value} } } ?> I don't know if this belongs here; sorry if it doesn't. I'm using a method=get on a form as I need to pass information through a URL once the form has been submitted. But I also need to INSERT some data from that form to multiple tables. - How can I stop the GET from passing my other variables into the URL? - How do I make the form submit to itself? I need to use the 'index.php?p=checkout' as this matches with a switch statement, which matches to the checkout page. The function PHP_SELF will just refresh to the index.php page, which will not have any of this checkout's page validation. Here's my code: Code: [Select] <h2>Please enter your details</h2> <h3>All fields required</h3> <div id="checkout"> <?php if (isset($_GET['checkout'])){ require_once ('./includes/connectvars.php'); $title = $_GET['title']; $fname = $_GET['fname']; $sname = $_GET['sname']; $ctype = $_GET['ctype']; $cnumber = md5($_GET['cnumber']); $syear = $_GET['smonth'] . $_GET['syear']; $fyear = $_GET['fmonth'] . $_GET['fyear']; $service = $_GET['cardAuth']; $amount = $_REQUEST[$total]; $msg = rand(1000,9999); $api = 'd41d8cd98f00b204e9800998ecf8427e'; $b_house = $_GET['b_house']; $b_postcode = $_GET['b_postcode']; $b_city = $_GET['b_city']; $b_country = $_GET['b_country']; $d_house = $_GET['d_house']; $d_postcode = $_GET['d_postcode']; $d_city = $_GET['d_city']; $d_country = $_GET['d_country']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "INSERT INTO customer (cust_id, first_name, last_name) VALUES ('', '$fname', '$sname') "; $query = "INSERT INTO bill (cust_id) VALUES ('') "; $query = "INSERT INTO deliver (cust_id) VALUES ('') "; mysqli_query($dbc, $query); } //.'service='.$service.'msg_id='.$msg.'num_md5='.$cnumber.'amount='.$amount.'currency=GBP'.'api_key='.$api. ?> <form method="get" action="index.php?p=checkout"> <table> <tr> <td><input type="hidden" name="cardAuth" /></td> </tr> <tr> <td> Title: </td> <td> <select name="title" value="<?php if (!empty($title)) echo $title; ?>" > <option></option> <option>Mr</option> <option>Sir</option> <option>Ms</option> <option>Miss</option> <option>Mrs</option> </select> </td> </tr> <tr> <td> First Name: </td> <td> <input type="text" name="fname" value="<?php if (!empty($fname)) echo $fname; ?>"/> </td> </tr> <tr> <td> Surname: </td> <td> <input type="text" name="sname" value="<?php if (!empty($sname)) echo $sname; ?>"/> </td> </tr> <tr> <td> </td> </tr> <tr> <td> Card Type: </td> <td> <select name="ctype" value="<?php if (!empty($ctype)) echo $ctype; ?>"> <option>mastercard</option> <option>visa</option> <option>amex</option> <option>solo</option> <option>maestro</option> <option>jcb</option> <option>diners</option> </select> </td> </tr> <tr> <td> Card Number: </td> <td> <input type="text" name="cnumber" value="<?php if (!empty($cnumber)) echo $cnumber; ?>"/> </td> </tr> <tr> <td> Valid From: </td> <td> <select name="smonth" value="<?php if (!empty($smonth)) echo $smonth; ?>"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select> <select name="syear" value="<?php if (!empty($syear)) echo $syear; ?>"> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> </select> </td> </tr> <tr> <td> Expires End: </td> <td> <select name="fmonth" value="<?php if (!empty($fmonth)) echo $fmonth; ?>"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select> <select name="fyear" value="<?php if (!empty($fyear)) echo $fyear; ?>"> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> </select> </td> </tr> <tr> <td><h4>Billing Address</h4></td> </tr> <tr> <td> House Name/ Number: </td> <td> <input type="text" name="b_house" /> </td> </tr> <tr> <td> Postcode </td> <td> <input type="text" name="b_postcode" /> </td> </tr> <tr> <td> City: </td> <td> <input type="text" name="b_city" /> </td> </tr> <tr> <td> Country: </td> <td> <input type="text" name="b_country" /> </td> </tr> <tr> <td><h4>Delivery Address</h4></td> </tr> <tr> <td> House Name/ Number: </td> <td> <input type="text" name="d_house" /> </td> </tr> <tr> <td> Postcode </td> <td> <input type="text" name="d_postcode" /> </td> </tr> <tr> <td> City: </td> <td> <input type="text" name="d_city" /> </td> </tr> <tr> <td> Country: </td> <td> <input type="text" name="d_country" /> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="checkout" value="Checkout"/> </td> </tr> </table> </form> </div> hello, i have been following the php.net oop manual but im having a little trouble understanding something. on this page in the manual: http://uk3.php.net/manual/en/language.oop5.basic.php it shows this code and if i seperate it out i cant get it to echo the results i want. what am i doing wrong? i have added a little extra code . class Bear Code: [Select] class Bear { // define properties public $name; public $weight; public $age; public $sex; public $colour; // constructor public function __construct() { $this->name = "winny the poo"; $this->weight = 100; $this->age = 0; $this->sex = "male"; $this->colour = "brown"; } // define methods public function eat($units) { echo $this->name." is eating ".$units." units of food... <br/>"; $this->weight += $units; } public function run() { echo $this->name." is running... <br/>"; } public function kill() { echo $this->name." is killing prey... <br/>"; } public function sleep() { echo $this->name." is sleeping... <br/>"; } } class PolarBear Code: [Select] class PolarBear extends Bear { // constructor public function __construct() { parent::__construct(); $this->colour = "white"; $this->weight = 600; } function polarbar() { // Note: the next line will issue a warning if E_STRICT is enabled. Bear::bear(); } // define methods public function swim() { echo $this->name." is swimming... "; } } now if i try to get back the results i have trouble. this is fine Code: [Select] $bear = new Bear(); $bear->eat($units); $bear->eat(); $bear->run(); $bear->kill(); $bear->sleep(); that echos back Quote //THE BEAR winny the poo is eating 5 units of food... winny the poo is eating units of food... winny the poo is running... winny the poo is killing prey... winny the poo is sleeping... //THE POLAR BEAR winny the poo is eating 5 units of food... winny the poo is eating units of food... winny the poo is running... winny the poo is killing prey... winny the poo is sleeping... winny the poo is swimming... THAT FINE but how come i can echo out each of the properties? why do these ways not work? Code: [Select] Bear::eat($units); Bear::eat(); Bear::run(); Bear::kill(); Bear::sleep(); or Code: [Select] $bear = new Bear(); $bear->$name; $bear->$weight; $bear->$age; $bear->$sex; $bear->$colour; or Code: [Select] echo Bear::eat($units); echo Bear::eat(); echo Bear::run(); echo Bear::kill(); echo Bear::sleep(); or Code: [Select] $bear = new Bear(); echo $bear->$name; echo $bear->$weight; echo $bear->$age; echo $bear->$sex; echo $bear->$colour; and the same goes for PolarBear if i try and get back any of the properties on a page i get nothing ??? i even tried putting it in a loop and that didnt work Code: [Select] $bear = new Bear(); foreach ($bear as $bears){ echo $bears->$name; echo $bears->$weight; echo $bears->$age; echo $bears->$sex; echo $bears->$colour; } whats wrong. why cant i get any results from these ? thanks Hi there, I am working on a PHP ecommerce website. I am going to install SSL on few of the pages. I need to install it on Apache web server coz thats the server our PHP website is running on. How we do go about installing SSL on PHP website. Can anybody please guide me in the right direction. All comments and feedback are always welcomed. Thank you! Hi, I am trying to get my head around classes, interfaces and methods for different animals
this is what I have so far: <?php interface animal { function walk(); function fly(); function swim(); } class monkey implements animal{ const interface1 = "I am from test class"; function noise() { echo "ooh ooh ah ah!"; } function walk() { echo "monkey is walking"; } function fly() { echo "monkey is Flying"; } function swim() { echo "monkey is Swimming"; } public function display() { echo monkey::interface1; echo PHP_EOL; } } class bear implements animal{ const interface1 = "I am from test class"; function noise() { echo "Grrr!"; } function walk() { echo "Bear is walking"; } function fly() { echo "Bear is Flying"; } function swim() { echo "Bear is Swimming"; } public function display() { echo bear::interface1; echo PHP_EOL; } } $Obj = new monkey(); $Obj->display(); $Obj1 = new bear(); $Obj1->display(); ?> I'm a bit stumped as animal interface not calling all functions?! please help Hi, I'm new to php and am attempting to build a site where the navigation and content is built with query functions. My current tables in my database are Categories, Products, and Variation. So a person chooses a category -> then a product -> then a product page shows variations for that product. The problem I am currently having is after when a person selects a section the previous section selected is reset. So lets a person selects a category the product list is shown, but when a person selects a product, the category is no longer selected in the navigation. Or if someone selects product and sees all the variations, if he selects a variation the product ID is reset. I've tried to comb through the internet for some type of solution. I came across concatenating URL encode, but am not sure if this is the correct solution. I tried concatenating one of my urls with Code: [Select] "<a href=\"product_detail.php?cat=" . urlencode($sel_cat["id"]) . '&' . "product=" . urlencode($sel_product['id']) . '&' . "var=" . urlencode($var["id"]) . "\" its a bit of a stab in the dark. My $_GET function is Code: [Select] function find_selected_product() { global $sel_cat; global $sel_product; global $sel_var; if (isset($_GET['cat'])) { $sel_cat = get_cat_by_id($_GET['cat']); } elseif (isset($_GET['product'])) { $sel_cat = NULL; $sel_product = get_product_by_id($_GET['product']); } elseif (isset($_GET['product'])) { $sel_product = get_product_by_id($_GET['product']); $sel_var = get_default_var($sel_product['id']); } elseif (isset($_GET['var'])) { $sel_product = NULL; //test $sel_var = get_variation_by_id($_GET['var']); } else { $sel_cat = NULL; $sel_product = NULL; $sel_var = NULL; } } My navigation code is Code: [Select] function public_navigation($sel_cat, $public = true) { $output = "<td class=\"c1\"><div class=\"sidenav\"><ul>"; $cat_set = get_all_cats($public); while ($cat = mysql_fetch_array($cat_set)) { $output .= "<li>"; if ($cat["id"] == $sel_cat['id']) { $output .= "<a class=\"current\""; } $output .= "<a href=\"index.php?cat=" . urlencode($cat["id"]) . "\">{$cat["cat_name"]}</a></li>"; } $output .= "</ul>"; return $output; } My product is divided into gender and is written like Code: [Select] function cat_content_ladies($sel_cat, $sel_product, $female = true) { $output = "<ul class=\"regions\">"; $cat_set = get_all_cats($female); while ($cat = mysql_fetch_array($cat_set)) { if ($cat["id"] == $sel_cat['id']) { $product_set = get_products_for_female($cat["id"], $female); $output .= "<tr>"; while ($product = mysql_fetch_array($product_set)) { if ($cat["id"] == $sel_cat['id']) { $output .= "<tr>"; $output .= "<div class=\"pre\"><a href=\"product_detail.php?product=" . urlencode($product["id"]) . "\"></li>"; $output .= "<img src=\"{$product["img_src"]}\" height=\"121\" width=\"121\">"; $output .= "<div>{$product["prod_name"]}</a></div>"; } } $output .= "</tr>"; } } return $output; } My variation table is set up in thumb nails and is written in this function Code: [Select] function show_thumb($sel_product, $sel_var, $public = true) { $output = "<ul class=\"subjects\">"; $product_set = get_all_products($public); while ($product = mysql_fetch_array($product_set)) { $output .= "<li"; if ($product["id"] == $sel_product['id']) { $output .= " class=\"selected\""; } //$output .= "><a href=\"product_detail.php?product=" . urlencode($product["id"]) . //"\">{$product["id"]}</a></li>"; if ($product["id"] == $sel_product['id']) { $var_set = get_variations_for_product($product["id"], $public); $output .= "<ul class=\"pages\">"; while ($var = mysql_fetch_array($var_set)) { $output .= "<li"; if ($var["id"] == $sel_var['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"product_detail.php?var=" . urlencode($var["id"]) . "\">{$var["id"]}</a></li>"; } $output .= "</ul>"; } } $output .= "</ul>"; return $output; } any light on this subject would be greatly appreciated. I am trying to run the function "age", using the last line, I thought that is how I could to access that method, but that doesn't work. Code: [Select] <?php require_once '../phpLive/phpLive.php'; $live->myClass = (object)array( "name" => "Billy Bob Joe", "age" => function($dob){ // Run some code } ); echo $live->myClass->age("1986-07-22"); ?> I get the following error when trying to do that. Quote Fatal error: Call to undefined method stdClass::age() in /xxx/new.plugin.php on line 9 Any Ideas how I can access that method? Thanks! Is there any way to produce a custom magic method? Let's say when I try to get an attribute that doesn't have any value, a method gets called that gives that attribute a value. So I want a method to be triggered when I try to get a value from an attribute that doesn't have any value. I just have a quick question, what happens if I don't assign a visibility element to methods? In other words, if I just have: [php] class Article_model { public $data; function index() { return $data; } [php] ...instead of declaring public, private, static, and so on before the function. Will php just consider it public? |