PHP - Multiple Classes Sharing Same Values
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? Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
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>
This may sound like a very stupid question, but I can't find a clear answer anywhere. I'm making my first dive in OOP and all the tutorials only really show basic usage. They define a class, and show how to use it in a file. My question is how does it work to use an object throughout a program? Is it available everywhere or do I store things in sessions and start a new object on each page? For example: logging in a user. If I created an instance after confirming the credentials, would that same instance be available for use in say index.php, or would I just pass a session over and create a new instance on each page? Again, sorry if this seems dumb to some people. I've been spending long hours learning about classes and their magic methods. I just came across a tutorial which showed a constructor like this:
class Device { //... public function __construct(Battery $battery, $name) { // $battery can only be a valid Battery object $this->battery = $battery; $this->name = $name; // connect to the network $this->connect(); } //... }the Battery part instantly caught my attention. Here had previously made a Battery class (and a more complete Device class) but the next thing he did really caught my interest: $device = new Device(new Battery(), 'iMagic'); // iMagic connected echo $device->name; // iMagicwhat the hell is going on here? Is this another way to include the methods and properties of one class into another class, in order words is this the same thing as: class Device extends BatteryI don't think so because this new Battery() thing looks more like its creating an object inside the Device object. Previously the only way I could to that was to type $battery = new Battery() inside one of my methods. But this looks like hes doing something different. Can anyone explain whats going on here? The whole tutorial is he http://code.tutsplus...-php--net-13085 in the main Device method he has a premade $battery variable to hold the Battery object. Sometimes I have multiple classes containing functions which I'd like to include in my main class. I can only extend one class, so I usually extent a class containing only properties, no methods. I still don't know what difference making that info class abstract is, I'd appreciate if anyone could tell me. Also I'd love to know what the point in static methods is. I've never used them because I've never seen the point. Is it just to make it easier to call the methods because you don't need to create an object instance to call them? Sorry for the extra questions, the first one is what I'm really wondering about. during lesson time we're developing php systems and our topic is virtual storage like dropbox, google drive etc. My teacher has now set the task to enable the ability to share files within the server but also restrict access within the server folder. I'm being taught MySQL however I've read a lot about PDO being better and decided to use this method to try and get a higher grade for my project although I'm having difficulty understanding how to go about it what i want to achieve is:
creating file sharing capability (i.e. students can share group projects)
restricting users (only those working on a particular document can view it)
don't worry this is not for my own benefit I'm just trying to get a grade here, I mainly just want advice on what I need I've read quite a bit but unfortunately I'm more of a visual learner.
I'm running a site where people can post confessions, there's an option to share confession to twitter but it doesn't work properly.
When you click on twitter icon there is a window opening, you need to log in to twitter and then you have your tweet you want to share which looks like this:
Confessions.ie - Irish Anonymous Confessions Confession: I did it! http://www.confessio...e.php?page=view
problem is that url, "http://www.confessio...e.php?page=view" - it doesn't correspond to actual post, then when clicked it shows "-1" and that's it.
normal post url's would be something like this:
http://www.confessio...w&confession=18
http://www.confessio...w&confession=15
http://www.confessio...w&confession=12
Website is: confessions dot ie
and here's the code that I think contains error somewhe
<?php $confId = $_GET['confession']; $viewIp = $_SERVER['REMOTE_ADDR']; // Get the Full Page URL $pageURL = (isset($_SERVER['HTTPS']) ? "https" : "http")."//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $count = 0; $hasViewed = ''; $msgBox = ''; // Get the File Uploads Folder from the Site Settings $uploadsDir = $set['uploadPath']; // Check if Moderation is On $moderated = $set['moderation']; // Check if Profanity Filter is On $filterProfanity = $set['useFilter']; $chkViews = mysqli_query($mysqli,"SELECT 'X' FROM views WHERE confessId = ".$confId." AND viewIp = '".$viewIp."' LIMIT 1"); $hasView = mysqli_num_rows($chkViews); if ($hasView == 0) { $hasViewed = '0'; } $viewDate = date("Y-m-d H:i:s"); if ($hasViewed == '0') { $stmt = $mysqli->prepare(" INSERT INTO views( confessId, viewIp, viewDate ) VALUES ( ?, ?, ? ) "); $stmt->bind_param('sss', $confId, $viewIp, $viewDate ); $stmt->execute(); } // Add New Comment if (isset($_POST['submit']) && $_POST['submit'] == 'addComment') { // Validation if($_POST['commentText'] == "") { $msgBox = alertBox($commentsReq, "<i class='fa fa-times-circle'></i>", "danger"); } else if($_POST['answer'] == "") { $msgBox = alertBox($captchaCodeReq, "<i class='fa fa-times-circle'></i>", "danger"); } else if ($_POST['hole'] != '') { $msgBox = alertBox($commentsErrorMsg, "<i class='fa fa-times-circle'></i>", "danger"); $_POST['firstName'] = $_POST['commentText'] = $_POST['answer'] = ''; } else { $commentText = htmlentities($_POST['commentText']); $usersId = $mysqli->real_escape_string($_POST['usersId']); if ($_POST['firstName'] == '') { $firstName = null; } else { $firstName = $mysqli->real_escape_string($_POST['firstName']); } $commentDate = date("Y-m-d H:i:s"); // Moderation Check if ($moderated == '1') { $isActive = '0'; } else { $isActive = '1'; } // Check if the poster is a logged in user if (isset($_SESSION['userId'])) { $user = $_SESSION['userId']; } else { $user = '0'; } if(strtolower($_POST['answer']) == $_SESSION['thecode']) { $stmt = $mysqli->prepare(" INSERT INTO comments( confessId, userId, firstName, comments, commentDate, isActive, commentIp ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) "); $stmt->bind_param('sssssss', $confId, $user, $firstName, $commentText, $commentDate, $isActive, $viewIp ); $stmt->execute(); if ($moderated == '1') { $msgBox = alertBox($commentsSavedMsg1, "<i class='fa fa-check-square'></i>", "success"); } else { $msgBox = alertBox($commentsSavedMsg2, "<i class='fa fa-check-square'></i>", "success"); } // Clear the Form of values $_POST['firstName'] = $_POST['commentText'] = $_POST['answer'] = ''; $stmt->close(); } else { $msgBox = alertBox($captchaErrorMsg, "<i class='fa fa-warning'></i>", "warning"); } // If the confession is posted by a user if ($usersId != '0') { $uemail = "SELECT userEmail, recEmails FROM users WHERE userId = ".$usersId; $remail = mysqli_query($mysqli, $uemail) or die('-1' . mysqli_error()); $e = mysqli_fetch_assoc($remail); $userEmail = $e['userEmail']; $recEmails = $e['recEmails']; // If the users has opted in to receive notifications if ($recEmails == '1') { // Send out the email in HTML $installUrl = $set['installUrl']; $siteName = $set['siteName']; $siteEmail = $set['siteEmail']; $subject = $newCommentEmailSubject; $message = '<html><body>'; $message .= '<h3>'.$subject.'</h3>'; $message .= '<hr>'; $message .= '<p>'.nl2br($commentText).'</p>'; $message .= '<hr>'; $message .= '<p>'.$newCommentEmail1.' '.$pageURL.'</p>'; $message .= '<p>'.$subscribeEmail3.'<br>'.$siteName.'</p>'; $message .= '</body></html>'; $headers = "From: ".$siteName." <".$siteEmail.">\r\n"; $headers .= "Reply-To: ".$siteEmail."\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($userEmail, $subject, $message, $headers); } } } } // Get Confession $select = "SELECT confessId, userId, (IFNULL(firstName, '')) AS firstName, confessText, DATE_FORMAT(postDate,'%b %d %Y %h:%i %p') AS postDate, hasImage, isActive, (SELECT COUNT(*) FROM views WHERE views.confessId = confessions.confessId ) as totalViews, (SELECT COUNT(*) FROM likes WHERE likes.confessId = confessions.confessId ) as totalLikes, (SELECT COUNT(*) FROM dislikes WHERE dislikes.confessId = confessions.confessId ) as totalDislikes FROM confessions WHERE confessId = ".$confId; $res = mysqli_query($mysqli, $select) or die('-1' . mysqli_error()); $row = mysqli_fetch_assoc($res); if ($row['totalViews'] == '1') { $viewText = $singleViewText; } else { $viewText = $multipleViewsText; } $shareURL = $set['installUrl'].'page.php?page=view&confession='.$row['confessId']; $googleURL = $set['installUrl']; // Get Comments $qry = "SELECT commentId, confessId, (IFNULL(firstName, '')) AS fName, comments, DATE_FORMAT(commentDate,'%b %d %Y %h:%i %p') AS commentDate, isActive FROM comments WHERE confessId = ".$confId." AND isActive = 1 ORDER BY commentId DESC"; $results = mysqli_query($mysqli, $qry) or die('-2'.mysqli_error()); include('includes/header.php'); ?> <section id="main-container"> <div class="container"> <?php if ($msgBox) { echo $msgBox; } ?> <div class="confessbox"> <div class="confession"> <?php if ($row['hasImage'] == '1') { // Get Image $sqlStmt = "SELECT uploadId, confessId, uploadUrl FROM uploads WHERE confessId = ".$confId; $sqlres = mysqli_query($mysqli, $sqlStmt) or die('-2'.mysqli_error()); $col = mysqli_fetch_assoc($sqlres); //Get File Extension $ext = substr(strrchr($col['uploadUrl'],'.'), 1); $imgExts = array('gif', 'GIF', 'jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'tiff', 'TIFF', 'tif', 'TIF', 'bmp', 'BMP'); if (in_array($ext, $imgExts)) { echo '<p class="mb-20"><img alt="'.$confImageAlt.'" src="'.$uploadsDir.$col['uploadUrl'].'" class="img-responsive" /></p>'; } } ?> <p> <i class="fa fa-quote-left"></i> <?php if ($filterProfanity == '1') { echo nl2br(clean(filterwords($row['confessText']))); } else { echo nl2br(clean($row['confessText'])); } ?> <i class="fa fa-quote-right"></i> </p> <input type="hidden" id="confessId" name="confessId_<?php echo $count; ?>" value="<?php echo $row['confessId']; ?>" /> <div class="confession-footer"> <div class="likes"> <span class="label label-confess first liked"> <a href="" id="likeIt<?php echo $row['confessId']; ?>" class="likeIt_<?php echo $count; ?> text-success"> <i class="fa fa-smile-o"></i> <span id="likesVal_<?php echo $count; ?>"><?php echo $row['totalLikes']; ?></span> </a> </span> </div> <div class="dislikes"> <span class="label label-confess disliked"> <a href="" id="dislikeIt<?php echo $row['confessId']; ?>" class="dislike_<?php echo $count; ?> text-danger"> <span id="dislikesVal_<?php echo $count; ?>"><?php echo $row['totalDislikes']; ?></span> <i class="fa fa-frown-o"></i> </a> </span> </div> <span class="label label-confess"><?php echo timeago($row['postDate']); ?></span> <span class="label label-confess last"><?php echo $row['totalViews'].' '.$viewText; ?></span> <a href="https://twitter.com/intent/tweet?text=<?php echo $set['siteName']; ?>%20Confession:%20<?php echo ellipsis($row['confessText'],65); ?>%20&url=<?php echo $shareURL; ?>" class="btn btn-tw btn-sm" target="_blank" data-toggle="tooltip" data-placement="top" title="<?php echo $twitterShareTooltip; ?>"> <i class="fa fa-twitter"></i> </a> <a href="https://plus.google.com/share?url=<?php echo $googleURL; ?>" class="btn btn-gp btn-sm" target="_blank" data-toggle="tooltip" data-placement="top" title="<?php echo $googleShareTooltip; ?>"> <i class="fa fa-google-plus"></i> </a> <span class="label label-confess last hasVoted text-danger"><strong><?php echo $onlyVoteOnceText; ?></strong></span> <div class="comments"> <?php if ($row['firstName'] != '') { ?> <span class="label label-confess last"><?php echo $postedByText.' '.clean($row['firstName']); ?></span> <?php } else { ?> <span class="label label-confess last"><?php echo $postedByAnon; ?></span> <?php } ?> </div> </div> <div class="clearfix"></div> </div> </div> <?php if(mysqli_num_rows($results) > 0) { ?> <hr /> <div class="commentbox"> <?php while ($rows = mysqli_fetch_assoc($results)) { ?> <div class="comment"> <p> <?php if ($filterProfanity == '1') { echo nl2br(clean(filterwords($rows['comments']))); } else { echo nl2br(clean($rows['comments'])); } ?> </p> <?php if ($rows['fName'] != '') { ?> <span class="label label-comments"><?php echo clean($rows['fName']).' '.$commentedText.' '.timeago($rows['commentDate']); ?></span> <?php } else { ?> <span class="label label-comments"><?php echo $anonCommented.' '.timeago($rows['commentDate']); ?></span> <?php } ?> </div> <?php } ?> </div> <?php } ?> <hr /> <form action="" method="post" class="comment-form mt-30"> <div class="form-group"> <textarea class="form-control" name="commentText" id="commentText" rows="4" required="" placeholder="<?php echo $addCommentsField; ?>"><?php echo isset($_POST['commentText']) ? $_POST['commentText'] : ''; ?></textarea> </div> <div class="row"> <div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" name="firstName" placeholder="<?php echo $firstNamePlaceholder; ?>" value="<?php echo isset($_POST['firstName']) ? $_POST['firstName'] : ''; ?>"> </div> </div> <div class="col-md-4"></div> <div class="col-md-4"> <div class="row"> <div class="col-md-4"> <img src="includes/captcha.php" id="captcha" data-toggle="tooltip" data-placement="left" class="pull-right" title="<?php echo $captchaCodeTooltip; ?>" /> </div> <div class="col-md-8"> <div class="form-group"> <input type="text" class="form-control" name="answer" required="" maxlength="6" placeholder="<?php echo $captchaCodeTooltip; ?>"> </div> </div> </div> </div> </div> <div class="row"> <div class="col-md-8"> <p><?php echo $commentsQuip1; ?><strong><?php echo $isOn; ?></strong>. <?php echo $commentsQuip2; ?> <strong><?php echo $filtered; ?></strong>.</p> </div> <div class="col-md-4"> <input type="hidden" name="hole" id="hole" /> <input type="hidden" name="usersId" value="<?php echo $row['userId']; ?>" /> <button type="input" name="submit" value="addComment" class="btn btn-fessup btn-lg pull-right btn-icon"><i class="fa fa-check-square-o"></i> <?php echo $saveCommentsBtn; ?></button> </div> </div> </form> </div> </section> Hello. I want to make a simple website, where I can upload a zip file and download it from a URL with just HTTP GET request. When I download the file, the file will then be deleted on the server. Can't find any examples. Maybe, I've searched wrong. Has somebody some written project links or some tips for me how can I achieve this?
Is is possible to give multiple values in a single checkbox? i need to have a checkbox that holds multiple values. Help Anyone.. 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. 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) 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 I'm looking for a secure way to share session data across two different domains (not subdomains) on the same server. I've looked at passing the session id through a GET var to the other domain. It works but it looks to open the possibility of session hijacking and I don't really like having the session id in the URL string. Any way to make this secure? The other option I'm looking at is using cURL to load a script on the other domain that sets a cookie with the session id. When the person loads the other domain, check for the cookie, get the session id, connect to session then delete the cookie. Can anyone see anything wrong with this? Thanks. 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! 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. 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'>";}?> 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 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!
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'"; 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 guys, I am trying to create a script that gets a multiple select form selections and assign them to variables with php via the POST method. This is my code: Code: [Select] <select name="search_commodity[]" multiple="multiple" size="3" style="position:absolute; top:80px; left:414px; " > <option value="all">All</option> <option value="none">None</option> <option value="some">Some</option> </select> Then after the form gets submited then it should go to this php page and the first value of the chosen options has to be assigned to the variable called commo. The problem is that is is not assigning anything. Code: [Select] <?php $commo = $_POST['search_commodity[0]']; ?> Can someone help please? I can't figure it out. |