Jump to content

c_pattle

Members
  • Posts

    295
  • Joined

  • Last visited

Posts posted by c_pattle

  1. Thanks.  I tried this but I'm not sure it's going to work.  A left join will list all the records from the table on the left even if there is no match with the records from the table on the right. 

     

    Because there are no matching elements in either of the tables it means I get the records from the table on the left and just "NULL" from all of the records from the table on the right. 

  2. I want to do a mysql query that takes the last two records from two tables and combines them into one row.

     

    So for example if I have a table called "table1" and the latest records are

     

    id - name

    35 - chris

    36 - chris2

    37 - chris3

     

    and a table called "table2" where the latest records are

     

    id - fruit

    16 - banana

    17 - apple

    18 - pear

     

    How can I do a query that will merge the last two rows into one so the result set would be,

     

    id - name    /    id - fruit

    37 - chris3  /    18 - pear

    36 - chris2  /    17 - apple

     

    Thanks for any help.

     

     

  3. Actually sorry forget that.  What I want to do is to have a mysql query that will combine a row from two tables into one.  For example say I have the follow tables,

     

    articles:

    1 - article 1

    2 - article 2

    3 - article 3

     

    announcements:

    1 - announcement 1

    2 - announcement 2

    3 - announcement 3

    4 - announcement 4

     

    What I want to do is to have a statement that will return the first row of both tables.  I think the best thing to do is a select statement but mine isn't quite working right. 

     

    select articles.article_title, announcements.announcement_title from articles, announcements order by article_number desc limit 0,10
    

  4. I have the follow sql which uses "union" to combine to select statements.  However when I run this it gives me all of the results of the first statement follow by all of the results of the second statement.  I was wondering if there is a way to make it output 1 results from the first statement then one results from the second statement then the second results from the first statement etc

     

    SELECT * FROM articles WHERE article_verification="1" limit 0,10 UNION (SELECT * FROM announcements WHERE announcement_verification="1" limit 0, 10);
    
    

     

    Thanks for any help. 

  5. I have a link that when pressed I want it to do a slideToggle on the next element with the class of ".article_info".  I want to do this because there are lot of elements with this class so I only want it to perform this on the next one.  I have tried lots of things but can't get this to work, it just does nothing.  Here is my code at the moment

     

    $('.article_toggle').click(function () {
    	$(this).nextAll(".article_info").slideToggle();
    return false;
    
    });
    

     

    Also here is an example of my HTML. 

     

    <div class="article">
        <div class="article_header">
            <h3>Header</h3><p><a class="article_toggle" href="">Toggle</a></p>
        </div>
    
        <p class="content">Content description</p>
    
        <div class="article_info">
            <p>Article info line 1</p>
            <p>Article info line 2</p>
            <p>Article info line 3</p>
        </div>
    </div>
    

     

    Thanks for any help. 

  6. I'm wondering if there is an easy way to converted certain characters like &'s and £'s to their html codes.  I want to do this because I am going to the getting data from a database and want to turn these characters into their html codes when doing so so that my pages validate. 

     

    Thanks for any help. 

  7. I've taken out the sections of code that are being used. 

     

    Here is the form code

     

    <label for="text">Your text <span id="text_status"></span></label>
    <textarea name="text" id="text" class="validate"></textarea>
    

     

    and this is PHP code used to submit it

     

    $submit_sql = sprintf("insert into table (name, text, category) values (\"%s\", \"%s\", \"%s\")", mysql_real_escape_string($_GET['name']), mysql_real_escape_string($_GET['text']), mysql_real_escape_string($_GET['category']));
    
    $submit_rs = mysql_query ($submit_sql, $mysql_conn);
    

     

    Could it be perhaps that I am using GET rather than POST?

  8. I am not sure what I am doing wrong but the line breaks aren't being preserved when I submit it to the database.  When I review the database there are no line breaks and when I look at the page source there are no "\n".  Below I have given an example of how I am submitting data. 

     

    sprintf("insert into table (name, content) values (\"%s\", \"%s\")", mysql_real_escape_string($_GET['name']), mysql_real_escape_string($_GET['content']));
    

     

     

  9. Ah right I see.  Thanks.  At the moment when I enter data the line breaks are not being preserved but this is because I am using mysql_real_escape.  So I should stop using this for this field and just used strip_tags?

  10. I'm trying to insert the contents of a textarea into a MySQL database but I am wondering what the best way is to preserve the users line breaks.  I know that you can use nl2br() to convert "\n" into "<br />" when the retrieve data from the database but I am looking at a way to insert these line breaks when I enter the data. 

     

    Thanks for any help. 

  11. I'm not sure if this is the right place for this but anyway.  I have a blog and all of the entries are stored in a database.  I then use the same page to display all of the entries.  So for example the URL for the first entry is "article.php?number=1" and the URL for the 6th entry is article.php?number=6". 

     

    Because each article uses the same page the title for this page is always "Article".  Is this bad for SEO?  Should I instead echo the name of the article into the title tag each time?

     

    Thanks for any help. 

  12. I have a form which has a textarea in it.  When the form is submitted the contents are submitted to a MySQL database and the contents or the textarea are stored in a text variable.  What is the best was to preserve line breaks in the textarea?  At the moment if the user enters to separate paragraphs into the textarea they will be merged into one.  Thanks for any help. 

  13. I have a form which lets the user put in the URL to their twitter account.  When the enter their URL I am trying to create a screen scraping script that scrapes that page to get basic information like their twitter name and number of tweets. 

     

    I'm not sure how I am going to do this, I don't think there is a twitter API for this so I may have to use something like cURL.  I was just wondering if anyone has done this and could give me any advice about the best method? 

     

    Thanks for any help

  14. I'm have a bit of trouble using jQuery bind. I have a function that I want to run on two different event types on 2 different elements. Basically I want to merge the two event types below into one. I have tried using bind but am not sure how to do it. Any help would be great.

     

    $(".validate").change(function() {

     

     

    $(".validate2").keyup(function() {

  15. On a website I'm building at the moment I want to have a search bar.  At the moment when I make the search I am using the MySQL "LIKE" to compare the user's search with records in a database.  However this is only a very basic search.  For example if the user is looking for articles on javascript but they mis spell it as "jaavscript" then using "LIKE" won't recognises these two as being similar. 

     

    Could anyone point me in the direction or some articles or tutorials about how to perform better search with PHP and MySQL? 

     

    Thanks for any help. 

  16. For example if I have this code on one page

     

    <a href=\"index.php?name=" . urlencode($array['name']) . "\">Text</a>

     

    When I then use this variable on another script.  For example

     

    $name = $_GET['name'];
    

     

    Should I use urldecode?

  17. I want to have a feature on a website I'm building where the user can select rows from a MySQL table based on it's age.  For example they could select a piece of content between 30-60 days old.  I'm going to do this using the following sequel

     

    "WHERE article_date BETWEEN 2010-12-01 AND 2010-11-01"

     

    However I'm not sure how to make this work.  If the date is 2010-12-12 what is the easiest way to subtract 30 days from this date?  Thanks for any help. 

  18. Thank you.  Although I don't think this will work.  I should explain better.  I want to get a random record based on "if category=film" rather than the whole dataset.  I'm not sure if there is an easy way to do it. 

  19. Is there anyway in MySQL you can select a random record in a table?  I normally do this by generating a random number first and then using that number to find a record but was wondering if there is an easier way.  Thanks for any help. 

×
×
  • 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.