PHP - Selecting Values From A Table Based On The Value Of Certain Fields In The Table.
Hi All ,
I have a small table with 4 fields namely Day_ID, Dues, Last_Visit, Points. where Day_ID is an auto-increment field. The table would be as follows:
Day_ID -- Dues --- Last_Visit --- Points.
1 --------- 900 -------- 1/12 -------- 6
2 --------- 700 -------- 4/12 -------- 7
3 --------- 600 -------- 7/12 -------- 5
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
So this is the record of a person's visit to say a club. The last row indicates the last date of his visit to the club. His points on this date are 6. Based on this point value of 6 in the last row I want to retrieve all the previous BUT adjoining all records that have the same Points i.e. 6.
So my query should retrieve for me, based on the column value of Points of the last row (i.e. Day_ID - 6 ), as follows:
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
This problem stated above had been completely resolved, thanks to a lot of help from Guru Barand by this following query :-
$query = "SELECT cv.day_id, cv.dues, cv.last_visit, cv.points FROM clubvisit cv WHERE last_visit >= ( SELECT MAX(last_visit) FROM clubvisit WHERE points <> ( SELECT points as lastpoints FROM clubvisit JOIN ( SELECT MAX(last_visit) as last_visit FROM clubvisit ) as latest USING (last_visit) ) )";I am using this and it works perfectly except that now there is a slight change in the table because the criteria for points is now dependent on more than one column cv.points and is more like cv.points1, cv.points2, cv.points3 etc. So now I need to make a selection based on each of these cv.points columns. As of now I can still get the results by running the query multiple times for each of the cv.points columns ( seperately for cv.points1, cv.points2, cv.points3) and it works correctly. However I am wondering if there is a better way to do this in just one go. This not only makes the code repetitive but also since the queries are interconnected, involves the use of transactions which I wish to avoid if possible. The values that I require for each of the cv.point columns is 1. day_id of the previous / old day on which the cv.points value changed from the current day value, and 2. cv.points on that old/ previous day. So for example if the table is as below: Day_ID -- Dues --- Last_Visit --- Points1 --- Points2. 1 --------- 900 -------- 1/12 ----------- 9 ------------ 5 2 --------- 600 -------- 4/12 ----------- 6 ------------ 6 3 --------- 400 -------- 7/12 ----------- 4 ------------ 7 4 --------- 500 -------- 9/12 ----------- 5 ------------ 8 5 --------- 600 -------- 10/12 ---------- 6 ------------ 8 6 --------- 600 -------- 11/12 ---------- 6 ------------ 8 7 --------- 600 -------- 13/12 ---------- 6 ------------ 7 8 --------- 500 -------- 15/12 ---------- 5 ------------ 7 9 --------- 500 -------- 19/12 ---------- 5 ------------ 7 Then I need the following set of values : 1. day_id1 -- Day 7, points1 ---- 6, days_diff1 -- (9-7 = 2) . // Difference between the latest day and day_id1 2. day_id2 -- Day 6, points2 ---- 8, days_diff2 -- (9-6 = 3) 3. day_id3 -- .... and so on for other points. Thanks all ! Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
I have 3 tables w/ the following fields: Cities id | state_id | city_name States id | state_name New_cities id | state_id | city_name I am trying to write a script (and still working on it) that will INSERT new cities in cities WHERE New_cities.state_id = Cities.state_id. Obviously I am still in testing and results sort out, but honest to all hell, I might be going about this all wrong, and would appreciate any comments, criticism, assistance or feedback on what I am trying to do. <?php $query = "SELECT * FROM cities, states, new_cities"; if ($results = mysqli_query($cxn, $query)) { $row_cnt = mysqli_num_rows($results); echo $row_cnt . " Total Records in Query.<br /><br />"; if (mysqli_num_rows($results)) { while ($row = mysqli_fetch_array($results)) { if ($row['cities']['state_id'] == $row['new_cities']['new_state_id']) { $insert_city_query = "INSERT INTO cities id, new_state_id, city_name VALUES ('','$new_state_id','$city_name')" or mysqli_error(); } //if ($row['cities']['state_id'] == $row['new_cities']['new_state_id']) echo "$row[new_city_name]<br />"; } //while ($row = mysqli_fetch_array($results)) } //if (mysqli_num_rows($results)) } //if ($results = mysqli_query($cxn, $query)) ?> Hi All,
I want to copy into a table values from another table that partially match a given value, case-insensitively. So far I do as follows but I wonder whether there is a quicker way.
$input_table=array('1'=>'toto','2'=>'tota','3'=>'hello','4'=>'TOTO','5'=>'toto'); $input_table_2 = array_map('strtolower', $input_table); $value_to_look_for='Tot'; $value_to_look_for_2=strtolower($value_to_look_for); $output_table=array(); foreach ($input_table_2 as $k=>$v) { if(false !== strpos($v, $value_to_look_for_2)) { $output_table[]=$input_table[$k]; } }One drawback is that $input_table_2 is 'foreached' whereas there might be no occurrences, which would lead to a loss of time/resources for big arrays. Thanks. Hello, I need some help. Say that I have a list in my MySQL database that contains elements "A", "S", "C", "D" etc... Now, I want to generate an html table where these elements should be distributed in a random and unique way while leaving some entries of the table empty, see the picture below. But, I have no clue how to do this... Any hints? Thanks in advance, Vero This is a little confusing so please bear with me. I was thinking of using left.join but couldn't figure out how to implement it properly. I am trying to order all of the results from a table names 'clans' based on how many points the clan has. To calculate the points you have to go into another table 'clanteams' and then loop every team in the clan pulling wins and losses from a row in a specific ladder table. Here is the code i have to calculate the points. Code: [Select] $total[wins] = 0; $total[loss] = 0; $members=mysql_query("SELECT id,clanid,teamid,DATE_FORMAT(datejoined,'%M %d, %Y') FROM clanteams WHERE clanid='$member[id]'"); while(list($id,$clanid,$teamid,$joined)=mysql_fetch_row($members)){ $team=mysql_query("SELECT name,ladderid FROM teams WHERE id='$teamid'"); if(mysql_num_rows($team) == 0) continue; $team=mysql_fetch_array($team); $ladder=mysql_query("SELECT name FROM ladders WHERE id='$team[ladderid]'"); $ladder=mysql_fetch_array($ladder); $linfo=mysql_query("SELECT rank,wins,loss FROM ladder_$team[ladderid] WHERE teamid='$teamid'"); $linfo=mysql_fetch_array($linfo); $total[wins] = $total[wins] + $linfo[wins]; $total[loss] = $total[loss] + $linfo[loss]; } $totalpoints = ($total[wins] * 2) - $total[loss]; So now i want to loop through every row in the clans table, and using the above code oder them by $total points. Ive spent hours wrapping my head around it and still cannot figure it out. Please help. I have a table called users with a fieldname called service_id. In a table called services I have id and name. I want to query the users table and, based on the service_id, display the name of the service (which is stored in the services table). However, when I try this code I get No records returned. I later echo out under a while statement $row['name']; or $row['id'] $query = "SELECT users.username, users.lname, users.fname, users.service_id, services.name, services.id FROM users, services WHERE users.inst_id = '".$userarray['inst_id']."' and users.id !='".$userarray['id']."' and users.service_id = services.id "; Hi, I've got a basic sign up form but I want a drop down list which will list different catergories that relate to different tables which when selected will input the sign up information into that table which was selected from the catergory drop down. This is the signup form <html><head><title>Birthdays Insert Form</title> <style type="text/css"> td {font-family: tahoma, arial, verdana; font-size: 10pt } </style> </head> <body> <table width="300" cellpadding="5" cellspacing="0" border="2"> <tr align="center" valign="top"> <td align="left" colspan="1" rowspan="1" bgcolor="64b1ff"> <h3>Insert Record</h3> <form method="POST" action="test.php"> <? print "Enter Company Name: <input type=text name=company_name size=30><br>"; print "Enter Contact Name: <input type=text name=contact_name size=30><br>"; print "Enter Telephone: <input type=text name=telephone size=20><br>"; print "Enter Fax: <input type=text name=fax size=30><br>"; print "Enter Email: <input type=text name=email size=30><br>"; print "Enter Address: <input type=text name=address1 size=20><br>"; print "Enter Address: <input type=text name=address2 size=30><br>"; print "Enter Postcode: <input type=text name=postcode size=30><br>"; print "Enter Town / City: <input type=text name=town_city size=20><br>"; print "Enter Website: <input type=text name=website size=30><br>"; print "Enter Company Type: <select name='table'> <option>stationary</option><option>reception</option></select><br>"; print "<br>"; print "<input type=submit value=Submit><input type=reset>"; ?> </form> </td></tr></table> </body> </html> This is the part which I can't figure out and is probably totally wrong! Im trying to use this script to sort the drop down list to then run the correct script to insert the form data. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Hello!</title> </head> <body> <?php if($_POST['table']=='stationary' 'birthdays_insert_record.php') else if($_POST['table']=='reception' 'insert_reception.php') ?> </body> </html> This is the script which works! that inserts the form data into a specific table <html><head><title>Birthdays Insert Record</title></head> <body> <? /* Change db and connect values if using online */ $company_name=$_POST['company_name']; $contact_name=$_POST['contact_name']; $telephone=$_POST['telephone']; $fax=$_POST['fax']; $email=$_POST['email']; $address1=$_POST['address1']; $address2=$_POST['address2']; $postcode=$_POST['postcode']; $town_city=$_POST['town_city']; $website=$_POST['website']; $db="myflawlesswedding"; $link = mysql_connect('localhost', 'root' , ''); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Select Error: ".mysql_error()); $result=mysql_query("INSERT INTO reception (company_name, contact_name, telephone, fax, email, address1, address2, postcode, town_city, website) VALUES ( '$company_name', '$contact_name', '$telephone', '$fax', '$email', '$address1', '$address2', '$postcode', '$town_city', '$website')") or die("Insert Error: ".mysql_error()); mysql_close($link); print "Record added"; ?> <form method="POST" action="birthdays_insert_form.php"> <input type="submit" value="Insert Another Record"> </form> <br> <form method="POST" action="birthdays_dbase_interface.php"> <input type="submit" value="Dbase Interface"> </form> </body> </html> I hope somebody can help me out here! or can point me in a better way to sort this problem! Thanks for any advice! Hi All, I am trying to pull a record from my table using the date of birth column (which is a date column) like so.. Code: [Select] $birthday = ('1936-08-21'); $query = "Select * from my_table where dob = $birthday"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ echo "Name is - " .$row['name']; } I know there is a record in the table with a date of birth(dob) value of 1936-08-21 but it does not return any records ? thanks for looking, Tony 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>
Can someone please tell me how to use the "SHOW FIELDS FROM $mytable" in php? I understand how the MySql works but need to get these fields back into an array in php. That is the part I am strruggling with.. I normally return rows of data from my table and use a while loop. Hi all, So I'm not completely sure on how to do this, but basically this i what i want. I want the users to be able to create "fields" in my table, so let's say we have a structure like this: Field 1 Field 2 Field 3 Data 1 Data 2 Data 3 Problem is, that i want my users to update both the <td> and <tr> information via mysql, without altering the database. And I'm not sure on how I can make sure, that everything gets out in the right order. I have this so far: Code: [Select] <table id="sort-table"> <thead> <tr> <?PHP echo ' <td> Identifier </td> '; $result = mysql_query("SELECT * FROM fields ORDER BY `order`"); while($row = mysql_fetch_array($result)) { echo ' <td> ' . $row["name"] . ' </td> '; } ?> <th style="width:128px">Options</th> </tr> </thead> This will display the field 1, 2, 3 etc.. My problem is.. How do i get the content displayed in the right order to the right fields.. :/ I hope you understand me, if not, please tell me so I can elaborate ^_^ I know this might seems like a noob question, and I'm sorry that I couldn't search, but I didn't know what to search for.
Hi there, wanted to see how I would have the columns I specified in $fields = array('id','type');
then be generated dynamically in the while loop and any other field I state in $fields = array('id','type');
then its added to the while loop in the below include('db.php'); class SelectData{ public function wpquery_select($conn,$sql,$fields){ $results = $conn->query($sql); if($results->num_rows > 0){ while($row = $results->fetch_assoc()){ // How would you process the array $fields which holds all the rows specified and dynamically create echo $row['id'], $row['id'] and so on? } } $conn->close(); } } $select = new SelectData(); $sql = "SELECT * FROM orders"; $fields = array('id','type'); $select->wpquery_select($conn,$sql,$fields); Thank you Hello All, Have another problem want to make the fields editable, i have tried in several ways but it's not helping if some one can help me out on this, i have tried contents editable = "true" but not helpful at all below is the code: Please advise what and where needs to be added to make the fields editable except date fields. <?php session_start(); error_reporting(0); include('includes/dbconnection.php'); if (strlen($_SESSION['cvmsaid']==0)) { header('location:logout.php'); } else{ if(isset($_POST['submit'])) { $eid=$_GET['editid']; $remark=$_POST['remark']; $fullname=$_POST['fullname']; $query=mysqli_query($con,"update tblsupvisitor set remark='$remark',fullname-'$fullname' where ID='$eid'"); if ($query) { $msg="Visitors Remark has been Updated."; } else { $msg="Something Went Wrong. Please try again"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags--> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content="au theme template"> <meta name="author" content="Hau Nguyen"> <meta name="keywords" content="au theme template"> <!-- Title Page--> <title>CVSM Visitors Forms</title> <!-- Fontfaces CSS--> <link href="css/font-face.css" rel="stylesheet" media="all"> <link href="vendor/font-awesome-5/css/fontawesome-all.min.css" rel="stylesheet" media="all"> <link href="vendor/font-awesome-4.7/css/font-awesome.min.css" rel="stylesheet" media="all"> <link href="vendor/mdi-font/css/material-design-iconic-font.min.css" rel="stylesheet" media="all"> <!-- Bootstrap CSS--> <link href="vendor/bootstrap-4.1/bootstrap.min.css" rel="stylesheet" media="all"> <!-- Vendor CSS--> <link href="vendor/animsition/animsition.min.css" rel="stylesheet" media="all"> <link href="vendor/bootstrap-progressbar/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet" media="all"> <link href="vendor/wow/animate.css" rel="stylesheet" media="all"> <link href="vendor/css-hamburgers/hamburgers.min.css" rel="stylesheet" media="all"> <link href="vendor/slick/slick.css" rel="stylesheet" media="all"> <link href="vendor/select2/select2.min.css" rel="stylesheet" media="all"> <link href="vendor/perfect-scrollbar/perfect-scrollbar.css" rel="stylesheet" media="all"> <!-- Main CSS--> <link href="css/theme.css" rel="stylesheet" media="all"> </head> <body class="animsition"> <div class="page-wrapper"> <!-- HEADER MOBILE--> <?php include_once('includes/sidebar-Supp.php');?> <!-- END HEADER MOBILE--> <!-- MENU SIDEBAR--> <!-- END MENU SIDEBAR--> <!-- PAGE CONTAINER--> <div class="page-container"> <!-- HEADER DESKTOP--> <?php include_once('includes/header-supp.php');?> <!-- HEADER DESKTOP--> <!-- MAIN CONTENT--> <div class="main-content"> <div class="section__content section__content--p30"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-header"> <strong>Visitor</strong> Details </div> <div class="card-body card-block"> <p style="font-size:16px; color:red" align="center"> <?php if($msg){ echo $msg; } ?> </p> <?php $eid=$_GET['editid']; $ret=mysqli_query($con,"select * from tblsupvisitor where ID='$eid'"); $cnt=1; while ($row=mysqli_fetch_array($ret)) { ?><table border="1" class="table table-bordered mg-b-0"> <tr> <th>Full Name</th> <td><?php echo $row['FullName'];?></td> </tr> <tr> <th>Qatar ID #</th> <td><?php echo $row['IDNO'];?></td> </tr> <tr> <th>Vehicle #</th> <td><?php echo $row['vno'];?></td> </tr> <tr> <th>No of Persons</th> <td><?php echo $row['noopaxs'];?></td> </tr> <tr> <th>Address</th> <td><?php echo $row['Address'];?></td> </tr> <tr> <th>Whom to Meet</th> <td><?php echo $row['WhomtoMeet'];?></td> </tr> <tr> <th>Deptartment</th> <td><?php echo $row['Deptartment'];?></td> </tr> <tr> <th>Reason to Meet</th> <td><?php echo $row['ReasontoMeet'];?></td> </tr> <tr> <th>Vistor Entring Time</th> <td><?php echo $row['EnterDate'];?></td> </tr> <?php if($row['remark']==""){ ?> <form method="post"> <tr> <th>Outing Remark :</th> <td> <textarea name="remark" placeholder="" rows="12" cols="14" class="form-control wd-450" required="true"></textarea></td> </tr> <tr align="center"> <td colspan="2"><button type="submit" name="submit" class="btn btn-primary btn-sm">Update</button></td> </tr> </form> <?php } else { ?> <tr> <th>Outing Remark </th> <td><?php echo $row['remark']; ?></td> </tr> <tr> <th>Out Time</th> <td><?php echo $row['outtime']; ?> </td> <?php } ?> </tr> </table> </div> </div> </div> </div> <?php include_once('includes/footer.php');?> </div> </div> </div> </div> <!-- Jquery JS--> <script src="vendor/jquery-3.2.1.min.js"></script> <!-- Bootstrap JS--> <script src="vendor/bootstrap-4.1/popper.min.js"></script> <script src="vendor/bootstrap-4.1/bootstrap.min.js"></script> <!-- Vendor JS --> <script src="vendor/slick/slick.min.js"> </script> <script src="vendor/wow/wow.min.js"></script> <script src="vendor/animsition/animsition.min.js"></script> <script src="vendor/bootstrap-progressbar/bootstrap-progressbar.min.js"> </script> <script src="vendor/counter-up/jquery.waypoints.min.js"></script> <script src="vendor/counter-up/jquery.counterup.min.js"> </script> <script src="vendor/circle-progress/circle-progress.min.js"></script> <script src="vendor/perfect-scrollbar/perfect-scrollbar.js"></script> <script src="vendor/chartjs/Chart.bundle.min.js"></script> <script src="vendor/select2/select2.min.js"> </script> <!-- Main JS--> <script src="js/main.js"></script> </body> </html> <!-- end document--> <?php } ?> <?php } ?>
Any help will be much appreciated.
Kind Regards, Naveed. Edited July 30, 2020 by Naveed786Hi and thank you in advance for helping me. Here is the code fragment: $sql="SELECT UserID,UserName FROM `UserValidation` WHERE UserID='".$_SESSION["UserID"]."'"; $rs=CustomQuery($sql); $RecData=db_fetch_array($rs); global $conn,$strUserValidation; $strSQLSave = "INSERT INTO RecruiterNames (UserID, UserName) values ("; $strSQLSave .= $RecData["UserID"].","; $strSQLSave .= chr(34).$RecData['UserName'].chr(34); $strSQLSave .= ")"; db_exec($strSQLSave,$conn); Here is the error I receive: php error happened Technical information Error type 256 Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"")' at line 1 URL www.dealwithaces.com/ACESDB/register.php? Error file /home/debra/public_html/dealwithaces.com/ACESDB/include/dbconnection.php Error line 36 SQL query INSERT INTO RecruiterNames (UserID, UserName) values (,"") More info Call stack File: line Function Arguments #0. include/dbconnection.php:36 db_query 1. INSERT INTO RecruiterNames (UserID, UserName) values (,""); 2. Resource id #10; #1. include/dbconnection.php:47 db_exec 1. INSERT INTO RecruiterNames (UserID, UserName) values (,""); 2. Resource id #10; #2. include/events.php:25 AfterSuccessfulRegistration 1. Array ( [UserName] => bsbnick [Password] => kaos55 [UserEmail] => mike@world-class-multimedia.com [GroupID] => 1 [UserActive] => 0 ) ; #3. register.php:298 Global scope N/A I need two fields from UserValidation table (UserID and UserName) to be inserted into table RecruiterNames (UserID and UserName), but ONLY when GroupID = 3 Thank you again for your help. Mike I have the following html code and php code. I would like clients to select which fields in the mysql database they would like to have appear in the resultant table by checking the text box next to the field in the html form. For instance they should be able to select first name and city and have only those columns appear in the resultant table. # <html> # <head> # <title>Search Clients Database</title> # </head> # # <body> # <h1>Clients Database Search Page</h1> # <form action="searchclients.php" method="post"> # <table width="100%" border="1" cellspacing="1" cellpadding="1"> # <tr> # <th width="37" scope="col"> </th> # <th width="114" scope="col">Fields</th> # <th width="169" scope="col">Filter Value</th> # <th width="1157" scope="col"> </th> # </tr> # <tr> # <td><input type="checkbox" name="idc" id="idc"></td> # <td>ID</td> # <td><input type="text" name="ID" id="ID"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="fnc" id="fnc"> # </label></td> # <td>First Name</td> # <td><input type="text" name="FirstName" id="FirstName"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="lnc" id="lnc"> # </label></td> # <td>Last Name</td> # <td><input type="text" name="LastName" id="LastName"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="cc" id="cc"> # </label></td> # <td>City</td> # <td><input type="text" name="City" id="City"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="pc" id="pc"> # </label></td> # <td>Province</td> # <td><select name="Province" id="Province"> # <option selected> </option> # <option>KZN</option> # <option>North West Province</option> # <option>Gauteng</option> # <option>Free State</option> # <option>Mpumalanga</option> # <option>Eastern Cape</option> # <option>Limpopo Province</option> # <option>Northern Cape</option> # <option>Western Cape</option> # </select></td> # <td> </td> # </tr> # </table> # <p> # <input type="submit" name="submit" value="Search" /> # </p> # </form> # # </body> # </html> # <?php # mysql_connect ("localhost", "username","password") or die (mysql_error()); # mysql_select_db ("clients"); # # $fn = $_POST['FirstName']; # $ln = $_POST['LastName']; # $city = $_POST['City']; # $prov = $_POST['Province']; # # $idc = $_POST['idc']; # $fnc = $_POST['fnc']; # $lnc = $_POST['lnc']; # $cc = $_POST['cc']; # $pc = $_POST['pc']; # # ?> # # <html> # <body> # # <table border=1> # <tr> # <th>ID</th> # <th>First Name</th> # <th>Last Name</th> # <th>City</th> # <th>Province</th> # </tr> # # <?php # $sql = mysql_query("select ID, FirstName, LastName, City, Province from clients where FirstName like '%$fn%' and LastName like '%$ln%' and City like '%$city%' and Province like '%$prov%'"); # # while ($row = mysql_fetch_array($sql)){ # # $id = $row['ID']; # $fname = $row['FirstName']; # $lname = $row['LastName']; # $city = $row['City']; # $prov = $row['Province']; # # ?> # # <tr> # <th><?php echo $id;?></th> # <th><?php echo $fname;?></th> # <th><?php echo $lname;?></th> # <th><?php echo $city;?></th> # <th><?php echo $prov;?></th> # </tr> # # <?php } //this ends the if?> # # </table> # </html> I'm trying to create a table form that pulls in "Extra" choices from a table and allows users to select a number of days and number of guests for each choice. I started creating it a a checkbox field but am thinking just using the name as a label and setting days and guests to default "0" might be a better bet. Guidance from someone more experienced with this? Also, how do I store the submission (db structure - in the "reservations" table, another?). I'm new to this and feel kind of lost with this challenge. //Extras $query = "select * from extras"; $data = mysqli_query($db, $query); $num = mysqli_num_rows($data); echo "<p><b>Extras:</b></p>"; for ($i=0; $i<$num; $i++) { $row = mysqli_fetch_array($data); $extra_id = $row['extra_id']; $extra_name = $row['extra_name']; $extra_rate = $row['extra_rate']; echo "<p><input type='checkbox' name='extra_id[]' value = '$extra_id' />$extra_name <i>\$$extra_rate</i> Num Days<input type='text' name='d$extra_id' /> Num Guests<input type='text' name='g$extra_id' />"; } I want to have a search product feature, but I would like members to be able to search multiple fields in one go i.e. product_code, Product_name in one MySQL query. The thing is, members have to be logged on, so the query must also only show results relating to that specific member, via the session[member_ID], my current query for listing products for that specific member is : Code: [Select] $sql = "SELECT productId, productCode, image, name, price, stock_level FROM product_inventory WHERE memberr_ID = '" . $_SESSION['SESS_mem_ID'] . "; How would I change the above into a search query to search for productcode, productname and still only show results beloging to this member using the session data ? all help appreciated hi, i'm new to php. i've got a problem. I've 3 tables and table has following content table 1 id name email address phone execution_date executor_name web_address table 2 id name email address phone execution_date executor_name project_title table 3 id name email address phone execution_date executor_name reviewer I want to export these table to and spreadsheet (.xls) with some criteria a form will assign which data will published at the spreadsheet with these criteria #all data can be exported from three tables #some column can be selected from three tables #some or all data can be selected from individual table i've implement a script for this but it didn't meet my requirements. Can anyone help? here is my script <?php $DB_Server = "localhost"; //your MySQL Server $DB_Username = "root"; //your MySQL User Name $DB_Password = "pass"; //your MySQL Password $DB_DBName = "mydb"; //your MySQL Database Name $search_from_date = $_POST['start_date']; $search_to_date = $_POST['end_date']; $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno()); $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno()); $now_date = date('m-d-Y H:i'); if(($_POST['typer_of_report'] == 'rrc_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName = 'rrc_record'; } if(($_POST['typer_of_report'] == 'erc_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName2 = 'erc_record'; } if(($_POST['typer_of_report'] == 'aeec_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName3 = 'aeec_record'; } $file_type = "vnd.ms-excel"; $file_ending = "xls"; //} header("Content-Type: application/$file_type"); header("Content-Disposition: attachment; filename=protocol_report.$file_ending"); header("Pragma: no-cache"); header("Expires: 0"); if($DB_TBLName) { $sql = "Select * from ".$DB_TBLName." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $Use_Title = 1; $title = "Report for $DB_TBLName on $now_date"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } //} echo "\n...\n"; } if($DB_TBLName2) { $sql = "Select * from ".$DB_TBLName2." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $Use_Title = 1; $title = "Report for $DB_TBLName2 on $now_date"; if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } echo "\n...\n"; } if($DB_TBLName3) { $sql = "Select * from ".$DB_TBLName3." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $Use_Title = 1; $title = "Report for $DB_TBLName3 on $now_date"; if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } } ?> have anyone any idea? hi, Instead giving its default on "Choose Process", I would like to display its process based on the value in database. How can I do it? Code: [Select] <?php require_once '../../connectDB.php'; require_once '../include/functions.php'; $sql = " SELECT * FROM tb_item ORDER BY itm_id asc"; $result = mysql_query($sql) or die(mysql_error()); ?> <form> <h1>Items</h1> <table width="75%" border="1" align="left" cellpadding="5" cellspacing="1"> <tr> <th width="100" align="left">Item ID</th> <th width="100" align="left">Parts</th> <th width="100" align="left">Sub-Process</th> <th width="100" align="left">Confirmation</th> </tr> <tr> <?php while ($row = mysql_fetch_array($result)) { extract($row); ?> <td><?php echo $itm_id; ?></td> <td><?php echo $itm_parts; ?></td> <td> <select name='cboSub' id='cbosub'> <option value='' selected>---- Choose Process ----</option> <?php createComboBox(); ?> </select> </td> <td> <a href='processItem.php?itm_id=<?php echo $itm_id; ?>'> <img src='../images/modify.png' width='20' height='20' alt='confirm'/> </a> </td> </tr> <?php }; ?> </table> </form> <?php /** * Create combo box for sub-process */ function createComboBox() { $sql = " SELECT * FROM tb_sub_process ORDER BY sub_id asc"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); echo "<option value='$sub_id' $select>$sub_name</option>"; } } ?> I've attached an example of what basically the output will looks like. Any help are appreciated. Thanks in advance. Regards, Juz [attachment deleted by admin] I'm wondering how to do this with javascript for a table that i have made in php and html. I want to hide the row for the table based on the value inside my first column for each row of the table. Like if column 1 has "apple" inside it, then the row would not be shown. I'm pretty sure this can be done in javascript but i'm not a coding guy, so any help would be appreciated! My table.php file that has the table i want to do this for: Code: [Select] <script language="javascript"> imageX1='plus'; imageX2='plus'; imageX3='plus'; function toggleDisplay(e){ imgX="imagePM"+e; tableX="table"+e; imageX="imageX"+e; tableLink="tableHref"+e; imageXval=eval("imageX"+e); element = document.getElementById(tableX).style; if (element.display=='none') {element.display='block';} else {element.display='none';} if (imageXval=='plus') {document.getElementById(imgX).src='http://www.pvpstreams.com/icons/wowicon.png';eval("imageX"+e+"='minus';");document.getElementById(tableLink).title='Hide WoW';} else {document.getElementById(imgX).src='http://www.pvpstreams.com/icons/wowicon.png';eval("imageX"+e+"='plus';");document.getElementById(tableLink).title='Show WoW';} } </script> <?php $username="user"; $password="password"; $tmp="database"; mysql_connect(localhost,$username,$password); @mysql_select_db($tmp) or die( "Unable to select database"); $query="SELECT * FROM users"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table class="sortable" id="wow" border="1" cellpadding="0" cellspacing="0" style="margin-left:auto;margin-right:auto;text-align:left"> <tr> <th><font face="Arial, Helvetica, sans-serif">Game</font></th> <th><font face="Arial, Helvetica, sans-serif">Character</font></th> <th><font face="Arial, Helvetica, sans-serif">Rating</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/xfirelogo.png"> Status</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/xfirelogo.png"> Link</font></th> <th><font face="Arial, Helvetica, sans-serif">Realm</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/livestreamlogo.png"> Status</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/livestreamlogo.png"> Link</font></th> <th><font face="Arial, Helvetica, sans-serif">Team Setup</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"wowcharacter"); $f2=mysql_result($result,$i,"username"); $f3=mysql_result($result,$i,"livestream"); $f4=mysql_result($result,$i,"wowserver"); $f5=mysql_result($result,$i,"wowplayer1"); $f6=mysql_result($result,$i,"wowplayer2"); $f9=mysql_result($result,$i,"wowplayer3"); $f7=mysql_result($result,$i,"wowrealm"); $f8=mysql_result($result,$i,"xfire"); $f10=mysql_result($result,$i,"xfirecheck"); $f11=mysql_result($result,$i,"wowrating"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<center><img src=http://www.pvpstreams.com/table-images/wowtable.png>"; ?></center></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://$f4.battle.net/wow/en/character/$f7/$f1/simple>$f1</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f11; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "$f10"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://www.pvpstreams.com/xfire.php?user=$f2>$f8</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f7; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php include("livestreamcheck.php"); ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://www.pvpstreams.com/livestream.php?user=$f2>$f3</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<img src=http://www.pvpstreams.com/wclassicons/$f5.png><img src=http://www.pvpstreams.com/wclassicons/$f6.png><img src=http://www.pvpstreams.com/wclassicons/$f9.png>" ?></font></td> </tr> <?php $i++; } ?> </table> |