PHP - Transferring Data From One Table To Another Table
hello friends
I'm dealing with this problem for two days. I put here the screenshot for easier understanding.Sorry about my bad english. Here is the ss http://i61.tinypic.com/2rz5q55.jpg I don't want to inner join or table join. All image links which same sku should displayed in single row where products.resimler colon I can join the tables but i want to one table.Because i can import single csv file for e-commerce script.How can I use a update query for list multiple images in table products. Edited by nogai, 10 October 2014 - 07:01 AM. Similar TutorialsHey there, I was wondering if this is possible with mysql, my goal is to transfer the users id from the users table to the id field in my status table, thanks in advance. NOTE: Not manually, through a script. hi, I have a webpage that is driven by a database mostly. it has a catalog of dog treats and most will transfer to the checkout page but 2 two won't. I have checked the database and everything looks fine if it would help, here 's the webpage. http://auntievics.com/treats.php. it's the Cara The Flirt's K9 Canoli Stuffed and the Cara The Flirt's K9 Canoli Unstuffed that won't transfer. Any help would be appreciated. the second database found on the cloud
i try to get JSON data but how to insert and update them to another online database with the same table my php script to return json data <?php include_once('db.php'); $users = array(); $users_data = $db -> prepare('SELECT id, username FROM users'); $users_data -> execute(); while($fetched = $users_data->fetch()) { $users[$fetchedt['id']] = array ( 'id' => $fetched['id'], 'username' => $fetched['name'] ); } echo json_encode($leaders);
i get
{"1":{"id":1,"username":"jeremia"},"2":{"id":2,"username":"Ernest"}} Edited March 24 by mahenda Sorry, I initially posted this in the Ajax Help Thread, but thinking about it, I suspect this is a php query.
I am trying to write a basic Private Messaging script.
I have my main page which lists all messages that have been received. I then want to click on an href link to run an ajax query to bring information in from another .php file which shows the content of the selected message.
But I can't fathom out how to do this with an href. First off, is it possible? If so, can anyone tell me what I am doing wrong?
The relevant script is:
privatemessage.php:
<?php $query2 = DB::getInstance()->query("SELECT c.id as cid, c.title, c.time, m.id as membersid, m.username, m.member_first_name, m.member_last_name FROM conversation as c, members as m WHERE ((c.member1='{$memberid}' and c.read1='Yes' and c.removed1='No' and m.id=c.member2) OR (c.member2='{$memberid}' and c.read2='Yes' and c.removed2='No' and m.id=c.member1)) GROUP BY m.id ORDER BY m.id DESC"); ?> <table> <tr> <td align="left"> <?php echo htmlentities($result2->member_first_name); ?> <?php echo htmlentities($result2->member_last_name); ?> <?php echo "("; echo htmlentities($result2->username); echo ")"; ?> </td> <td align="right"> <?php echo timeAgo(strtotime($result2->time)); ?> </td> </tr> <tr> <td colspan="2" align="left"> <form action="" method="post"> <?php echo "Subject: "; ?> <?php echo "<input type='hidden' name='id' id='id' value='{$result2->cid}'>"; ?> <a href="#$result2->cid" onClick="showMessages(this.value)"><?php echo htmlentities($result2->title); ?> </form> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="js/readmessage.js"></script> </td> </tr> </table> <div id="txtMessage"></div>My readmessage.js code is: function showMessages(str) { if (str=="") { document.getElementById("txtMessage").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtMessage").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","readmessage.php?q="+str,true); xmlhttp.send(); }And my readmessage.php code is: ?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $req1 = DB::getInstance()->query("SELECT title, member1, member2 FROM conversation WHERE id='{$q}' AND id2='1'"); foreach ($req1->results() as $dn1) if($req1->count()==1) { if(($dn1->member1=='{$memberid}') or ($dn->member2=='{$memberid}')) { if($dn1->member1=='{$memberid}') { DB::getInstance()->query("UPDATE conversation SET read1='Yes' where id='{$q}' and id2='1'"); $user_partic = 2; } else { DB::getInstance()->query("UPDATE conversation SET read2='Yes' where id='{$q}' and id2='1'"); $user_partic = "1"; } $req2 = DB::getInstance()->query("SELECT conversation.time, conversation.message, members.id as userid, members.username, members.member_first_name, members.member_last_name FROM conversation, members WHERE conversation.id='{$id}' AND members.id=conversation.member1 ORDER BY conversation.id2"); if(isset($_POST['message']) and $_POST['message']!='') { $message = $_POST['message']; if(get_magic_quotes_gpc()) { $message = stripslashes($message); } $message = $string(nl2br(htmlentities($message, ENT_QUOTES, 'UTF-8'))); if( DB::getInstance()->query("INSERT into conversation (id, id2, title, member1, member2, message, time, read1, read2) VALUES('{$q}', '{(intval($req2->id2)+1)}', '', '{$memberid}', '', '{$message}', '.time().', '', '')") and DB::getInstance()->query("UPDATE conversation SET read'{$user_partic}'='Yes' WHERE id='{$q}' AND id2='1'")); } echo "<h4>"; echo $dn1->title; echo "</h4><br><br>"; echo "<table><col width='150px'><col width='50px'><col width='150px'>"; echo "<tr><th>Member</th><th> </th><th>Message</th></tr>"; foreach ($req2->results() as $dn2) { echo "<tr><td>"; echo $dn2->members.member_first_name; echo $dn2->members.member_last_name; echo " ("; echo $dn2->members.username; echo ") </td><td></td><td>"; echo timeAgo(strtotime($dn2->time)); echo "<br>"; echo $dn2->message; echo "</td></tr>"; } echo "</table>"; } } } ?>However, just to try and find where the error lies, I have tried the following code for my readmessage.php file: <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = intval($_GET['q']); echo $q; } ?>Which always returns a "0" reply - which says to me that my files are talking, but that the id isn't being carried across. Anybody got any suggestions? Many thanks for any help offered. I have the following code Code: [Select] while($player = mysql_fetch_array($players)) { #Lets loop through all the players echo "<BR><input type=submit onclick=this.form.action='points.php?points=".$_GET['points']."&player=".$player['playerID']."&playerName=".$player['name']."' value='".$player['name']."'>"; }but the problem is that $player['name'] is always two words and it doesn't work. So I have removed '&playerName=".$player['name']."' but now don't know how to transfer that info. Is there a way of having the player name in the header or another way of sending this data to the next page? Another way of doing it is to check for the players name via there playerID number but this involves another call to the database which I am trying to avoid. I have a page that reads from a database to list employees from different states. Under each name is a link that pulls up a new window with a contact form. My goal is to get the name from that link to appear on that new window. (Which I will then use to ultimately add the name into the email that was generated so the recipient can know who the email was intended for.) I've tried using the GET and POST methods but nothing seems to work. Any help would be appreciated greatly. I will name my firstborn after anything you desire. I've included my code below. (The last line is what I've been primarily working with) Code: [Select] //Open Database Connection $db = open_db_connection(); $sql = "SELECT DISTINCT 1 from users where active = 'Y' and show_on_contactus = 'Y'"; $results = mysql_query($sql, $db); $emaillink = "<a target='main' onclick=window.open('contactform/contactCentral.php?name=$state_row[state]','popup','width=380,height=400,scrollbars=no,resizable=no,toolbar=yes,directories=no,location=no,menubar=yes,status=no,left=0,top=0'); return false>"; if(!mysql_num_rows($results) == FALSE) while($row = mysql_fetch_array($results, MYSQL_BOTH)) { echo "<ul id=\"directors\">\n"; $state_sql = "SELECT * from users where active = 'Y' and show_on_contactus = 'Y' and state_full = 'indiana' order by last_name"; $state_results = mysql_query($state_sql, $db); if(!mysql_num_rows($results) == FALSE) { while($state_row = mysql_fetch_array($state_results, MYSQL_BOTH)) { echo "<li>\n"; echo " <div class=\"fl dirimg\">\n"; if($state_row[photo] == "") { echo "<img border=\"0\" width=\"61\" height=\"85\" src=\"images/exe_placeholder.jpg\" alt=\"$state_row[first_name] $state_row[last_name]\" />\n"; } else { echo "<img border=\"0\" width=\"61\" height=\"85\" src=\"n2team/pictures/$state_row[photo]\" alt=\"$state_row[firstname] $state_row[last_name]\" />\n"; } echo " </div>\n"; echo " <span class=\"fr\">$state_row[first_name] $state_row[last_name]<br />\n"; echo " $state_row[title]<br />\n"; echo " $state_row[city], $state_row[state]<br />\n"; echo " $emaillink Contact $state_row[first_name] </a></span></li>\n"; } Hi, I am a curious fellow just beginning to use PHP. I understand the basics of what the $_GET and $_POST superglobals do, and how we can use them to retrieve data after form submission. I also know that since $_GET and $_POST are just associate arrays, we can create our own values in both $_GET and $_POST by writing statements like $_POST['variable'] = "value". I am wondering if it is at all possible to send data beyond form data by adding new key/value pairs into $_GET and $_POST. So for example, if I had a form that transferred username/password through Post, would it be possible for me to include further data by just saying $_POST['formtype'] = "house_insurance_form"? Basically what I'm getting at is trying to physically add your own data to $_POST or $_GET that you could pull from the next page where the form redirects to. In other words, can I send data beyond form data using these superglobals? I know I can do this with $_SESSION, but could I do it through $_POST or $_GET? I haven't been able to accomplish this, and I was just wondering if someone could give me an in-depth explanation of how this might work or how this is not possible. I would really really really appreciate it. Best Regards, -Sky Hi guys,
I am having a problem transferring data between pages, using PHP sessions. I have a HTML SELECT drop-down to let user set the number of posts per page to display. <form method="POST" style="margin:auto;position:relative;width:35%;padding:17px;top:47px;"> <span>select posts-per-page:</span> <select name="ppp"> <option selected disabled>--select ppp--</option> <option value=10>10</option> <option value=15>15</option> <option value=20>20</option> <option value=50>50</option> <option value=100>100</option> </select> <input type="submit" name="submit" value="OK"/> </form> I want to transfer the value selected by user to a session so that I can load the value in other pages. The value of posts per page is carried by variable $ppp; so, file1 contains the code $_SESSION['ppp'] = $ppp; That seems to work great; the system updates correctly the session's value as user submits different numbers of posts-per-page.
The problem is in page2.php: it doesn't update to the new user's selection; I already have a session active in that page so I don't need session_start(). To call the session, I use the line $ppp=$_SESSION['ppp']; When user changes the selection from 50 to 100 posts per age, for example, the value of page1.php changes as expected, but the value transferred to page2.php doesn't change, appears to remain with the default value the page loads with. I don't know if the problem is that I already have a session going. Can you have more than one session running simultaneously in a page? Can anybody help? Thanks in advance!
Sept Hi all I am describing my problem below can any body please look into this I have two databases DB1:datain1 DB2:datain2 having the below structure database, table, fields datain1 , student , id,name datain2 , student , id,name the two databases having same structure My query is i want copy all data from datain1 to datain2 on daily process through php script(script will be executed manually on daily) i don't want any duplicate or repeated data in datain2 give me some script to do this kindly help me to solve this its so urgent Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? Hey everyone. I am creating a website so my family can select from the list of present my daugther has asked for. I have them logging in, and that works. I have the table data set and the search and table display works. But I would like to display the list (as in the code below) but with a checkbox in the first column (add a column). From that the authenticated user can click on the item they have purchased and that selection will be moved to another table (called purchased). I have that code. The only thing I cannot figure out is to present the data in list form with a checkbox (like you would see on an order form). Here is the display code (there is no error checking at this point): <head><LINK REL="SHORTCUT ICON" HREF="cmwschl.ico"></head> <body bgcolor="#C0C0C0"> <font face="Arial" color="#000080">Books from the Selected Series</font> </h1> <hr font color="Navy" font size="3"> <center> <table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000"> <tr> <td width="170" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Number</center></font></b></center></td> <td width="140" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Group</center></font></b></center></td> <td width="100" bgcolor="#FFCC66"><center><b><font color="navy" size="2" face="Trebuchet MS"><b><center>Book Title</center></font></b></center></td> </tr> <?php $con = mysql_connect("localhost","twilson","R00tb33r!") or die('Connection: ' . mysql_error());; mysql_select_db("CMWWeb", $con) or die('Database: ' . mysql_error()); ?> <? $group = $_POST['bookgrp']; //if ($Prod <> 0) { $sql = "SELECT * FROM `OpenBooks` WHERE `bookgrp`= '$group'"; $results = mysql_query($sql); if ($results) { //this will check if the query failed or not if (mysql_num_rows($results) > 0) { //this will check if results were returned while($copy = mysql_fetch_array($results)) { $variable1=$copy['booknum']; $variable2=$copy['bookgrp']; $variable3=$copy['booktitle']; //table layout for results print ("<tr>"); print ("<td><center>$variable1</center></td>"); print ("<td><center>$variable2</center></td>"); print ("<td><left>$variable3</left></td>"); print ("</tr>"); } } else { echo "No results returned"; } } else { echo "Query error: ".mysql_error(); } mysql_close($con); ?> </table> </center> Hi,
A little new to php programming... I have a question:
I have written this code:
<html> <head> <title>Test</title> </head> <FONT FACE="Verdana, sans-serif"> <H3>Movies</h3> <?php include 'config.php'; include 'opendb.php'; $result = mysql_query("SELECT * FROM DayMovie ORDER BY FileDate") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Filename</th><th>Path</th><th>Date</th><th>Filetype</th> <th>Size</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['FileName']; echo "</td><td>"; echo $row['FilePath']; echo "</td><td>"; echo $row['FileDate']; echo "</td><td>"; echo $row['FileType']; echo "</td><td>"; echo $row['FileSize']; echo "</td></tr>"; } echo "</table>"; include 'closedb.php'; ?>I would like to have a link to these files on all the rows to open the files. How can I do that? I would also like that the link from the mysql row is not shown in the table. Only a text with the text "link" or "view". What I'm wanting to do is instead of March-July have it always display the last 5 months and for the Visits th have it display the number of hits to my main page for each month and display the number of logins for each month to my CMS script. Can someone point me in the right direction? Code: [Select] <?php function get_visit_data_table() { echo "<table class=\"visualize_dashboard\">"; echo "<caption>Dashboard Chart Example</caption>"; echo "<thead>"; echo "<tr>"; echo "<td></td>"; echo "<th scope=\"col\">March</th>"; echo "<th scope=\"col\">April</th>"; echo "<th scope=\"col\">May</th>"; echo "<th scope=\"col\">June</th>"; echo "<th scope=\"col\">July</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; echo "<tr>"; echo "<th scope=\"row\">Visits</th>"; echo "<td>175</td>"; echo "<td>145</td>"; echo "<td>212</td>"; echo "<td>175</td>"; echo "<td>182</td>"; echo "</tr>"; echo "<tr>"; echo "<th scope=\"row\">Logins</th>"; echo "<td>94</td>"; echo "<td>53</td>"; echo "<td>124</td>"; echo "<td>92</td>"; echo "<td>105</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; } ?> First I need to create a table or add to an existing table - the table needs to contain a date -msg last sent date Then run the following email script for each record if the value of the msg last sent date is greater than >30 days??? after the script is run, it updates the records it emailed to todays date... <?php include "vsadmin/db_conn_open.php"; $allprods=mysql_query("select pID, pName, pPrice, pDropship, dsID, dsName, dsEmail from products, dropshipper where pDropship = dsID"); while ($yarr=mysql_fetch_assoc($allprods)){ $aname=$yarr["pID"]; $bname=$yarr["pName"]; $cname=$yarr["dsName"]; $dname=$yarr["dsEmail"]; $ename=$yarr["pPrice"]; $to = $dname; $subject = ("Your Ebook: " . $bname); $body = ("Hello " . $cname .",\n\nYou have the following ebook listed for sale on www.insertwebsite.com (". $bname ."). \nYour Ebook (product) is currently listed at the retail price of $" . $ename . "\n\nThe following link is provided to you as a marketing tool for your current or future email campaigns. This link is a direct link to your ebook on the Enlightened Ebooks site. \n www.www.insertwebsite.com/proddetail.php?prod=". $aname . "\n\nOnline sales is a safe secure way to increase your ebook sales. Simply provide the link in all your correspondences and you sales will increase. You are your own best promoter."); $headers = "From: neil@me.com\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { echo("<p><b>Message sent to.</b></P>". $cname . " for the following ebook " . $bname ); } else { echo("<p>Message delivery failed...</p>"); }} ?> Hi This may seem pretty standard to some of you but I am having a problem with tables. What I am trying to do is give the user 4 fields to choose from and depending upon which field they enter data into the php will query the mysql database and return all of the data related to that value and place it into a table. Seems fair enough however there could be multiple entries of that value and I want there to maybe be a loop that will check for the information and then when it is done complete the table. My code looks something like this: <html> <?php # Script 14.2 - course_form.php // This page allows the administrator to add a course (product). $con = mysql_connect("localhost","root","millennium"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_POST['submitted'])) { // Check if the form has been submitted. // Validate the print_name, image, artist (existing or first_name, last_name, middle_name), size, price, and description. // Check for a course id. if (!empty($_POST['IpAddress'])) { $ip = ($_POST['IpAddress']); } else { $ip = FALSE; } // Check for a course id. if (!empty($_POST['Identifier'])) { $id = ($_POST['Identifier']); } else { $id = FALSE; } // Check for a course id. if (!empty($_POST['Destination'])) { $de = ($_POST['Destination']); } else { $de = FALSE; } // Check for a course id. if (!empty($_POST['Reply'])) { $re = ($_POST['Reply']); } else { $re = FALSE; } // Add the course to the database. mysql_select_db("accs", $con); $result = mysql_query("SELECT * FROM smsaudit WHERE smsreply='$re' || smsorigip='$ip' || smsidentifier='$id' || smsdest='$de'"); $tdcount = 1; $numtd = 4; // number of cells per row echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { if ($tdcount == 1) echo "<tr>"; echo "<td>IP Address: $ip </td>"; // display as you like echo "<td>Identifier: $id </td>"; echo "<td>Destination: $de </td>"; echo "<td>Reply: $re </td>"; if ($tdcount == $numtd) { echo "</tr>"; $tdcount = 1; } else { $tdcount++; } // time to close up our table if ($tdcount!= 1) { while ($tdcount <= $numtd) { echo "<td> </td>"; $tdcount++; } echo "</tr>"; } echo "</table>"; } echo "<br />"; $result2 = mysql_query("SELECT totalsms FROM smsaudit ORDER BY totalsms DESC LIMIT 1"); while($row = mysql_fetch_array($result2)) { echo 'You have used ' . $row['totalsms'] .' sms messages'; } } else { // Display the form. ?> <form action="form1.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="524288"> <p> </p> <table width="449" border="0"> <td><h1>SMS Information</h1></td> <td> </td> <td> </td> <td> </td> </tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td width="160"><strong>IP Address</strong></td> <td width="95"> </td> <td width="167"><strong>Identifier</strong></td> </tr> <tr> <td><input name="IpAddress" type="text" id="IpAddress" /></td> <td> </td> <td><input name="Identifier" type="text" id="Identifier" /></td> <td width="9"> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><strong>Destination</strong></td> <td> </td> <td><strong>Reply</strong></td> <td> </td> </tr> <tr> <td><input name="Destination" type="text" id="Destination" /></td> <td> </td> <td><input name="Reply" type="text" id="Reply" /></td> <td> </td> </tr> <tr> <td><input type="submit" name="Submit" id="Submit" value="Submit" /></td> <td> </td> <td> </td> <td> </td> </tr> </table> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php } // End of main conditional. ?> </html> Can anyone please let me know of a way to achieve this? Thanks Hi I have the following code works well However, if there is more than one record in the search result it shows the table lables on every record rather than just the one is it possible to have the table lables for just the result headings and not on each line after <?php require "header.php"; ?> <main> <link href="style.css" rel="stylesheet" type="text/css"> <div class="wrapper-main"> <div class="welcomelogged1"> <p>Searching For A Starter<p> </div> <form action="" method="post"> <select name="WeekComm" id="WeekComm"> <option value="Enter Week No To Search">Enter Week No To Search</option> <option value="WC 6th April">WC 6th April</option> <option value="WC 13th April">WC 13th April</option> <option value="WC 20th April">WC 20th April</option> </select> <input type="submit" name="Search" value="Search Starters"> </form> <?php $dBServername = "localhost"; $dBUsername = "root"; $dBPassword = ""; $dBName = "CandidateManagement"; mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect($dBServername, $dBUsername, $dBPassword, $dBName); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } if (isset($_POST['Search'])) { $WeekComm = $_POST['WeekComm']; $query = "SELECT * FROM contract where WeekComm='$WeekComm' "; $query_run = mysqli_query($conn,$query); while($row = mysqli_fetch_array($query_run)) { ?> <form action="" method="POST"> <table> <Tr><td><label></label></td> <td><label>Week Commencing</label></td> <td><label>First Name</label></td> <td><label>Last Name</label></td> <td><label>Start Date</label></td> <td><label>Client Name</label></td> <td><label>Action</label></td> </Tr> <tr> <td><input type="hidden" name="id" value="<?php echo $row['id'] ?>"></td> <td><input type="text" name="WeekComm" value="<?php echo $row['WeekComm'] ?>"></td> <td><input type="text" name="FirstName" value="<?php echo $row['FirstName'] ?>"></td> <td><input type="text" name="LastName" value="<?php echo $row['LastName'] ?>"></td> <td><input type="date" name="StartDate" value="<?php echo $row['StartDate'] ?>"></td> <td><input type="text" name="ClientName"value="<?php echo $row['ClientName'] ?>"></td> </tr> </form> <?php } }
I have attached a picture to show what i mean
Thanks grouping - i need to add an option where i can select ALL of the branches -then my table will show all list of employees' leaves from all the branches.. -to make it easier to view all the leave details when i select ALL.. -instead of having to preview all the branches 1 by 1. -do i need to modify my view on my database or just modify my codes..what codes should i use. -Please tell me where and what do i need to change. Code: [Select] <h3><FORM name ="reportbutton" method="post" align="left" action="index.php?view=report"> <strong>Leave Application Listing </strong>| <Input type = "Submit" Name = "Submit1" Class="button" VALUE = "Back To Report"> </h3> </FORM> <br><br> <form name="leavebutton" method="post" action="index.php?view=report_leave"> <? $b=$_GET['b']; $m=$_GET['m']; $y=$_GET['y']; if ($b <> '' && $m <> '' && $y <> '') { $branch=$b; $leavemonth=$m; $leaveyear=$y; } else { $branch=$_POST['branch']; $leavemonth=$_POST['leavemonth']; $leaveyear=$_POST['leaveyear']; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query="SELECT * from tblworkgroup"; $result=mysql_query($query);?> Branch <select name="branch" > <? while($row=mysql_fetch_array($result)) { ?> <option value= "<?=$row['WorkGroupID']?>" <? if ($branch==$row['WorkGroupID']){ echo 'selected'; } ?> ><?=$row['WorkGroupName']?></option> <? } ?> </select> </td> </tr> <br><br><br> Month <select name="leavemonth" > <option value = "1" <? if ($leavemonth==1){ echo 'selected'; } ?>>January</option> <option value = "2" <? if ($leavemonth==2){ echo 'selected'; } ?>>February</option> <option value = "3" <? if ($leavemonth==3){ echo 'selected'; } ?>>March</option> <option value = "4" <? if ($leavemonth==4){ echo 'selected'; } ?>>April</option> <option value = "5" <? if ($leavemonth==5){ echo 'selected'; } ?>>May</option> <option value = "6" <? if ($leavemonth==6){ echo 'selected'; } ?>>June</option> <option value = "7" <? if ($leavemonth==7){ echo 'selected'; } ?>>July</option> <option value = "8" <? if ($leavemonth==8){ echo 'selected'; } ?>>August</option> <option value = "9" <? if ($leavemonth==9){ echo 'selected'; } ?>>September</option> <option value = "10" <? if ($leavemonth==10){ echo 'selected'; } ?>>October</option> <option value = "11" <? if ($leavemonth==11){ echo 'selected'; } ?>>November</option> <option value = "12" <? if ($leavemonth==12){ echo 'selected'; } ?>>December</option> </select> Year <select name="leaveyear" > <option value = "2010" <? if ($leaveyear==2010) { echo 'selected';} ?>>2010</option> <option value = "2011" <? if ($leaveyear==2011) { echo 'selected';} ?>>2011</option> <option value = "2012" <? if ($leaveyear==2012) { echo 'selected';} ?>>2012</option> <option value = "2013" <? if ($leaveyear==2013) { echo 'selected';} ?>>2013</option> <option value = "2014" <? if ($leaveyear==2014) { echo 'selected';} ?>>2014</option> <option value = "2015" <? if ($leaveyear==2015) { echo 'selected';} ?>>2015</option> <option value = "2016" <? if ($leaveyear==2016) { echo 'selected';} ?>>2016</option> <option value = "2017" <? if ($leaveyear==2017) { echo 'selected';} ?>>2017</option> </select> <input type='submit' name='submit' value='Preview' Class="button" onclick='return validate()'> </div> </form> <br /><br /> <div id="box" valign="top"> <h3> <strong>Leave Application Details</strong>  </h3> <br><br> <FORM name="printbutton" method="post" align="left" action="report_print.php" target="_blank"> <input type="hidden" name="leavemonth" value="<?php echo $leavemonth; ?>"> <input type="hidden" name="leaveyear" value="<?php echo $leaveyear; ?>"> <input type="hidden" name="branch" value="<?php echo $branch;?>"> <Input type = "Submit" Name = "Submit1" Class="button" VALUE = "Print Leave Details"> </form> <table width="80%" align="center" > <thead> <tr> <th width="700px" align="left">Name</a></th> <th width="500px" align="center"></a>Application</th> <th width="500px" align="center"></a>Date</th> <th width="500x" align="right"></a>Reason</th> </tr> </thead> <tbody> <? /*echo "branch:".$branch.'<br />'; echo "leavemonth:".$leavemonth.'<br />'; echo "leaveyear:".$leaveyear.'<br />';*/ //-------------------------------------------------- if ($leavemonth =='' || $leaveyear =='' || $branch == '') { // one value missing, so don't display } else { // start display data $rs = mysql_query( " call vwleavereport('$leavemonth', '$leaveyear', $branchid, 0);"); $query="SELECT *, MONTH(tblleaveapplication.DateFrom) as DFMonth, MONTH(tblleaveapplication.DateTo) as DTMonth, YEAR(tblleaveapplication.DateFrom) as DFYear FROM `tblleaveapplication` LEFT JOIN `tblemployee` ON tblleaveapplication.employeeid = tblemployee.id WHERE WorkGroupID = '".$branch."' AND ( (MONTH(tblleaveapplication.DateFrom)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") OR (MONTH(tblleaveapplication.DateTo)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") ) "; $result = mysql_query($query); while($row=mysql_fetch_array($result)) { echo '<tr>'; echo '<td>'.$row['EmployeeName'].'</td>'; echo '<td>'.$row['DateFrom'].'</td>'; echo '<td>'.$row['DateTo'].'</td>'; echo '<td>'.$row['Purpose'].'</td>'; echo '</tr>'; } } ?> </table> Hi all! I've been recently messing with PHP and MySQL to attempt to create a search function for my tables (too advanced, so I toned it down to learning to just display data from my table). Anyways, I'm watching a YouTube video on how to do it, and I'm copying his code exactly, but I'm still getting an error. Can anyone help? Thanks. Edit: Sorry, my error was snuggled down below the code. Anyways, my error is just my while echo appearing in and out of my tables on the page. My code: <?php //Make connection mysql_connect('localhost', 'root', 'test'); // select db mysql_select_db('testdatabase'); $sql="SELECT * FROM employees"; $records=mysql_query($sql); ?> <html> <head> <title>Employee Data</title> </head> <body> <table width="600" border="1" cellpadding="1" cellspacing="1"> <tr> <th>ID</th> <th>First name</th> <th>Surname</th> <th>Age</th> </tr> <?php while($employees=mysql_fetch_assoc($records)){ echo "<tr>"; echo "<td>".$Employee['ID']."</td>"; echo "<td>".$Employee['First name']."</td>"; echo "<td>".$Employee['Surname']."</td>"; echo "<td>".$Employee['Age']."</td>"; echo "</tr>"; } // end while ?> </table> </body> </html> Edited by thwikehu1990, 19 January 2015 - 01:33 PM. Hi, I have 2 tables t1 and t2. They have identical columns only except t1 has one extra column x1. What I want is to dump data from t2 to t1, and in the x1 column, put the person's name (get from SESSION). So, I want the best optimized way to do something like Code: [Select] mysql_query("INSERT INTO `t1` '".$usename."' , SELECT * FROM `shareltp`"); //which obviously doesn't work please help |