PHP - Simple Mysql_query Table Join Help Needed
I have two mysql tables, one is called "posts", the other is called "removed_posts", I have joined them together and can get some of the information from the tables, but I want to be able to get all of the information.
This is my query, and the variables I need the information to go to: Code: [Select] $quer = mysql_query("SELECT posts.id, removed_posts.post_id FROM posts, removed_posts WHERE posts.id=removed_posts.post_id AND removed_posts.user_id='".$session."'"); while($get_post = mysql_fetch_array($quer)) { $session = $_COOKIE['id']; $to_id = $get_post['to_id']; $from_id = $get_post['from_id']; $post = linkify(nl2br(htmlentities($get_post['post']))); $date = time_stamp($get_post['date']); $id = $get_post['id']; What that's doing is selecting the id from 'posts' table, and selecting the post_id from the 'removed_posts' table (The query checks to make sure posts.id is equal to removed_posts.post_id), it does that just fine, since I defined what information I wanted it to get in the query, however, now I need to get the other information which will come from the 'posts' table. $get_post['to_id'], $get_post['from_id'], $get_post['post'], and $get_post['date'] I hope that's not toooooo confusing, any help would be appreciated Similar TutorialsHello, I am still new to PHP, but am getting better. The Problem is, I have read all the tutorials and everything and successfully accomplished this at other places so I don't know what the issue is. I bet it is small, as it always seems to be an oversight that causes issues. I am trying to do a MySQL Update Query with variables and I keep getting this error message: Quote 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 'LastName = 'Smith' BirthDate = '1993-12-05' Gender = 'Male' De Here is the code: Code: [Select] mysql_query("UPDATE orphans SET FirstName = '$firstname' LastName = '$lastname' BirthDate = '$birthdate' Gender = '$gender' Description = '$decrip' SponsorCount = '$sponsorcount' Created_On = 'createdon' Changed_On = '$changedon' PictureOne = 'pictureone' PictureTwo = 'picturetwo' PictureThree = '$picturethree' PictureFour = $picturefour' PictureFive = '$picturefive' WHERE IDa = '$IDa'") or die(mysql_error());The variables seem to be working, I just don't know what the issue is. Thanks for the help in advance! Edited to Fix Stupid Mistakes Hi, well, I think it's about joining within the same table, but I'm not sure. Here's my problem: I have a table with a number of categories and undercategories, see screendump of database he I show the categories in my select by: <option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option> This gives me (here sorted alphabetically): 1.semester 3.semester 5.semester Underkategori_1_i_1.semester Underkategori_1_i_3.semester Underkategori_1.1_i_3.semester But I would like for it to show the path (the relation between categori and under-/subcategory (see "parent" and "path" in the database (screenshot above)), so that is will display the list like this: 1.semester 1.semester/Underkategori_1_i_1.semester 3.semester 3.semester/Underkategori_1_i_3.semester 3.semesterUnderkategori_1_i_3.semester/Underkategori_1.1_i_3.semester 5.semester etc. How can I join either "parent" or "path" with "id" (see screendump of database above) to create a listing like that? Or is that the correct way to do it at all? Hope someone can help me out! SELECT R.RegionName, A.City FROM `activepropertylist` A, `ParentRegionList` R, `RegionEANHotelIDMapping` RM WHERE MATCH(City, RegionName) AGAINST ('hervey bay' IN BOOLEAN MODE) and A.EANHotelID = RM.EANHotelID and RM.RegionID = R.RegionID and R.RegionType = 'Neighborhood' schema http://developer.ean.com/database-catalogs/relational/geography-data/ book a suit search box example http://www.bookasuite.com/I am trying to join 3 tables together to get the correct information from expedia tables for my auto drop down box the schema is here, located in the link and I am looking auto search like book a suite do(link also provided) problem is I can manage to get the word hervey bay out of the property region list table but the incorrect city comes back from the activeproperylist table(it seems to be showing something from the other table for the city) here is my query Hi, I have a fantasy football website, and on a user account page I want to display fixtures that are coming up that include teams that the current user has chosen. My test_teams table stores all the team names and their teamid. The test_selections table is where each users team selections are stored, it has two columns, userid and teamid. The test_fixtures table has two columns, hometeam and awayteam, these two cloumns hold the teamid of the teams that are playing. The code below correctly displays the fixtures that contain any of the current users team selections. However, it is only displaying the teamid of the teams that are playing as they have not been matched to the test_teams table to get the team name. Does anybody now how I can do this? I believe it can be done using a left join but so far I just keep getting errors when i try to write the code. Any help would be very much appreciated. Code: [Select] <table width="380" border="0"> <?php $query = "SELECT test_fixtures.competition, test_fixtures.date, test_fixtures.hometeam, test_fixtures.awayteam FROM test_fixtures, test_selections WHERE test_selections.userid = '{$_SESSION['userid']}' AND (test_selections.teamid = test_fixtures.hometeam OR test_selections.teamid = test_fixtures.awayteam)"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> <tr> <td width="85" class="fixtures_date"><?php echo $row['date']; ?></td> <td width="30" class="fixtures_comp"><?php echo $row['competition']; ?></td> <td width="135" class="fixtures_home_teams"><?php echo $row['hometeam']; ?></td> <td width="25" class="fixtures_center">v</td> <td width="135" class="fixtures_away_teams"><?php echo $row['awayteam']; ?></td> </tr> <?php } ?> </table> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321459.0 I'm outputting my DB to a table. I want to include a JOIN so the table shows name, email, and company (which is in a different table). Not sure where to put the join. 2 other things I'd like to do: Not all users have email and I want any NULL to output as N/A instead of NULL. Would like the rows to alternate background color between white and blue for each row. Any hints appreciated. $query= "select * from Managers"; $result=mysql_query($query); echo mysql_error(); echo '<table align="center" cellspacing="1" cellpadding="2"> <tr> <td align="left"><b>Name</b></td> <td align="left"><b>Email</b></td> <td align="left"><b>Company</b></td> </tr> '; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['name'] . '</td> <td align="left">' . $row['email'] . '</td> <td align="left">' . $row['company.name'] . '</td> //Need JOIN here </tr> '; } Dear All, As I would like to create json as below format { "data": [ { "title": "After getting a COVID-19 Vaccine", "content": [ { "list": "You may have some side effects, which are normal signs that your body is building protection." }, { "list": "Following symptoms can take place, and it usually resolves within 2 to 3 days." }, { "list": "Common Side Effects pain, redness, swelling, warmth, nausea, muscle pain, tiredness, headache" } ] }, { "title": "After getting a COVID-19 Vaccine", "content": [ { "list": "You may have some side effects, which are normal signs that your body is building protection." }, { "list": "Following symptoms can take place, and it usually resolves within 2 to 3 days." }, { "list": "Common Side Effects pain, redness, swelling, warmth, nausea, muscle pain, tiredness, headache" } ] } ] } The information is from mysql select command: SELECT (tb_helpinfo.title_eng) as title,(tb_helpdetail.content_eng) as content FROM tb_helpinfo INNER JOIN tb_helpdetail ON tb_helpinfo.id = tb_helpdetail.helpinfo_id
I'm trying to conditionally add a table to a select query using the join, but I always get an "no such table" error. I'm not at all sure if the syntax is correct, so I decided to ask.
I'm using the sqlite C API interface and my tables and query were constructed using sprintf, so please ignore any %d, %s that may appear
CREATE TABLE IF NOT EXISTS tbl_master ( id INTEGER PRIMARY KEY AUTOINCREMENT, volume TEXT(16) UNIQUE NOT NULL DEFAULT '', note TEXT(%d) NOT NULL DEFAULT '', items INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE IF NOT EXISTS tbl_file ( id INTEGER PRIMARY KEY AUTOINCREMENT, volume_key TEXT(16) NOT NULL DEFAULT '', name TEXT(%d), size TEXT(20), type TEXT(4), path TEXT(%d), file_id INTEGER ); CREATE TABLE IF NOT EXISTS tbl_hash ( id INTEGER PRIMARY KEY AUTOINCREMENT, hash TEXT(33) NOT NULL DEFAULT '', volume_key TEXT(16) NOT NULL DEFAULT '', file_key INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE IF NOT EXISTS tbl_media ( id INTEGER PRIMARY KEY AUTOINCREMENT, runtime TEXT(10) NOT NULL DEFAULT '', frame TEXT(12) NOT NULL DEFAULT '', type_key TEXT(4) NOT NULL DEFAULT '', hash_key TEXT(33) NOT NULL DEFAULT '', volume_key TEXT(16) NOT NULL DEFAULT '', file_key INTEGER NOT NULL DEFAULT 0 );I milled over a few JOIN tutorials, but I'm still unclear on the exact usage of JOIN; I'm trying to add the media table if the file type is a vid, snd, or pix, but I need file information regardless. I've tried various flavors of the following query, but each time I get the table doesn't exist error. Selects, deletes, updates, inserts work on all tables, so I'm guessing my syntax is wrong with the JOIN. SELECT tbl_file.*, tbl_hash.hash FROM tbl_file AS f, tbl_hash AS h LEFT OUTER JOIN tbl_media AS m ON ((f.type='VID' OR f.type='SND' OR f.type='PIX') AND m.file_key=f.file_id) WHERE ((f.volume_key=tbl_master.volume AND (h.volume_key=tbl_master.volume AND h.file_key=f.file_id))) ORDER BY f.path ASC;Any ideas on how to pull off what I'm trying to do would be greatly appreciated. Thank you for your time. Hello EXPERTS , i want to Frame many pages of same code so how to do it from one page example 1 = www.abcd.com/Frame1.html [has the code given below in it] <iframe src="http://abcdsecond.com/Frame1.html" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" frameborder="0" height="100%" scrolling="yes" width="100%"></iframe> www.abcd.com/Frame2.html [has the code given below in it] <iframe src="http://abcdsecond.com/Frame2.html" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" frameborder="0" height="100%" scrolling="yes" width="100%"></iframe> and so on , so is it possible to create one php script in www.abcd.com so when abcd.com/Frame1.html or Frame2.html or Frame3.html is run it will run this code <iframe src="http://abcdsecond.com/Frame1.html" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" frameborder="0" height="100%" scrolling="yes" width="100%"></iframe> <iframe src="http://abcdsecond.com/Frame2.html" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" frameborder="0" height="100%" scrolling="yes" width="100%"></iframe> <iframe src="http://abcdsecond.com/Frame3.html" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" frameborder="0" height="100%" scrolling="yes" width="100%"></iframe> would appreciate help I recently converted my business to an ip-pbx that has lots of capabilites. Among them is a feature I would like to use called http_notify. It sends a post to a url with parameters such as caller id number, caller id name etc.. I need to write a simple program to accept these parameters and write them to a csv file along with a date/time stamp. This seems like a super easy, short piece of code to come up with and as a noob I was hoping to write this myself. I have found a few examples where the post is for a form but I can't find any examples where the data is coming in as part of the url. This is the description of the feature on the phone system site: HTTP Notify Sends notifications to a remote web server through a URL. This allows allows an event in a Jive Core PBX to trigger an action on a remote system. Simply enter a URL in the node, and that URL will be hit with an HTTP POST as calls 'pass through'. Multiple variables are available and all variables are also included in the post body. URL Defines the URL to be used (limit of 255 characters). Next Node Connects nodes together to create a call flow. Drag and drop on the next node in the dial plan. Hello there, I'm quite new on PHP language.I'm trying to make an simple Phone book apps.I added insert & show options in Phone book.Now i want to add "update & delete" option.How can i do that. This is add code: Code: [Select] <?php mysql_connect("localhost","admin",""); mysql_select_db("simphp"); //Get Values from form $name=$_POST['name']; $email=$_POST['email']; $number=$_POST['number']; mysql_query("insert into phonebook(name,email,number) values('$name','$email','$number')"); echo"Saved Sucessfully"; echo "<br/>"; echo '<a href="index.php/">Homepage</a>'; echo "<br/>"; echo '<a href="select.php/">Show Data</a>'; echo "<br/>"; echo '<a href=update.php>Update</a>'; mysql_close(); ?>Show.php=>> Code: [Select] <?php mysql_connect("localhost","admin",""); mysql_select_db("simphp"); $query="select *from phonebook"; $result=mysql_query($query); $num=mysql_numrows($result); echo"Number of records Stored:$num"; $i=0; while($i<$num) { $name=mysql_result($result,$i,"Name"); $email=mysql_result($result,$i,"Email"); $number=mysql_result($result,$i,"number"); echo "<br/>"; echo "Name :<b> $name </b><br/>"; echo "<br/>"; echo "Email : <b>$email</b> <br/>"; echo "<br/>"; echo "Phone :<b>$number</b><br/>"; echo '<a href=update.php>Update</a>'; $i++; } ?> How can i update and delete data?? :confused:help me Hi I have a simple idea for a webapp I would like to pay someone to develop for my small business. It's a system for tracking "one off" orders we get. Basically at the moment we use paper notes. Problems with this:- - They get lost - In 6 months time if the customer wants to reorder, you have to take the customer's details again, which isn't very professional - If I remember I've taken an order for something I can't do anything about it (i.e. let my colleagues know) until I'm next at work. etc etc I wanted built a web app (basically a webpage front end to a as yet non-existent database) which would allow us to log these items and then have a search/query function where we would look through:- "open orders" "closed orders" "orders awaiting collection" etc offers to mefijob@forward.cat thanks! <?php session_start(); if(!isset($_SESSION['User'] )) header('Location : error.php'); ?> im not being redirected even when the $_SESSION['User'] is not set neither does it display any error message other than a white blank space. Please help me som1 as how I can make this to work or suggest any other altenatives so as to get it redirected as i dont want anonymous users to access some contents unles he logs in as members. Thanx Hello Freaks! I am having problem with following code: <?php simplexml_load_string ('?xml version="1.0" encoding="utf-8"?>'); php?> This code is giving me following error Parse error: syntax error, unexpected '<' in public_html/wp-content/plugins/pluginnamehere/whatever.php on line 665 I know there is only a minor bracket problem that causing me this error. I would be helpful to you if you can modify it for me Thanks First and foremost I am PHP newbie so excuse the dumb question but I have been struggling with this one for hours and can not find the solution. Can someone show me how I would rewite the following wordpress code for meta tags so that it automatically strips out the character ' from the "single" page titles? Example I want this title: "My Cat's Black" to be "My Cats Black" This is the line I am trying to edit..... Code: [Select] elseif ( is_single() ) { wp_title(''); print ' | '; bloginfo('name'); } here is the full piece of code... Code: [Select] <title><?php if ( is_home() ) { bloginfo('name'); print ' | '; bloginfo('description'); } elseif ( is_search() ) { bloginfo('name'); print ' | '; _e('Search Results', 'woothemes'); } elseif ( is_author() ) { bloginfo('name'); print ' | '; _e('Author Archives', 'woothemes'); } elseif ( is_single() ) { wp_title(''); print ' | '; bloginfo('name'); } elseif ( is_page() ) { bloginfo('name'); print ' | '; bloginfo('description'); } elseif ( is_category() ) { single_cat_title(); print ' | '; bloginfo('name'); } elseif ( is_month() ) { _e('Archive', 'woothemes'); print ' | '; the_time('F'); bloginfo('name'); } elseif (function_exists('is_tag')) { if ( is_tag() ) { bloginfo('name'); print ' | '; _e('Tag Archive', 'woothemes'); print ' | '; single_tag_title("", true); } } ?></title> Any help would be greatly appreciated!! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308855.0 I'm attempting to implement a simple social networking system but at the moment am confused about how to create a multiple query which will display a certain user's friends list. The database contains four tables, the two tables that I'm using at the moment at 'usersTable' and 'friendshipsTable' are detailed below. usersTable | Table that stores all the user data UserID | Default primary key Forename | Surname | Username | Password | Email Address | friendshipTable | Table that stores information about friendships between users FriendshipID | Default primary key userID_1 | UserID userID_2 | UserID Status | Either Pending or Confirmed. The user's id is parsed into the url, and then saved into a variable. blah.com/userprofile.php?id=6 $id = $_GET['id']; I am familiar with creating simple queries, but can't quite work out how to set up multiple table queries. What the query needs to do is to check the userID that is parsed with the url, and then check the friendshipsTable by checking if either the userID_1 or userID_2 field matches the userID to grab the records from the table where there is a match. The next step is to check to see if the friendship is 'Confirmed' or 'Pending' and if it is 'Pending' to ignore it. Once the records have then been chosen I need the query to then check the value in either userID_1 or userID_2 that doesn't match userID and then pull the user's username and name from the usersTable so it can be displayed on a webpage. I've no idea hoe much I may or may not be overcomplicating this, an example of the code that I've got so far for this query can be found below, but that's as far as I've got at the moment. $displayFriends = mysql_query("SELECT * FROM friendshipTable, usersTable WHERE friendshipTable.userID_1='$id' OR friendshipTable.userID_2='$id' "); Cheers for any help. I am getting a "mysqli_query() expects parameter 1 to be mysqli, null given" error. the code I am using is below but simplified. connect() does connect to the database without throwing any errors but when I get down to query() I get the above error. public function connect() { mysqli_connect(self::DBHOST, self::DBUSER, self::DBPASS, self::DBNAME); } public function query($query) { mysqli_query(self::connect(), $query); } below is what I am using to call the function. I am not sure if I have to pass the $link in the query function too. I have tried but it didn't seem to do any better. $link = db::connect(); $query = "SELECT name FROM plugins"; db::query($query); I am sure this is something simple that I have overlooked but I am new to this and still learning. Thank you for any help you can provide. |