PHP - Moved: How To Contact Two Tables In A Database ?
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=353621.0 Similar TutorialsThis topic has been escorted to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=354341.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305902.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308347.0 Hi All I have a contact form whcih works great - its has a little validation on it and sends me all the information I need via email. I now want to store all data submitted via the form to be stored in a MySQL database. What is the best way to do this?? Attached is my form as it is, just being emailed to the relevent accounts. Look forward to your replies. Adi This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=359389.0 Hello All, I have a contact directory database. It has all the employees of my company (name, phone, email, department, building, etc). Say on one page I have the Marketing Department, and I want to say: "The Marketing Department Director is ________" How would I assign that value from the database? Do I want to put in a unique "keyword" field in the database, but then how would I store all the values automatically on the page? I see pages where I would want to list the Marketing Director, and his secretary, then another page with the Sales Director, and his secretary, etc.... all with being able to change the values in the database, and it changing across all the pages instantly. Do I need to say on every page "select * from database where keyword = marketingdirector" and then store that result as a variable? It seems unpractical to repeat that a few times for each different person I want to list. Is there a better way to do this then I'm thinking? Thanks all! This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358012.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=329670.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=306808.0 Hi guys, Is it possible to insert into two tables in a database? Thanks I have two tables. Let's call the first one items and the second one item categories. Now the items table would look something like this: id(auto_increment id) name description categoryid The item categories table would look something like this: categoryid name description An entry in the items table would look something like this: categoryid = 1,2 name = Thing description = something id = 1 Say I want to retrieve records that contain "1" in the categoryid column. How would I do that? Hi, I am re-visiting my database table relationship for criminal incidents. Six tables are involved plus a junction table to make it seven tables in total. I need someone to review this relationship and advise whether or not it is correctly set up. The relationships are as follows: 1. A person can belong to more than one incident: t_persons (one-to-many) t)_incidents_persons 2. A person can only have one nationality by birth t_persons (one-to-one) t_countries 3. An agency can have more than one incident t_agencies (one-to-many) t_incidents 4. A status (e.g. closed incident) can belong to more than one incident t_status (one-to-many_ t_incidents 5. A keyword (i.e. offence type eg theft) t_offencekeywords (one-to-many) t_incidents How we can make the connection to ODBC in PHP If any shares the coding part then it would be great. (Table to database) Hi can anybody help I need to export and download tables from a database into a excel sheet. I have this code and it works what I need is to export specific fields and not just the whole table can anyone help modifying the code to export certain fields within the table please? Here is the code... Code: [Select] <?php $host = 'localhost'; $user = 'user'; $pass = 'password'; $db = 'qdbname'; $table = 'tablename'; $file = 'export'; $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field']."; "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j]."; "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Hi everyone. I would like to do this: In page1.php, I need to make a few checkboxes, which when the user clicks "next" button, transfers the data (which checkboxes were clicked) to a database table. Then, when the user clicks a button "next", he is moved to another page, page2.php, from which he is automatically transferred to page3.php. At page3.php those values are gathered from the database, and the user has to click "next" button again, then those values are written into another table, in the same or another database. How can I do this? I've not much knowledge with neither SQL, neither PHP. I hope you will help me make this work, I'm making a little system for my HTML website. Thanks, if you do! Hi there i have a big issues which is starting to cause me lots of stress. I have two tables one which is products and contains the following below and the other which is additionalCategories which the contains is also below. products id name image1 image2 image3 image4 image5 description department category subcategory Price additonalCategories id departmentID categoryID subcategoryID productID i have made a products upload script to my site where i can add products too it saves the category and subcategory id's in the fields above then if i wish to add the product to additional categories i do so and again this adds all the data to the addiotnalCategories table. however i can seems to be able to display this on the view products page i tried the below code but get no luck Code: [Select] <?php session_start(); $username=$_SESSION['username']; include_once"../includes/db_connect.php"; $cat=$_GET['cat']; ?> <!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>Untitled Document</title> </head> <body> <?php $query("SELECT products.name AS name, products.price AS price, addtionalCategories.productID AS productID FROM products, addtionalCategories WHERE category='$cat' AND products.id = addtionalCategories.productID"); while($fetch=mysql_fetch_object($query)){ echo"$fetch->name"; } ?> </body> </html> i need a way in which on the page it check the category id then finds all the products that are saved in the additionalCategories table then to find the data saved in the products table such as the name and price etc please any help will be appreciated thank you for reading Hey All, Been banging my head into the wall on this one. I have 2 tables one for users 'myMembers' and one for products 'products'. Each table has a auto increment id. The myMembers id is the user id and the products table id is for the product id. I have a row in the products table for agent_id. I would like the agent_id to be filled with the id from the myMembers table. I took a look at the manual; still do not understand how to take the id from the myMembers table then place that id into the agent_id; so the products(id) can be listed under the specific members id(agent_id) in the products table. So far my script for the products table inserts items correctly, but does not file under the specific agent_id. Here is the script for entering items to the products table. Thanks for the guidance! <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Delete Item Question to Admin, and Delete Product if they choose if (isset($_GET['deleteid'])) { echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="inventory_list.php">No</a>'; exit(); } if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error()); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: inventory_list.php"); exit(); } ?> <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, agent_id price, details, category, subcategory, date_added) VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); } ?> <?php // This block grabs the whole list for viewing $product_list = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $product_list .= "Product ID: $id - <strong>$product_name</strong> - $$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; } } else { $product_list = "You have no products yet"; } ?> Here is the sample page: http://hoosierhoopsreport.com/pg-test/ Trying to create a table that has three sections (groupings). That part I have figured out. The first grouping is sorted numerically. The second group is sorted alphabetically based on what part of the state they live in. It's breaking down this second part that I can't seem to get. (The third group is just what's left over, sorted alphabetically.) So it needs to look like this: (Each group and region have their own header row. Only Group 2 is broken down into Regions.) Group 1 Group 2 -Region 1 -Region 2 -Region 3 -Region 4 -Region 5 Group 3 The sample page above, in Group 2, it just shows Region 1 header. Code: [Select] $query = 'SELECT * FROM a_playerRank WHERE year="2015" and position="1" ORDER BY grouping DESC,rankPos,region,nameLast'; $results = mysql_query($query) or trigger_error('MySQL error: ' . mysql_error()); $currentGrouping = false; $currentRegion = false; while($line = mysql_fetch_assoc($results)) { if($currentGrouping != $line['grouping']) { //Status has changed, display status header $currentGrouping = $line['grouping']; if($line['grouping']==2) { echo '<thead> <tr> <th class="num">#</th> <th class="top">Top 10</th> <th class="height">HT</th>'; if (current_user_can("access_s2member_level4")){ echo '<th class="level">Level</th>'; } echo' <th class="school">City (School)</th>'; if (current_user_can("access_s2member_level4")){ echo '<th class="summer">Summer Team</th>'; } echo' <th class="college">College</th> </tr> </thead>'; } if($line['grouping']==1) {echo '<tr><th colspan="7">Best of the Rest</th></tr>'; if($currentRegion != $line['region']) { $currentRegion = $line['region']; echo '<tr><th colspan="7">Region' .$line['region'] . '</th></tr>';} } if($line['grouping']==0) echo '<tr><th colspan="7">Names to Know</th></tr>'; } I have a relational table call sales with prodcut_id and custmer_id tables. I also have a product and customer tables. products table with product_id as an auto increment and customer with custumer_id I want to join through the sales tables all t he fields of row 1 from tables customer and products and pull it at once. This is a member login script and I want to display the products by members. So far I have this query to display the products once the member is login in. $userid is the id of the customer coming from the $userid= $_SESSION['customer_id']; $mysqlSales="SELECT products.* FROM products JOIN sales ON (products.product_id = procuct_id ) WHERE sales.customer_id = '$userid'"; so far that statement is not working where should I have some type of incoherance with the english statement above expressing what I want the query to do. Hi, I have a problem. i want to show the current date and time in my tables of the database. I want to show it because i want to show it on my report generated in php. By the way i do not have a "date" field in my form. Can anyone help me out? Thanks, Heshan. |