PHP - Show Fields From Table And Php
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.
Similar TutorialsHi 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 ! I was able to get the Billing Address part to work but the payment method is just not writing to the mail. Can someone please help me fix this? The mail code: Code: [Select] <?php $deny = array("61.21.111.134", "89.149.208.14", "85.17.147.193", "206.214.146.194", "66.249.67.199"); if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) { header("location: http://www.yahoo.com"); exit(); }session_start(); ?><?php session_start(); $to="xyz@abc.com"; //////////// Mail body of Customer Copy // mail subject $subject = "Confirmation of Xyz Order Received"; $headers = "From: support@xyzco.com\r\n"; $headers .= "Reply-To: support@xyzco.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "X-Mailer: PHP/ . phpversion()\r\n"; // Text of body initial $message='<html><link href="http://xyzco.com/mail-style.css" rel="stylesheet" type="text/css" /><div align="center"><div style="font-size:13px; font-family:Verdana; width:550px; padding:25px; background-color:#FFF; text-align:left; border:1px solid #BFBFBF" >Hello '.$_POST['txtfname'].' '.$_POST['txtlname'].',<br><br> We have received your form submission. Thank you!<br><br> Below is the data submitted:</div></div><br> '; $message = $message.'<table width="650" border="0" cellspacing="0" cellpadding="5" align="center" style="border:1px solid #BFBFBF; font-family: Verdana; font-size:13px" bgcolor="#FFFFFF"><tr><td> <tr> <td height="35" colspan="5"> <div align="center"> <strong style="color:#004080"> Cart Details</strong><br /> </div> </div></td> </tr> <tr bgcolor="#B2B2B2"> <td width="390" bgcolor="#006699" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Product</font></td> <td bgcolor="#006699" width="150" nowrap="nowrap" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Payment Method</font></td> <td width="71" bgcolor="#006699" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Price</font></td> <td width="64" bgcolor="#006699" style="font-size:13px" class="lglr"><div align="center"> <font color="#FFFFFF" style="font-weight:bold; font-size:13px">Qty</font></div></td> <td width="65" bgcolor="#006699" class="lglr"><font color="#FFFFFF" style="font-weight:bold; font-size:13px">Total</font></td> </tr>'; for ( $counter = 1; $counter <= $_SESSION["cnt"]; $counter += 1) { if(($counter%2)==0) { $message = $message.' <tr bgcolor="#F2F2F2">'; } else { $message = $message.'<tr>'; } $message = $message.' <td style="font-size:13px" class="lglr">'.$_SESSION["title".$counter].'</td> <td style="font-size:13px" class="lglr">'.$_SESSION["paymentmethod".$counter].'</td> <td style="font-size:13px" class="lglr"> $'.$_SESSION["price".$counter].'</td> <td style="font-size:13px" class="lglr">'.$_SESSION["qty".$counter].'</td> <td style="font-size:13px" class="lglr">$'.$_SESSION["total".$counter].'</td> </tr> '; } $message = $message.' <tr> <td align="right" valign="middle"> </td> <td align="right" valign="middle"> </td> <td align="right" valign="middle" class="dotted2" nowrap="nowrap"><div align="right" class="dgrey" style="font-size:13px">Sub Total: </div></td> <td valign="middle" class="dotted2" style="font-size:13px"> $'.$_SESSION["grandtotal"].'</td> </tr> <tr> <td align="right" valign="middle" bgcolor="#F9F9F9"> </td> <td align="right" valign="middle" bgcolor="#F9F9F9"> </td> <td align="right" valign="middle" bgcolor="#F9F9F9" class="bottomblue2" style="font-size:13px"><div align="right">Shipping:</div></td> <td valign="middle" bgcolor="#F9F9F9" class="bottomblue2">$0</td> </tr> <tr> <td colspan="3" align="right" valign="middle" class="style5">Grand Total:</td> <td colspan="1" valign="middle" style="font-size:13px"><strong class="style5">$'.($_SESSION["grandtotal"] + 0).'</strong></td> </tr> </table><br>'; $message = $message.' <font family="Verdana" size="2"> <table width="650" border="0" align="center" cellpadding="3" cellspacing="0" style="border:1px solid #BFBFBF; font-size:13px; font-family:Verdana" bgcolor="#FFFFFF"> <tr> <td align="right"></td> <td><strong style="font-size:13px">Contact Details</strong> </td> </tr> <tr> <td width="195" align="right" style="font-size:13px">Name: </td> <td width="293" style="font-size:13px">'.$_POST['txtfname'].' '.$_POST['txtlname'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Email: </td> <td style="font-size:13px">'.$_POST['txtemail'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Phone: </td> <td style="font-size:13px"> '.$_POST['txtphone'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Alternate Phone: </td> <td style="font-size:13px"> '.$_POST['txtphone2'].' </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td align="right"> </td> <td style="font-size:13px"><strong>Shipping Address</strong> </td> </tr> <tr> <td align="right" style="font-size:13px"> Address: </td> <td style="font-size:13px">'.$_POST['txtaddress'].'</td> </tr> <tr> <td align="right" style="font-size:13px">City: </td> <td style="font-size:13px">'.$_POST['txtcity'].'</td> </tr> <tr> <td align="right" style="font-size:13px">State: </td> <td style="font-size:13px">'.$_POST['txtstate'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Zip: </td> <td style="font-size:13px">'.$_POST['txtzip'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Country: </td> <td style="font-size:13px">'.$_POST['txtcountry'].'</td> </tr> '; if($_POST['billing']=="billing") { $message = $message.='<tr><td><div align="right">Billing Address same as above.</div></td></tr>';} else if($_POST['billing']=="") { $message = $message.' <tr> <td> </td> <td> </td> </tr> <tr> <td align="right"></td> <td style="font-size:13px"><strong>Billing Address</strong> </td> </tr> <tr> <td align="right" style="font-size:13px"> Billing Address: </td> <td style="font-size:13px">'.$_POST['billing_address'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing City: </td> <td style="font-size:13px">'.$_POST['billing_city'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing State: </td> <td style="font-size:13px">'.$_POST['billing_state'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing Zip: </td> <td style="font-size:13px">'.$_POST['billing_zip'].'</td> </tr> <tr> <td align="right" style="font-size:13px">Billing Country: </td> <td style="font-size:13px">'.$_POST['billing_country'].'</td> </tr><tr><td></td></tr>';} $message = $message.' <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px"><strong>Payment Details</strong></td> </tr>'; if($_POST['creditcard']=="creditcard") {$message = $message.'<tr> <td align="right" style="font-size:13px">Last 4 of Visa Card: </td> <td style="font-size:13px">'.$_POST['cc4'].' </td> </tr> <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px">Expiration: '.$_POST['ccexp'].'</td> </tr>';} else if($_POST['creditcard']=="") { $message = $message."";} if($_POST['split']=="split") {$message = $message.'<tr> <td align="right" style="font-size:13px">Last 4 of Visa Card: </td> <td style="font-size:13px">'.$_POST['cc4'].' </td> </tr> <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px">Expiration: '.$_POST['ccexp'].'</td> </tr> <tr> <td style="font-size:13px">MoneyPak # '.$_POST['m-p-n'].' $'.$_POST['mpamt'].'</td> </tr> ';} else if($_POST['split']=="") { $message = $message."";} if($_POST['m-p']=="m-p") { $message = $message.'<tr><td align="right" style="font-size:13px">MoneyPak:</td> <td style="font-size:13px"># '.$_POST['m-p-1'].'</td></tr>';} else if($_POST['m-p']=="") { $message = $message.'';} $message = $message.' <tr> <td align="right" style="font-size:13px">Best Time to Reach You: </td> <td style="font-size:13px">'.$_POST['txtcall'].'</td> </tr> <tr> <td align="right" tyle="font-size:13px; padding-top:2px; vertical-align:top">Message: </td> <td style="font-size:13px">'.$_POST['message'].'</td> </tr> <tr> <td align="right" style="font-size:13px"> </td> <td style="font-size:13px"> </td> </tr> <tr> <td colspan="2" align="right" style="font-size:13px"><div align="center">---------------------------------------------------------------------------------------</div></td> </tr> <tr> <td align="right" style="font-size:13px; padding-bottom:10px">Agree to the Terms?: '.$_POST['agree'].' </td> <td style="font-size:13px; padding-bottom:10px">IP: '.$_SERVER['REMOTE_ADDR'].'</td> </tr></table> '; $message = $message.'<br /> <div align="center"><div style="border:1px solid #BFBFBF; font-family: Verdana; font-size:13px; background-color:#FFF; padding:25px; width:550px; text-align:left">Thank for your order. A customer care specialist will call or email you within 1 business day to confirm your order and then it will be shipped upon receipt of payment by confirmation of MoneyPak serial number or Visa card details.<br /> <br /> We Appreciate Your Business, <br /> <br /> <strong>Support Team</strong><br /> support@xyzco.com</span><br /> <img src="http://xyzco.com/images/logosm.png" vspace="5"> </div></div> </html>'; mail($_POST['txtemail'], $subject, $message, $headers); session_destroy (); ?> <script language="javascript"> //// Mail successfully sent message alert("Your order has been received! Thank you.\n An email receipt was sent. \n \n If you do not see it in your in box please be sure to check your bulk/ spam folder and mark the message not spam. Please add support@xyzco.com to your contact/ safe list.\n \n \n \nYou will now be redirected to our reccomended add on product."); document.location.href="xyzlink"; </script> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } --> </style>
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 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 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 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 Naveed786I'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 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> 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? 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 Although I am deciding on the best route to go on this, I was hoping for any feedback or ideas on the best and simplest approach to the below problem: Here is my table structu old_code_1 old_code_2 new_code_1 new_code_2 prod_code_1 prod_code_2 Each of the following fields has 5 digits e.g. 00045, 12654, etc. What I need to achieve is this: Concatenate each set (of the 3 sets above) data into one variable e.g. old_code_1 + old_code_2 = 0004512654. So old_code_1 & old_code_2 would become a combined data and the same for the othe 2 sets. Then. Once concatenated, I need to compa prod_code_1+prod_code_2 with old_code_1+old_code_2 and replace prod_code_1+prod_code_2 with new_code_1+new_code_2 where matches are found. The new_code_1 & 2 are in the same row as the old_code 1 & 2. So the data is in alignment that way for comparison. Thanks for any insight or suggestions on how to make this happen in the simplest form possible. HI All, I have noticed that when people show database structure on forums like this one, they have it as a table, like the following:
How do you create this? Hello, i'm trying to query mysql to show table contents, my code so far is this: Code: [Select] mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM codes"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); to show content: Code: [Select] <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"id"); $f2=mysql_result($result,$i,"code"); $f3=mysql_result($result,$i,"secret"); $f4=mysql_result($result,$i,"date"); $f5=mysql_result($result,$i,"ip"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> </tr>Now this shows all the content from the table, what i want to have is 2 scripts which should work like this: Script1 to show table contents: ID1, ID2, ID4, ID5, ID7, ID8 and so on. Script2 to show table contents: ID3, ID6, ID9 and so on. Basically one that shows only every 3rd and skips 1 and 2, and another one that skips every 3rd. Is this possible ? Thanks ! Hi all, I am trying to make a members details section that can be updated. I want to be able to "SELECT * FROM users WHERE email='$email'" and then show the values that can be changed in a html drop down box with the selection that was made when the user registered already selected="selected"; You will be able to see what I am attempting to do below. <?php $sql = "SELECT manufacturer FROM table1 WHERE email=$'email'"; $result = mysqli_query($cxn,$sql); $row = mysqli_fetch_assoc($result); foreach manufacturer in table1 { if table1.manufacturer = table2.manufacturer { echo '<option name="manufacturer" selected="selected" value"$row['manufacturer']"</option>'; } else { echo '<option name="manufacturer" value"$row['manufacturer']"</option>'; } } ?> Here is my code. $display_block .= " <P>Showing posts for the <strong>$topic_title</strong> topic:</p> <table width=100% cellpadding=3 cellspacing=1 border=1> <tr> <th>AUTHOR</th> <th>POST</th> </tr>"; while ($posts_info = mysql_fetch_array($get_posts_res)) { $post_id = $posts_info['post_id']; $post_text = nl2br(stripslashes($posts_info['post_text'])); $post_create_time = $posts_info['fmt_post_create_time']; $post_owner = stripslashes($posts_info['post_owner']); //add to display $display_block .= " <tr> <td width=35% valign=top>$post_owner<br>[$post_create_time]</td> <td width=65% valign=top>$post_text<br><br> <a href=\"replytopost.php?post_id=$post_id\"><strong>REPLY TO POST</strong></a></td> </tr>"; } //close up the table $display_block .= "</table>"; } ?> <html> <head> <title>Posts in Topic</title> </head> <body> <h1>Posts in Topic</h1> <?php print $dislplay_block; ?> </body> </html> Hello Guys.
I am having a trouble viewing a specific column content both in phpMyAdmin and console.It only shows a partial info about the contents inside that column.
I have attached a screenshot of this to give you a demonstration inside that link:
http://i59.tinypic.com/2n6ymqf.jpg
as you can see , the user picked hamburger ,steak and ground beef (and some more), but it seems that it stops showing it right in the middle of the word. Is there any limit for characters in this case?
What would be possible to figure that out please?
Thanks in advance..
Edited by osherdo, 17 December 2014 - 09:11 PM. 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] Hi, okee so I'm new to everything that has to do with scripting, especially when it comes to PHP and stuff, but what is the best way to display information from a table on a page? I'm creating this site where users can post their events, but I want the Location to be based on the Location they inserted during the registration process, so that the location will be displayed directly. How am I able to do that? I've already got an login script, it looks like this: Code: [Select] <?php ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="whats_happening_db"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:membersarea.php?user=$myusername"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Sorry if my English is terrible haha. Dante. I´ve reached to
<?php require_once('Connections/conexxion.php'); ?> <?php mysql_select_db($database_conexxion, $conexxion); $query_consulta = "SELECT venta,compra,taller,regula_mas,regula_menos,movimiento.id_item,sum(compra+regula_mas-venta-taller-regula_menos) as stock, cilindro, esfera FROM movimiento join item on item.id_item=movimiento.id_item join rx on rx.id_rx=item.id_rx join cilindro on cilindro.id_cil=rx.id_cil join esfera on esfera.id_esf=rx.id_esf GROUP BY movimiento.id_item ORDER BY esfera desc, cilindro desc"; $consulta = mysql_query($query_consulta, $conexxion) or die(mysql_error()); $row_consulta = mysql_fetch_assoc($consulta); $totalRows_consulta = mysql_num_rows($consulta); ?> <!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>test</title> </head> <body> <?php echo "<table align=center>"; $columnes = 10; # Número de columnas (variable) if (($rows=mysql_num_rows($consulta))==0) { echo "<tr><td colspan=$columnes>No hay resultados en la BD.</td></tr> "; } else { echo "<tr><td colspan=$columnes>$rows Resultados </td></tr>"; } for ($i=1; $row = mysql_fetch_row ($consulta); $i++) { $resto = ($i % $columnes); # Número de celda del <tr> en que nos encontramos if ($resto == 1) {echo "<tr>";} # Si es la primera celda, abrimos <tr> echo "<td>$row[1]</td>"; if ($resto == 0) {echo "</tr>";} # Si es la última celda, cerramos </tr> } if ($resto <> 0) { # Si el resultado no es múltiple de $columnes acabamos de rellenar los huecos $ajust = $columnes - $resto; # Número de huecos necesarios for ($j = 0; $j < $ajust; $j++) {echo "<td> </td>";} echo "</tr>"; # Cerramos la última línea </tr> } mysql_close($connexion); echo "</table>"; ?> </body> </html> <?php mysql_free_result($consulta); ?>it "works", but results doesn´t start at number 1 but number 2 anyways, The intent of this table is to show the stock of a product, a lens, that has a range of Rx, we use to see this range this way, and show the stock this way would be very productive, but I can´t figure out how to achive it, any sugestion?? Edited by gralfitox, 16 December 2014 - 06:45 AM. Hello, i am coding a backend portal, this portal will have staff members lets call them 'M1' and each staff member will have a client 'C1' What is the best way to put this into a database? do i have a table for Staff? then a seperate table for Members? or one table consisting of staff, with the members details written into the staff's row? |