PHP - $variable = Multiple Values
Hi Guys,
I don't know how to do this but basically I want the value of $postcode3 to equal the value of $postcodep1 aswell as $postcodep2 like this... else {$postcode3 = $postcodep1 $postcodep2;} That doesn't work... Say $postcodep1 = LS14 $postcodep2 = 2AB Then $postcode3 = LS14 2AB How do I write this in the above php code?! Thanks, S Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
Hi folks, I was wondering how to do this. I want the if statement to detect if the query string has any of these values. so im trying to assign them all to the same variable. However, this code wont work. Whats the trick here? <?php $primary=$_GET['intro']; $primary=$_GET['port']; $primary=$_GET['about']; $primary=$_GET['contact']; if(isset($primary)){ echo "<img src='graphics/left-a.png'>";} else {echo "<img src='graphics/leftb.png'>";}?> Hey everyone, I'm new to this forum and I came here looking for some help with PHP. I've just started getting into PHP and you guys are probably a smile ahead. So basically, I have some inputs and want them to be sent to my email in a basic layout shown below. Code: [Select] Inputs: Title = _title Forum Name = _forumname Name = _irlname Age = _age I want the email to be sent to me like: Code: [Select] Email Title --------------- Forum Name: TextGiven Real Life Name: TextGiven Age: TextGiven Here is my current code which titles the email correctly, but I want to figure out how to make $message set to the example email I showed above. Code: [Select] <?php $to = "******@*********.net"; $subject = $_REQUEST['_title']; $headers = "From: ***** Applicant \r\n"; $headers .= "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n"; $message = $_REQUEST['_forumname' & '_irlname']; <--- Part I want fixed if(mail($to, $subject, $message, $headers)) { echo 'MAIL SENT'; } else { echo 'MAIL FAILED'; } ?> I have this code, and it works. But I want $message = "" to make the message contain not just the forum name, but as well as the name, age, and all other inputs I want. Hi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
Hi all, Just curious why this works: Code: [Select] while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]')"; } And this does not: $headdata_1 = "'$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]'"; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values($headdata_1)"; }it puts $data[#'s] in the database fields instead of the actual data that '$data[0]','$data[1]'... relates to. I wrote a script to create the values in $headdata_1 based on the number of headers in $csvheaders1 but can't seem to get it working in the sql statement. Thanks I have a form that has a list of checboxes, each checkbox has multiple values. IE. Checkbox1 has Date 1 and Cost1. Checkbox2 has Date2 and cost2 and so on. This is what I have in form. echo "<input type=checkbox name=service_id[] value=".$id."><label>".$description."</label> Date:<input type=date name=date[] value=".date('Y-m-d').">Date:<input type=number name=cost[] value=".$cost."><br>"; When i run the for loop to insert the values into a table i have this.
foreach($_POST['service_id'] as $key => $value){
The problem is that when I select certain boxes (ie, checkbox #2), it inserts Date1 and Cost1 but does use the correct service id (ie checkbox) I'm sorting out a simple PHP email form, and I would like, when the email arrives in my inbox, for it to display both the email of the sender AND their name as specified in the form on my website. So far I have $from = $_POST['from']; with the 'from' being the client's email address. I would also like their name ('name') to show up next to their email in the header. I have tried such things like $from = $_POST['from' . 'name']; //or $from = $_POST['from']; $_POST['name']; and a few more, but I'm terrible at PHP coding in general. I have searched, but I really am at a loss as to what to search for. Can someone please give me an idea as to what I should do? Thanks, Sacha. Is is possible to give multiple values in a single checkbox? i need to have a checkbox that holds multiple values. Help Anyone.. i've google but no luck on finding what i need....is there a way in javascript to compare 2 variables ie.
var him = "jack"; var her = "jill"; if (him == her){ alert('same name'); }thank you I am very grateful for any input. I have a field in a database that contains references (pattern: authorYYYY), such as the following string:
"authorA1989; authorB1978a; authorB1984; authorC1999; authorC2000a; authorC2000b; authorC2002; authorD2009"
What I want is an output as the following in order to create a proper bibliography (therefore accessing another table and picking out the respective reference details):
authorA
1989
authorB
1978a
1984
authorC
1999
2000a
2000b
2002
authorD
2009
I somewhat fail to group the values (years) per author. I know that keys are unique, but is there a way to work around this?
Many thanks for any help!
Hi People i'm a newb at this so bare with me but i currently have a php file called Newkpi.php which has a select statement in. this selects data from a table called "StaffList". this then populates the page with a html table with 14 records (this will increase/decrease over time) i then have some extra text boxes to enter more detail into like service amaount service date and so on. when i click the submit button i want it to cycle through each row and insert the data into a separate table called "Services". however i cannot for the life of me get this to work and need some help with it. people find attached the code for Newkpi and see if you can help me with this. in total i want it to take the names from stafflist and populate Services with the names and the extra detail which is entered on the page Much Thanx in advance SLOWIE I have this form
<form action="" method="get" name="size"> Størrelse <hr><label><input type="radio" value="9" name="size" onchange="this.form.submit()">92 (2år)</label> <label><input type="checkbox" value="147" name="size" onchange="this.form.submit()">68 (6-9 mdr.) </label><label><input type="checkbox" value="150" name="size" onchange="this.form.submit()">86 (18-24 mdr.)</label> <input type="checkbox" value="149" name="size" onchange="this.form.submit()">80 (12-18 mdr.)</label> <label><input type="checkbox" value="148" name="size" onchange="this.form.submit()">74 (9-12 mdr.)</label> </form>I want to make it so that when the user clicks one checkbox for example size 68 and then checks size 80 I want both sizes to be in the URL query string. But every time the user clicks a new checkbox, the query string changes accordingly. Maybe with a separator like ?size=4:23 and then I will handle it with the DB stuff. Please tell me how to add multiple elements in the query string with this form, thank you! Edited by Stefany93, 21 May 2014 - 08:03 AM. I have the form: hi everybody simply love this forum because i always get the question perfectly answered. i am here this time with a rather complicated question: i am creating a simple duty plan for different departments for exeample department #1 is "Tech" and department #2 is "Service" different employees working in these departments change their dutys and will are sent to another department or section or go on holidays. this is why i have at least 4 different mysql tables to store the data:- personel(storing the personal information of the workers) dutyplan(storing the week's working daysy of the workers) departments(storing the starting and ending dates of the department change) vacation(stores the start and ending dates of the vacations) in all the tables the common id is the pid which is issued unique to every worker. i am still able to work only with the 1st two tables. i can edit and create new plans for the weeks for employees working in the departments with the following php code(submitting only to edit the plan) if i add a date range for example Monday the 24th of January to Sunday the 30th of January for an employee working in the Tech department to work a few days in service department, it will show the employee in the week on the plan of both departments. if both department heads edit the plan without communicating to each other, and knowing on which date the worker goes out and in to the department, the 1st one will plan him for the whole week on his dutyplan and the second department head will overwrite this plan(if edited) or if creating a new plan(create the duty of the worker also one more time). i want to avoid this confusion and manual work. the same is with the vacation or sickness tables, if the employee has vacation, the program should check and return the selected value in the pulldown menu with the value stored in the vacation or sickness tables appropriate to the date in the plan table. ************************************************************************ form.php: <? require "config.php"; $result=mysql_query("select * from personel, dutyplan, department, vacation WHERE personel.pid = dutyplan.pid and personel.pid = vacation.pid and dp.pid = departments.pid and departments.Section = 'Service' order by dp.id asc"); ?> <? while($row=mysql_fetch_assoc($result)){ ?> // after that i create table, displaying all the days of the week from monday to sunday and use this code <tr> <td><? echo $row['FirstName'] . " " . $row['LastName']; ?>: </td> <td> <select name="monday_<? echo $row['id']; ?>" id="select1"> <option><? echo $row['Mo']; ?></option> <option>Duty</option> <option>Free</option> <option>Vacation</option> //the same way down to sunday, for every day the different options to be selected. it displays the records perfectly, as long as there is no change of department planed and the vacation must also be selected manually. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update.php <? if($_POST['Submit']){ require "includes/config.php"; $result=mysql_query("select * from dutyplan, departments, vacation order by dutyplan.id asc"); while($row=mysql_fetch_assoc($result)){ $mo=$_POST["monday_".$row[id]]; $tu=$_POST["tuesday_".$row[id]]; $we=$_POST["wednesday_".$row[id]]; $th=$_POST["thursday_".$row[id]]; $fr=$_POST["friday_".$row[id]]; $sa=$_POST["saturday_".$row[id]]; $su=$_POST["sunday_".$row[id]]; mysql_query("update dp set Mo='$mo', Tu='$tu', We='$we', Th='$th', Fr='$fr', Sa='$sa', Su='$su' where id='$row[id]'"); } echo "Records updated"; } ?> **************************************************** how would you gueys solve this problem? many thanks in advance Hi, I have a row called code in mysql data base now what I want to do is something like this $rand=rand(1111,9999); $code=mysql_query("UPDATE member SET code='$rand' WHERE clan_id='1'"); At the moment its updating the code row with the same random number. What I want to achieve is a unique number for each member. For instance Currently if the $rand=1289 lets suppose Every code row will become 1289 I want the code rows to be different to each other. I tried a few things up my sleeve but no luck. How can i do this? thanks any help much appreciated. I have a textarea feild in my form where the user can type in several keywords such as Textarea Box Below Cars Trains Buses I have a database with the meanings of the words entered and want to be able to get the three definitions from the database on for submission. In a normal input box where i only type one word i can grab no problem like so $word = $_POST['word']; $sql = "SELECT meaning FROM table WHERE word='$word'"; Though i am trying to get multiple values from the same textarea box So if a user types in 3 words the query would query the database on thoses three words, the problem is i dont know how to get the diffrent words from the form for example $first = $_POST['word']; which would be the first word $sec = $_POST['word']; which would be the second word etc. Any help here would be great thanks. Ok I'm trying to select the pet with the current eggid in the url. That part works fine, but when I try to select more than one color, it gets all messed up. Because I don't know how to do it and I can't find it on the internet anywhere. Code: [Select] $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR 'green' OR 'yellow' OR 'red'"; Does anyone know how to do that? Because whenever I put this: Code: [Select] $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR color='yellow' OR color='green' OR color='red'"; It gets all messed up. It selects ALL the colors even if the eggid isn't the current eggid. So it displays the colors of all the pets that have those colors.. :/ EDIT: OR is this the only way I can do it: Code: [Select] $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR eggid='".$_GET['eggid']."' AND color='green' OR eggid='".$_GET['eggid']."' AND color='yellow' OR eggid='".$_GET['eggid']."' AND color='red'"; I have 3 tables.
1)state(s_id, details);
2)univer(u_id,details,s_id);
3)sub(su-id,daetails,u_id, s_id)
Now there is a problem, for ever selection of state and univer there is multiple choice of sub and they can be common in different selections. And how to store these values in databse and can call in a selection menu. so how can i solve it?
Edited by N0name, 31 May 2014 - 10:38 PM. Hello, I am trying to add all rows in the same column together. So here is the basic scheme: id l column1 1 l 1 2 l 2 3 l 3 Second table id l variable1 1 l 3 2 l 5 3 l 6 I basically want to add 5+3+6 and set it to a variable named '$total'. Would this be done using while loops? Here is the code I have been messing with. $sql="SELECT column1 from table1 where id='$userid'"; // userid would be set near the top of the page $sql2=mysql_query($sql,$conn); while($rows=mysql_fetch_array($sql2)){ $getid = $rows['column1']; $sql3="SELECT variable1 FROM table2 where id='$getid'"; $sql4=mysql_query($sql3,$conn); while($items=mysql_fetch_array($sql4)){ // Then I'm getting lost... } } Can you at least see what I am trying to do? I'm not even sure if this is the right approach, any help would be appreciated! Sorry, but I forget how to do this, mostly because I don't do it often. To keep things simple lets say I have 3 classes: Main, A, B class Main{ public $classA, $classB; public $shared; public function init(){ // Do some stuff return $this; } } class A{ public function aMethod(){ $me = $this->shared; // Same value as from B::bMethod() // Do some stuff return $this; } } class B{ public function bMethod(){ $me = $this->shared; // Same value as from A::aMethod() // Do some stuff return $this; } } $main = new Main(); $main->classA->aMethod(); $main->classB->bMethod(); I really want to be able to call the main class, then tell it what subclass to use and be able to use $this->shared in any class and it will be the same. If changed in any class the other classes should see the change as well. Does that make sense? What I have is a page with a list of cars, each with a checkbox next to them. Code: [Select] <?php $sth = null; $count = 0; $sth = $dbh->prepare("SELECT * FROM garage WHERE warehouse_id = ? ORDER BY car_name ASC"); $sth->execute(array($_POST['ware_id'])); echo "<table>"; echo "<tr>"; echo '<td>Choose Vehicles:</td>'; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "<form action='warehouse_ship_3.php' method='POST'>"; while($row = $sth->fetch()){ echo "<input type='checkbox' name='cars' value='".$row['uci']."' /> ID: ".$row['uci'].", ".$row['car_year']." ".$row['car_name']."<br />"; } echo "<input type='hidden' name='ware_id' value='".$_POST['ware_id']."' />"; echo "<hr />"; echo '<div class="center"><input class="myButton" type="submit" name="submit" value="Next" /></div></form>'; echo "</td>"; echo "</tr>"; echo "</table>"; ?> That works fine. What I'm trying to do with this second page, is select all the car's info from a table called "garage" which stores data for all the cars (car name, year, etc) and display it. UCI stands for Unique car id, every car has a different id. It works when the user only selects one car on the previous page, but if they select two or more cars, only the car with the highest UCI number shows up. How would I work it to display info on every car that they selected? Code: [Select] <?php if(empty($_POST['cars'])) { echo("You didn't select any cars."); } else { $sth = $dbh->prepare("SELECT * FROM `garage` WHERE `uci` = ?"); $sth->execute(array($_POST['cars'])); while($cars = $sth->fetch()){ echo" ".$cars['uci'].", ".$cars['car_year']." ".$cars['car_name']." "; } } ?> |