PHP - Looking For A Better Way To Remember & Display Drop Down Box Data
Hi everyone,
On my website i have a drop down box on the account information page that has a list of countries. In the example below, im using the php to do 2 things, 1: if the user changes the country and clicks submit but an error is found on the page, rather than revert back to the original country it stays as the newly selected one. 2: if the user does not change the country, the country from the database is simple displayed. As you can see below it is taking up quite a bit of code. I was wondering if anybody has any ideas how i can make this smaller? <select name="country"> <option value="select" selected>Select...</option> <option value="Afganistan" <?php if ($submit) { if ($country == "Afganistan"){ echo "selected";}} else {if ($row['country'] == "Afganistan") {echo "selected";}} ?>>Afghanistan</option> <option value="Albania" <?php if ($submit) {if ($country == "Albania"){echo "selected";}} else {if ($row['country'] == "Albania") {echo "selected";}} ?>>Albania</option> <option value="Algeria" <?php if ($submit) {if ($country == "Algeria"){echo "selected";}} else {if ($row['country'] == "Algeria") {echo "selected";}} ?>>Algeria</option> <option value="American Samoa" <?php if ($submit) {if ($country == "American Samoa"){echo "selected";}} else {if ($row['country'] == "American Samoa") {echo "selected";}} ?>>American Samoa</option> <option value="Andorra"<?php if ($submit) {if ($country == "Andorra"){echo "selected";}} else {if ($row['country'] == "Andorra") {echo "selected";}} ?>>Andorra</option> <option value="Angola"<?php if ($submit) {if ($country == "Angola"){echo "selected";}} else {if ($row['country'] == "Angola") {echo "selected";}} ?>>Angola</option> Thanks Similar TutorialsAs a complete newbie to php and webdesigning i have a following problem.I would like to retrieve the data from database and display it in a drop down menu.Then i should allow the user to select the values from drop down list along with other details,in other words i have to embed the drop down output as the form input for the user and store the form data in another table.I am running a xampp server and i am using php 5.4 version.Please help.My code is as follows.In this case project_name is displayed as the drop down output.but how do i use the same drop down output as a input in the form. <html> <head></head> <body> <?php error_reporting(E_ALL ^ E_DEPRECATED); include 'connect.php' ; $tbl_name="projects"; $sql="SELECT project_name FROM $tbl_name "; $result=mysql_query($sql); if($result === FALSE) { die(mysql_error()); } ?> <form name="resources" action="hourssubmit.php" method="post" > <?php echo "<select name='project_name'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['project_name'] ."'>" . $row['project_name'] ."</option>"; } echo "</select>"; ?> </form> </body> </html> This problem happens in both IE9 and Chrome 13.0.782.112 m on Windows If I close the browser down, my session data is gone on browser restart, if however I just close the tab leaving other tabs say with BBC news and restart my app in a new tab, both browsers remember the old session data. Since the intended user could do this at any time before completing a transaction, I don't actually get a chance to destroy the session this only happens if they complete payment for their order via.. Code: [Select] session_destroy(); $conn->commit(); $conn->autocommit(TRUE); In an attempt to clean up I tried various combinations at the top of the start page "index.php".. Code: [Select] session_start(); // $_SESSION = array(); session_destroy($_SESSION['cart']); session_destroy($_SESSION['address']); // $_SESSION['cart'] = array(); // $_SESSION['address'] = array(); // session_destroy(); Can anyone please shed any light on this behaviour difference? Jamie I have a drop down list which retrieves site name acronym and the url from the database. I need help in 2 things. 1.I do not want the url to be displayed in the drop down list. 2. When I hit submit I need to echo the sitename acronym as well as the url in a page called display.php. Here is my code so far: Code: [Select] <form action="display.php" method ="post"> <tr> <td>Category</td> <td> <select name="new_id"> <option value="">=============</option> <?php foreach($acronym as $key=>$value){ ?> <option value="<?php echo $value['site_id']; ?>"><?php echo $value['acronym']; ?></option> <option value="<?php echo $value['site_id']; ?>"><?php echo $value['url']; ?></option> <?php }?> </td> </tr> <input type="submit" name="submit" value="submit" /> </form> Hello there, i have a pretty simple problem, but i cant seem to get over it hence this post. I have a very simple form with 2 text boxes and a dropdown box. The user is supposed to insert an actor to the database using that form, but the thing is that i can't get the value from my dropdown box for some reason. Anyway here's the form. Code: [Select] <div id="content"> <?php if (isset($_POST["actorID"]) && isset($_POST["actorName"]) && isset($_POST["nation"])) { if ($_POST["actorID"] != "" && $_POST["actorName"] != "") { $link = mysql_connect('localhost', 'Ugluth', 'dracul'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("videoclub", $link); $sql="INSERT INTO actors (Actor_ID, Actor_Name, Actor_Nation) VALUES ('$_POST[actorID]','$_POST[actorName]','$_POST[nation]')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; mysql_close($link); } } else { echo "All fields need to be completed to add the record."; } } $link = mysql_connect('localhost', 'turu', 'tururu'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("videoclub", $link); $result_nation = mysql_query("SELECT * FROM nationalities"); $row = mysql_fetch_array($result_nation); mysql_close($link); ?> <form action="actor_add.php" method="post"> <table> <tr> <td> Actor ID: </td> <td> <input type="text" name="actorID"> </td> </tr> <tr> <td> Actor Name: </td> <td> <input type="text" name="actorName"> </td> </tr> <tr> <td> Actor Nationality ID: <?php ?> </td> <td> <select name="nation"> <?php while($row = mysql_fetch_array($result_nation)) { ?> <option value="<?php $row[0]; ?>"><?php echo $row[1]; ?></option> <?php } ?> </select> </td> </tr> </table> <?php mysql_free_result($result_nation); ?> <input type="submit" value="Submit" /> </form> </div> <!-- end #content --> I'm trying to enter the value to my query using '$_POST[nation]' on the $sql string i use for query. I have also tried just displaying it on the screen to see what value it holds, but it just wont show anything. Also i don't really need this answered for this particular problem, but in general its good to know, how can i select the value from the text of each option on the drop down box? The $row[0] holds the id while $row[1] holds the name. Thank you in advance and if u need any more information just let me know Name says it all. I have a form and 2 tables that are going to have to be linked with each other. Although what I'm trying to do now is very basic and I'm struggling haha Though this is my first php project Basicly I got a form with a drop down menu, which I want to display the contents of my table (course) which the user then selects from and submits to another table (student) Here is my code for this part <?php Code: [Select] <?php $q = "SELECT cname FROM course "; $result = mysql_query($q); $course = mysql_fetch_array($result); ?> <div id="apdiv3"> <FORM action = "demo.php" method ="post"> <p>Course name:</p> <select name="cname"> <OPTION> <?php echo $course['cname']; ?> </option> </SELECT>?> It only displays 1 item from my course table. What am I doing wrong? And also please explain so I can learn from my mistakes When I look at my page in source view the <br> are in the drop down but not working. Here is my php code along with the view source.
This is the main page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Water Analysis Data(WAD)</title> <style type="text/css"></style> </head> <body> <p align="center"><a href="../test/index.html">Home</a> | <a href="../test/register.php">Register</a> | <a href="../test/login.php">Login</a> | <a href="../test/tank.php">Add Tank</a> | <a href="../test/fish.php">Add Fish</a> | <a href="../test/water_test.php">Add Water Test</a></p> <p align="center"> </p> <table width="810" border="2" align="center"> <tr> <td><table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" bgcolor="#FFFFFF" scope="col"><h2><b>Water Analysis Data(WAD)</b></h2></td> </tr> <tr> <td bgcolor="#FFFFFF"> <form id="form1" method="POST" action="/include/waterparameters/water-parameters.inc.php"> <table border="2" align="center" cellpadding="0"> <tr> <td><div align="left"><b>Tank Name: </b> </div></td> <td><div align="left"> <select id="tankname" type='text' name="tankname"> <option> <?php include_once '/include/dropdowns/water-parameters-dd.inc.php'; ?> </option> </select> </div></td> </tr> <tr> <td><div align="left"><b>Test Date: </b> </div></td> <td><div align="left"> <input id="date" type="text" name="date" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Temperatu </b> </div></td> <td><div align="left"> <input id="temperature" type="text" name="temperature" size=25> </div></td> </tr> <tr> <td><div align="left"><b>pH: </b> </div></td> <td><div align="left"> <input id="ph" type="text" name="ph" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Ammonia: </b> </div></td> <td><div align="left"> <input id="ammonia" type="text" name="ammonia" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Nitrite: </b> </div></td> <td><div align="left"> <input id="nitrite" type="text" name="nitrite" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Nitrate: </b> </div></td> <td><div align="left"> <input id="nitrate" type="text" name="nitrate" size=25> </div></td> </tr> <tr> <td><div align="left"><b>phosphate: </b> </div></td> <td><div align="left"> <input id="phosphate" type="text" name="phosphate" size=25> </div></td> </tr> <tr> <td><div align="left"><b>GH: </b> </div></td> <td><div align="left"> <input id="gh" type="text" name="gh" size=25> </div></td> </tr> <tr> <td><div align="left"><b>KH: </b> </div></td> <td><div align="left"> <input id="kh" type="text" name="kh" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Iron: </b> </div></td> <td><div align="left"> <input id="iron" type="text" name="iron" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Potassium: </b> </div></td> <td><div align="left"> <input id="potassium" type="text" name="potassium" size=25> </div></td> </tr> <tr> <td><div align="left"><b>Notes: </b> </div></td> <td><div align="left"> <p> <textarea id="notes" name="notes" cols="50" rows="10"></textarea> </p> </div></td> </tr> <tr> <th colspan=2><p> <input type="submit" value="Submit"id="submit1" class="submit" name="submit" /> </p></th> </tr> </table> </form></td> </tr> <tr> <td align="center" valign="top" bgcolor="#FFFFFF"><div align="center"><font size=2> © 2014 <a href="http://www.pctechtime.com">PC TECH TIME</a> </font> </div></td> </tr> </table></td> </tr> </table> </body> </html>This is the include for the page (the echo line for <br> shows in the source but doesn't produce the break <?php include_once "/include/db/db.inc.php"; $result = mysqli_query($con,"SELECT tankname FROM tank"); while($row = mysqli_fetch_array($result)) { echo $row['tankname']; echo "<br>"; } mysqli_close($con); ?>Here is the source when you bring the file up in a browser <select id="tankname" type='text' name="tankname"> <option> Tank 1<br>Tank 2<br>Tank 3<br> </option> </select> Hello my problem here is to have a drop down menu which gathers usernames from the database. Then with a click of a button the information for that specific user selected is shown. I'm close code wise but right now it's just showing me all users. I'm displaying the info in text box's to allow an admin to change the info.
<form action="edit.php" method="post"> <select name="username" id="username"> <?php // Connects to your Database $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } $query = "SELECT `username` FROM `bencobricks` . `users`"; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); if($result) { while($row = mysqli_fetch_assoc($result)) { //printf ("%s\n %s\n ", echo "<label for='username'>Username: </label> <option value='$row[username]'>$row[username] </option><br/>"; echo "<br/><br/> "; } } mysqli_close($con); ?> </select> <br /> <input name="send" id="send" type="submit" value="Edit User" /> </form>Then in the edit.php file i have this code: <?php // Connects to your Database $con=mysqli_connect('localhost', 'root', ''); /* check connection */ if (mysqli_connect_errno($con)) { trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR); } if (isset($_POST['send'])) { $username = $_POST['username']; $query = "SELECT * FROM `bencobricks` . `users` "; $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); // Print the result if($result) { while ($row = mysqli_fetch_assoc($result)) { // $query = "SELECT * FROM `bencobricks` . `users` WHERE `username` = username = $row[username]"; printf ("%s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n", "<label for='username'>Username: </label> <input type='text' name='username' value='$row[username]'>" . "</input><br/>", "<label for='email'>Email: </label> <input type='text' name='email' value='$row[email]'>" . "</input><br/>", "<label for='membership'>Membership: </label> <input type='text' name='membership' value='$row[membership]'>" . "</input><br/>", "<label for='firstName'>First name: </label> <input type='text' name='firstName' value='$row[firstName]'>" . "</input><br/>", "<label for='lastName'>Last name: </label> <input type='text' name='lastName' value='$row[lastName]'>" . "</input><br/>", "<label for='gender'>Gender: </label> <input type='text' name='gender' value='$row[gender]'>" . "</input><br/>", "<label for='dateOfBirth'>Birthdate: </label> <input type='text' name='dateOfBirth' value='$row[dateOfBirth]'>" . "</input><br/>", "<label for='date'>Date: </label> <input type='text' name='date' value='$row[date]'>" . "</input><br/>", "<label for='sets'>Sets: </label> <input type='text' name='sets' value='$row[sets]'>" . "</input><br/>", "<label for='checkbox'>Checkbox: </label> <input type='text' name='checkbox' value='$row[checkbox]'>" . "</input><br/>", "<label for='admin'>Admin? </label> <input type='text' name='admin' value='$row[adminFlag]'>" . "</input><BR>", "<br/><br/> "); } } } mysqli_close($con); ?>Any help is greatly appreciated. Hi I have coded a drop down menu with php and i am trying to retrieve the data when a user select a option from the menu and the data is retrieved from the database. So far i have tried and nothing is displaying when i tried to process the php form. Sales.php Page <form action="saleprocess.php" method="GET"> <?php echo 'Product Model:'; $query="SELECT * FROM products"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=product_model value=Select>Product Model</option>"; // printing the list box select command while($rows=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option name=product_model value='.$rows[product_id].'>$rows[product_model]</option>"; /* Option values are added by looping through the array */ } echo "</select><br>"; ?> <input type='submit' name='submit' value='Create'></input> <br> </form> ******************************************************************************** Salesprocess.php page <?php include("connect.php"); if(isset($_GET['product_id'])){ $product_id = $_GET['product_id']; $query = mysql_query("SELECT * FROM products WHERE product_id= $product_id"); while($rows = mysql_fetch_assoc($query)) { echo 'Product Model<br>'; echo $rows['product_id']; echo $rows['product_model']; } } ?> Muchly appreciated if someone can help me Hey guys, I have a drop down menu like so <select name="Categories[]"> <Option value="Horror" Name="Horror">Horror</Option> <Option value="Romance" Name="Romance">Romance</Option> ......................................... Like that, just out of interest once the user has selected the option I am unsure on how to extract what the user chose from the drop down menu, how do you grab the value from array of the drop down menu that the user has selected. Any help A.S.A.P would really be appreciated. It also has to be an array. I also thought of using the $_POST['Categories']; to try grab the value if that is the correct way to go about it. Thank you in advance. Alright so I created a MySQL database that has 5 tables each named a brand of a dirt bike. In each table their are 2 fields, one INDEX_ID and MODELS. Under that for rows I have every model bike named. A quick question before I get onto what I want to do: Can data be added underneath the rows? For example, users will be able to submit information about each bike model. If each bike model is a row, can there be a category past that row or do I need to make each field a model name and just have a ton of fields and have the rows be the information users submit. To make it easier to understand I'll post the SQL code for the brand Honda: CREATE TABLE `Honda` ( `INDEX_ID` int(3) NOT NULL auto_increment, `MODELS` varchar(20) collate latin1_general_ci NOT NULL, PRIMARY KEY (`INDEX_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=23 ; -- -- Dumping data for table `Honda` -- INSERT INTO `Honda` VALUES(1, 'CR85'); INSERT INTO `Honda` VALUES(2, 'CR125'); INSERT INTO `Honda` VALUES(3, 'CR250'); INSERT INTO `Honda` VALUES(4, 'CRF100'); INSERT INTO `Honda` VALUES(5, 'CRF150'); INSERT INTO `Honda` VALUES(6, 'CRF230'); INSERT INTO `Honda` VALUES(7, 'CRF250X'); INSERT INTO `Honda` VALUES(8, 'CRF250R'); INSERT INTO `Honda` VALUES(9, 'CRF450X'); INSERT INTO `Honda` VALUES(10, 'CRF450R'); INSERT INTO `Honda` VALUES(11, 'CRF50'); INSERT INTO `Honda` VALUES(12, 'CRF70'); INSERT INTO `Honda` VALUES(13, 'CRF80'); INSERT INTO `Honda` VALUES(14, 'XR650'); INSERT INTO `Honda` VALUES(15, 'CR500'); INSERT INTO `Honda` VALUES(16, 'XR100'); INSERT INTO `Honda` VALUES(17, 'XR200'); INSERT INTO `Honda` VALUES(18, 'XR250'); INSERT INTO `Honda` VALUES(19, 'XR400'); INSERT INTO `Honda` VALUES(20, 'XR50'); INSERT INTO `Honda` VALUES(21, 'XR70'); INSERT INTO `Honda` VALUES(22, 'XR80'); Anyway I still need to figure out how to have this under a form that a user can use to select the bike they want to submit information about. A code like this perhaps?: <? $connection = mysql_connect("localhost","user","pass"); $fields = mysql_list_fields("dbname", "table", $connection); $columns = mysql_num_fields($fields); echo "<form action=page_to_post_to.php method=POST><select name=Field>"; for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } echo "</select></form>"; ?> Thanks. Hello, I just reach the ultimate high in frustration because i can not display all the data from my database in a table using php. Im trying to display all the members from my database (id, username, email and account type) in my admin cp, and what is happening is that i am displaying all my data in one td. (Ex, in the <td></td>, it will display all the usernames at once, rather than separating them). Code: [Select] <?php include_once "../config.php"; include_once "admin_check.php"; $get_members = mysql_query("SELECT * FROM members ORDER BY id"); while ($row = mysql_fetch_array($get_members)) { $id .= $row['id']; $username .= $row['username']; $account_type .= $row['account_type']; $email .= $row['email']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome Admin!</title> </head> <body> <h1>Welcome admin! <a href='../index.php'> Click here to go back! </a></h1> <table cellspacing="5" cellpadding="5" style="border: black thin solid" align="center"> <tr> <td>ID</td> <td>Username</td> <td>Email</td> <td>Account Type</td> </tr> <tr> <td><?php echo $id;?></td> <td><?php echo $username;?></td> <td><?php echo $email;?></td> <td><?php echo $account_type;?></td> </tr> </table> </body> </html> Now i tried making the table in the while loop, but i am also having the same problem. Please help. Hi all. The following is a function to get and display data. However, I've hit a wall in my progress. It's only printing out one field. I need to have it print out every retrieved field. Any help is appreciated. function get_data($table_name){ $result=mysql_query("SELECT * FROM $table_name"); $num=mysql_num_rows($result); $i=0; while($i < $num){ $fields=mysql_fetch_field($result,$i); $display_fields=mysql_result($result,$i,$fields->name); echo $display_fields; $i++; }; }; I realized that (I think) I need the $display_fields var to be concatenated with the $i variable so there's a unique var name for each field retrieved from the mysql_fetch_field line. Any ideas? Hello. What I have created is a menu with links. The links will display content on the page from a database. I have the links with id displayed, but nothing is displayed when the link is clicks. I have seen isset() and $_GET used but not a form and I don't know how to change the code to allow the display of data using ID. My site is local, and I am using XAMPP. The database connections work. This is my code: // query $query = "SELECT * FROM topmenu ORDER BY id ASC"; $row = $PDO->query($query); .... <table class="topmenu"> <tr> <td> <h1 class="siteName">site title</h1> </td> <?php foreach($row as $data) { ?> <td><a href="index.php?id=<?php echo $data['id']; ?>"> <?php echo $data['menuheader']; ?> </a></td> <?php } ?> </tr> </table> As a beginner, I would appreciate any help, no criticism of my code please! Also, is there a way of hiding the id in the url? Thanks in advance. Hi guys, basically here pull out the data from database then creating taxt field automatically and submit into anther table. everything works fine but data not inserting in to the table. could you guys check my code please? <?php $con = mysql_connect("localhost","root",""); mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); ?> <?php $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">'. $row['CourseID'] .'</option>'; } echo '</select>'; //------------------ ?> <?php if(!empty($_POST["submit"])) { $value = empty($_POST['question']) ? 0 : $_POST['question']; ?> <form name="form1" method="post" action="result.php"> <?php for($i=0;$i<$value;$i++) { echo 'Question NO: <input type="text" name="qno[]" size="2" maxlength="2" class="style10"> Enter Marks: <input type="text" name="marks[]" size="3" maxlength="3" class="style10"><br>'; } ?> <label> <br /> <br /> <input type="submit" name="Submit" value="Submit" class="style10"> </label> </form> <?php } else{ ?> <form method="POST" action="#"> <label> <span class="style10">Enter the Number of Question</span> <input name="question" type="text" class="style10" size="2" maxlength="2"> </label> <input name="submit" type="submit" class="style10" value="Submit"> </form> <?php }?> result.php <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("uni",$con) or die('Could not connect: ' . mysql_error()); foreach ($_POST['cid'] as $c) {$cid [] = $c;} foreach($_POST['qno'] as $q){$qno[] = $q;} foreach($_POST['marks'] as $m){$marks[] = $m;} $ct = 0; for($i=0;$i<count($qno);$i++) { $sql="INSERT INTO examquesion (CourseID,QuesionNo,MarksAllocated) VALUES('$cid[$i]','$qno[$i]','$marks[$i]')"; mysql_query($sql,$con) or die('Error: ' . mysql_error()); $ct++; } echo "$ct record(s) added"; mysql_close($con) ?> I am developing a script for hospital. I have wards like General, Delux, ICU etc. Each ward can have number of patients. Each nurse will be allocated to some wards in weekly basis. Now I want to display for the nurse that how many patients are there in the ward which is allocated to her/him on that week. Here is my wards table
Here is my ward allotment for each nurse
And patient admitted details i get from admission table, which is like this
Now i want to show result like this
From 16/09/2019 to 22/09/2019 General Ward Patient bed No shift HSSC022 3 1 ICU HSSC014 1 1 I have written query like this, but it doesn't show this way $firstday = date('Y-m-d', strtotime("this week monday")); $lastday = date("Y-m-d", strtotime("this week sunday")); "SELECT wa.sdate, DAYNAME(wa.sdate) AS Day, wa.shift, w.ward_name, a.patient_id, a.ward, p.patient_name FROM ward_allotment wa INNER JOIN admission a ON wa.ward=a.ward INNER JOIN patient p ON a.patient_id=p.patient_id INNER JOIN wards w ON wa.ward=w.wid WHERE wa.week=".$_SESSION['Cweek']." AND a.from_date>='".$firstday."' AND a.discharge_date='0000-00-00' AND wa.nurse=".$_SESSION['user_id']." GROUP BY a.patient_id"; Can somebody help me how to do it.
Hi there I never had any php lessons. But I made a site, and now I'm kinda sorta working on a CMS so that someone else can edit the information on the site. Now I was wondering if there was a simple way of displaying all the data from a table, and editing it (not in phpmyadmin). This is my current method; it's rather sloppy but it works like a charm: Code: [Select] mysql_select_db('yourdatabase')or die(mysql_error()); $query = mysql_query("SELECT * FROM activiteit ORDER BY datum"); if(isset($_POST['editActiviteit'])){ $id = mysql_real_escape_string(htmlentities($_POST['id'])); }else{ $id = ''; } echo "<table border='1'><tr><th>Begindatum</th><th>Einddatum</th><th>Titel</th><th>Omschrijving</th><th>Zichtbaar?</th><th>Aanpassen</th><th>Verwijderen</th><th>Voorbeeld</th></tr>"; while($row = mysql_fetch_array($query)){ if($id == $row['id']){ if(empty($row['einddatum'])){ $einddatum = "<input type='text' size='2' name='activiteitDagEind' placeholder='dd' />/<input type='text' size='2' maxlength='2' name='activiteitMaandEind' placeholder='mm' />/<input typ='text' size='4' maxlength='4' name='activiteitJaarEind' placeholder='jjjj' />"; }else{ $explode = explode('/',$row['einddatum']); $einddatum = "<input type='text' size='2' name='activiteitDagEind' value='$explode[0]' />/<input type='text' size='2' maxlength='2' name='activiteitMaandEind' value='$explode[1]' />/<input typ='text' size='4' maxlength='4' name='activiteitJaarEind' value='$explode[2]' />"; } $explode2 = explode('/',$row['datum']); $datum = "<input type='text' size='2' name='activiteitDag' value='$explode2[0]' />/<input type='text' size='2' maxlength='2' name='activiteitMaand' value='$explode2[1]' />/<input typ='text' size='4' maxlength='4' name='activiteitJaar' value='$explode2[2]' />"; if($row['actief'] == 0){ $actief = "<select name='actief'><option value='1'>1</option><option value='0' selected='selected'>0</option></select>"; }else{ $actief = "<select name='actief'><option value='1' selected='selected'>1</option><option value='0'>0</option></select>"; } echo "<form action='ward.php' method='post'>"; echo "<tr><td>$datum</td><td>$einddatum</td><td><input type='text' name='activiteitTitel' value='".$row['titel']."' /></td><td><textarea name='activiteitOmschrijving'>".$row['omschrijving']."</textarea></td><td>$actief</td><td><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='Slaag op' name='saveActiviteit' /></form></td><td><form action='ward.php' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' name='verwijderActiviteit' value='verwijderen' /></form></td><td><input type='button' disabled='disabled' value='Voorbeeld' /></td></tr>"; }else{ echo "<tr><td>".$row['datum']."</td><td>".$row['einddatum']."</td><td>" . $row['titel'] . "</td><td>" . bbcode_format($row['omschrijving']) . "</td><td>" . $row['actief']."</td><td><form action='ward.php?fx=activiteit' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='Pas aan' name='editActiviteit' /></form></td><td><form action='ward.php' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='verwijderen' name='verwijderActiviteit' /></form></td><td><input type='button' value='Voorbeeld' onClick=\"parent.location='ward.php?fx=activiteit&voorbeeld=".$row['id']."'\" /></td></tr>"; } } echo "</table><br /><br />"; I just copy pasted all the code but I'll explain it in big lines: First I open a table. I manually enter a row with the headers. Then every result of the query gets shown in a cell. The last cells of each row contain a delete and an edit button. The delete button deletes that row with the hidden id and reloads the page. When the edit button is clicked, it sends a form with the name of the button, here 'editActiviteit', and the id of the entry. And then the page gets reloaded. When the query is then done again, it checks if $_POST['editActiviteit'] is set, and if it is, it displays input fields with the values in the cells instead of pure text, and a save button instead of a edit button. The system works just fine, but it's heaps of work every time I implement it, for activities, users, ... Also I've been told that table's are not the correct way for displaying results (and they also get a little stretched). How should it be displayed? Thanks in advance. It's very possible, and I've seen a website that's done it (http://www.zybez.net/radio/) - They are able to include the recent songs played on there website. The information can be obtained from right he http://68.168.100.60:7942/played.html But I'm not sure if thats where they get it from. If I login to my Admin section, there will be an option that says get XML stats. But I'm not sure if that shows the recent songs played like it would at http://68.168.100.60:7942/played.html (Everytime I refresh the page, the stats/data/info in the XML change) Code: [Select] 1250001522Rockhttp://srbuckey.listen2myradio.comMusicPEAK - RockKings of Leon - Radioactive N/AN/AN/A226153140audio/mpeg1.9.86201901701119000000004013207.144.125.60NSPlayer/11.0.6001.7006 WMFSDK/11.0026101521287587284Kings of Leon - Radioactive 1287586919Three Days Grace - Riot 1287586542Alice In Chains - Here Comes The Rooster 1287586281Green Day - Boulevard of Broken Dreams 1287586277down 1287586075Green Day - American Idiot 1287586044Metallica - Enter Sandman 1287585836ACDC Highway To Hell.mp3 1287585449Metallica - 04 The Unforgiven I.MP3 1287585448[HTTP/1.1 200 OK] http://www.ventsi.com/Music/MetallicA/1991 - Black Album/Metallica - 04 The Unforgiven I.MP3 Hi, i need help for get data from following tables:
questions:
id
question
options:
id
ques_id
value
votes:
id
option_id
voted_on
ip
Question: What is your favorite color.
Option1: Test 1 - 83 votes
Option2: Test 2 - 0 votes
Option3: Test 3 - 51 votes
I'm using this sql for result:
SELECT options.id, options.value, COUNT(*) as votes FROM votes, options WHERE votes.option_id=options.id AND votes.option_id IN(SELECT id FROM options WHERE ques_id=2) GROUP BY votes.option_id;so i get this: id value votes 1 Test1 83 3 Test3 51 because there is not votes for option Test2 and doesn't show it. i need help to get all data like this: id value votes 1 Test1 83 2 Test2 0 3 Test3 51 I am managing a shop website which is using php and mysql for data. The website has a section that will display the related products with the one that you are watching. Now my problem is that if there are more than 5 items it will continue to display all the items in one row with the consequent that the page will not display well. I need to find a way to begin a new row after the 5th item so it will display 5 items in each row. this is my current code that is responsible for showing the related items. There is also a picture attached with the problem. while ($row = mysql_fetch_array($retd)) { $code = $row["code"]; $name = $row["name"]; echo("<td width=150 align=center>"); echo ("<a href=../products/info.php?scode=$code><img src=pictures/$code.gif border=0 alt=Item $name</a>"); echo ("<br><a href=../products/info.php?scode=$code><span class=fs13>$name</span></a>"); echo("</td>"); } Does anyone know how can I do this? I want to fetch data from a table let's say table "activities". Uid | day | activity | time | remarks 1. Mon. Act1. 3pm. Good 2. Mon. Act1. 5pm. Bad 1. Tue. Act2. 12am. Bad 1. Tue. Act5. 1am. Bad 1. Thur. Act8. 9pm. Good 2. Wed. Act4. 7am. Good
Now assuming I want to fetch all the data that is related to user Id 1 and display them in another table (Uid 1). Which is 4 rows according to the table, how do I go about it using select query? Thanks!!! I tried something like this but it displays just one row <?php $uid = $_SESSION['login']; $sql2 = "SELECT * FROM Activities WHERE uid=? ORDER BY Uid LIMIT 6"; $stmt2 = $connection->prepare($sql2); $stmt2->bind_param('i', $Uid); $stmt2->execute(); $result2 = $stmt2->get_result(); $row2 = $result2->fetch_assoc(); //now am stuck here ?> now trying to display the fetch those data for only Uid 1 in these simple format...
<table style="width:100%"> <tr> <th>Day</th> <th>Activity</th> <th>Remarks</th> </tr> <tr> <td>Mon</td> <td>Act1</td> <td>Good</td> </tr> <tr> <td>Tue</td> <td>Act2</td> <td>Bad</td> </tr> <tr> <td>Tue</td> <td>Act5</td> <td>Bad</td> </tr> </table>
|