Jump to content

Andy17

Members
  • Posts

    249
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male

Andy17's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Hey guys, Firstly, this is not solely about PHP, but rather a mixture of jQuery, JSON, PHP and MySQL, but I hope it's OK to post it here. I am sending data to a PHP script via the jQuery ajax function. The data is encoded in JSON and then decoded in the PHP script. This all works great. However, I noticed that one of my queries does not work with certain characters in the data (more specifically the Danish characters æ, ø and å). The query works with other data except those. The query also works if I hard code the data into the PHP script, even if it contains any of the three mentioned characters. This leads me to believe that the problem is somehow connected to character sets when sending data from one page to my PHP script with jQuery. The page from which the data is sent to the PHP script has a charset of iso-8859-1 and the columns utf8_danish_ci. I can indeed see that those are not the same, but I have tried to use the PHP uft8_encode() function in my PHP script, but without luck. I have not posted any code because I don't really find this relevant in relation to my problem. Can anyone think of a way to solve this without changing charset on the page from which the data is sent from (to the PHP script)? Thanks in advance, Andy
  2. I'm not 100% sure I understand what you want. But, if you have a product which has a single manufacturer associated with the product, you can simply have a foreign key in your product table that references a column in a manufacturer table. So, a query could look like this: SELECT * FROM Manufacturer WHERE ManufacturerId = (SELECT ManufacturerId FROM Product WHERE someUniqueColumn = 'someUniqueValue') That would give you the manufacturer details for a given product. As I was reading your post again, it seems like I misunderstood what you wrote, but I hope the above is of any help anyways - otherwise I will have to try again.
  3. I already said to notice the orange border in that screenshot. It finds the correct values, but for some reason, I only have access to the Name column. When I try to echo out the other columns in PHP, nothing is displayed.
  4. You're welcome - glad I could help.
  5. I didn't read what you are doing too much, but I hope the below will be useful anyways (the principle). You could put a column in your current table (I will assume that it is named "Booking") named something like "pageId" and then make a new table named "Page" with the following columns: pageId, pageName. You should of course add more if you find some useful - a description for instance. Then add a foreign key from Booking.pageId to Page.pageId. So, each row in your "Booking" table has a reference to a Page row. This means that you can have different pages for different bookings. So, you should be able to do something like this: $query = "SELECT b.field1, b.field2, b.field3, b.pageName FROM Booking b, Page p WHERE b.someUniqueField = 'someValue' AND p.pageId = b.pageId"; // Some code omitted while($rows = mysql_fetch_assoc($result)) { echo '-Title: <a href="' . $rows['pageName'] . '.php" alt="' . $rows['title'] . '">' . $rows['title'] . '</a><br/>-Author: ' . $rows['author'] . '<br />'; } Excuse me if I made some simple syntax mistake above. But, now you should be able to associate a given booking row with a page and link to that page. Good luck!
  6. Just a security note; as users can easily modify the id value and therefore do SQL injection, I strongly suggest doing like below: $id = mysql_real_escape_string($_GET['id']); $sql = "select * from book where title_id = " . $id; You probably already know this, but just making sure he does not make this mistake.
  7. (Just so you don't have to scroll) Let's say that I have the following ContentTypes with some descriptions: News Videos Pictures For each of those ContentTypes, I have associated ContentCategories (which is done in the many-to-many relation named TypeCategory). So, the ContentType "News" could have the following categories: Sports Crime Celebrities Gaming ... and the "pictures" ContentType could have different categories associated with it. So on a page I want to display the categories a given ContentType has associated with it. If this ContentType was "News", I would want the query to return the rows in ContentCategory that are associated with it. In this example, I would want it to return the categories given above (sports, crime, celebrities, gaming - and their Description and CategoryNum). My query finds the correct categories associated with the ContentType I provide, but it only returns the category's Name and not Description and CategoryNum, which I also need (notice the orange border around the Name column in the phpMyAdmin screenshot in the first post). I hope that helps.
  8. Hey guys, I am building a new website and have a query that I want to return multiple columns, but it only returns one. Before I start explaining too much, here is the relevant part of my database diagram: What I want to do is to select the Name, Description and CategoryNum from the ContentCategory table that corresponds to a given ContentType row. For example, let's say that I have a ContentType row with the name "News". I would then want to find the categories associated with that type in the ContentCategory table. So, there are a number of categories associated with different types of content. Here is my query: SELECT cc.Name, cc.Description, cc.CategoryNum FROM ContentCategory cc INNER JOIN TypeCategory ON cc.CategoryId = TypeCategory.CategoryId INNER JOIN ContentType ON ContentType.ContentTypeId = TypeCategory.ContentTypeId WHERE ContentType.ContentTypeId = 'News' The Name column in ContentType is unique. I have some test data in my tables. I get the correct row, but it only selects the Name column from ContentCategory as shown below. I am pretty new to inner joins and using many-to-many relations, so I would really appreciate if anyone can tell what I am doing wrong. If it helps anyone, here is my table structure: CREATE TABLE ContentType ( ContentTypeId int NOT NULL auto_increment, Name VARCHAR(20) NOT NULL, Description VARCHAR(150) NOT NULL, PRIMARY KEY (ContentTypeId), UNIQUE (Name) ) CREATE TABLE TypeCategory ( ContentTypeId int NOT NULL, CategoryId int NOT NULL, PRIMARY KEY (ContentTypeId, CategoryId), FOREIGN KEY (ContentTypeId) REFERENCES ContentType(ContentTypeId), FOREIGN KEY (CategoryId) REFERENCES ContentCategory(CategoryId) ) CREATE TABLE ContentCategory ( CategoryId int NOT NULL auto_increment, Name VARCHAR(50) NOT NULL, Description VARCHAR(500) NOT NULL, CategoryNum int NOT NULL, PRIMARY KEY (CategoryId), UNIQUE (Name, CategoryNum) ) Thanks a lot in advance! Andy
  9. This should work (with MySQL or PostgreSQL): SELECT * FROM YourTable ORDER BY TableId ASC LIMIT 1 OFFSET 20 Replace the 20 with 11 for getting the 12th row.
  10. Yeah, I was thinking that it had something to do with that function. I don't know why I didn't look it up. Guess I was too frustrated. Anyways, after reading what you wrote, I made it work by using the file_get_contents function instead. Thank you very much for your help.
  11. Wow, I didn't even think of that. Thanks for pointing that out. Smooth, that seems to work. Thanks a lot.
  12. I hope that subject made sense! I have a page where I want to generate page-specific keywords automatically. Actually I have some general keywords stored in a text file and then I add the page-specific ones after those. The problem is, however, solely caused by the keywords I pull from my text file. A "1" is added to my list of keywords. Consider a news page like so: news.php // ... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="<?php require('php/generateKeywordList.php'); ?>" /> </head> // ... And then generateKeywordList.php // I have omitted the part with the page-specific keywords, because it is not what causes the problem (commented it all out) set_include_path('/mypath/'); $str = require_once('includes/websiteKeywords.txt'); echo $str; // For some reason, the number 1 is added at the end of this string websiteKeywords.txt (it doesn't matter what I put in there) these, are, my, keywords, for, my, website In my meta tag, the above would be displayed as: these, are, my, keywords, for, my, website1 I then tried to make a simple php page like this $keywords = require('includes/websiteKeywords.txt'); echo $keywords; ... and it worked. At the moment I have absolutely no idea where the number 1 comes from. So, basically if I include the keywords directly from the text file into my meta tag, it displays fine. If I make a simple php page where I echo out the keywords from the text file, it displays fine. But if I include my php script, which echos the keywords, into my meta tag, the number 1 is added at the end of the string. Am I completely missing something here or is this extremely strange? Thanks for any help!
  13. Hey I'm pretty new to regular expression, so I might have made a silly mistake. I want to check if there are any symbols/special characters (not letters or numbers) in a string. I have the code below. function validateKeywords($kw) { if (preg_match("/[^A-Za-z0-9]/", $kw)) { echo 'validation of keywords failed<br />'; return false; // String contains symbols (not letters or numbers) - incorrect format! } else { echo 'validation of keywords succeeded<br />'; return true; // Correct format } } // Testing validateKeywords('some random string I wrote for testing purposes'); // should succeed validateKeywords('some random 10 string I wrote for testing purposes 2010'); // should succeed validateKeywords('some random, string, I wrote for 19 testing purposes'); // should fail validateKeywords('some, random, string I wrote, for testing purposes'); // should fail The problem is that all 4 calls return false and print that the validation failed. So, where did I mess up? Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.