Advanced Search

Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: PHP Retrieve data from DB Table

  1. #21
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Ok, I've been researching and I found a script which works....However, it's pulling every single record. I want the script to parse the "title" column and only retrieve the records of player names.

    Example

    The column "title" in the table has "Bob Smith vs John Doe Apr 1, 2012 hockey team vs hockey team". I want only records which have the name "John Doe" in it. I don't want, any records besides John Doe's.

    Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("10.x.xx.xx", "un", "pw") or die(mysql_error());
    mysql_select_db("mydbname") or die(mysql_error());
    
    // Get all the data from the "_mytables" table
    $result = mysql_query("SELECT * FROM _mytables") 
    or die(mysql_error());  
    
    
    echo "<table border='1'>";
    echo "<tr> <th>Fight Matchup</th> <th>Fight Video</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['title'];
    	echo "</td><td>"; 
    	echo $row['link'];
    	echo "</td></tr>"; 
    } 
    
    echo "</table>";
    ?>
    Thank you for any help. It's greatly appreciated.

  2. #22
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Code:
    SELECT `title` FROM `_mytables`
    Sorry for the lack of response earlier; I missed your last post. I'm glad you found something that works!
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  3. #23
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Hi traq, while I am able to find all data in the "title". I only want to find. I only want my query to find a single name in the title, (not the whole title)

    So if this is the title : "Bob Smith vs John Doe Apr 1, 2012 hockey team vs hockey team"

    I only want to find any records in the table related to "John Doe". Nothing else. HOpe that makes sense.

    Thank you

  4. #24
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    You can add LIKE '%John Doe%' to your search query. (Use Google to find out more information.)
    Note: different servers implement caseless or case-sensitive searching with LIKE. So be aware of that if it matters to you. My impression is that many/most servers are case-insensitive, so it won't matter. But it's an option to have it be case-sensitive.

    What you're asking isn't anything particularly obscure in PHP/MySQL, but it does require understanding the basics. You should be able to find tutorials for these things.

    From what I can see in this thread, it's time for you to invest in learning these languages so that you can do it yourself. It's far from impossible, although it might take you some time.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #25
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Hi djr33. All I want to do is have my page automatically update with the fights from one player. I've been trying to figure this out for weeks.

  6. #26
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    That's sort of like saying that you just want to fly a plane from New York to Los Angeles one time, so you don't want to take flying lessons. Alternatively you can ask someone to fly the plane for you.

    Anyway, I really am trying to be helpful here. You can use the LIKE keyword as needed. Any MySQL page with "LIKE" on it will have clear examples. Something like this:

    Code:
    SELECT `title` FROM `_mytables` WHERE `title` LIKE '%John Doe%'
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #27
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    This sounds very much like the same question we were discussing earlier:
    Quote Originally Posted by traq View Post
    if all the data is lumped together in one field, you can't do that...
    Code:
    SELECT whatever FROM the_table 
    WHERE the_field = 'Bob Smith'    #maybe just the name?
    OR the_field LIKE 'Bob Smith%'   #maybe the name at the beginning?
    OR the_field LIKE '%Bob Smith'   #maybe the name at the end?
    OR the_field LIKE '%Bob Smith%'  #maybe the name in the middle?
    ...and even then, there might be conditions where the search would still fail (or return bad results).
    Did you try a query like this (without the comments)?
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  8. #28
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    It seems like I've upset you guys. I'm sorry. I really only wanted to do one query for my website. I am a designer, unfortunately I know nothing about the database end. I would love to learn it, but it's enough trying to keep up with design. I apologize if I offended anybody, it wasn't meant to be such. All I wanted to do was make custom pages for these players without having to code each fight one by one. Now its working. Thank you all for your help. I really appreciate it.

  9. #29
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    You haven't really upset us, but it's pretty clear that you need to learn how to use databases-- and that's not a bad thing. I'm glad it's working. Maybe this is really the only time you'll ever need to use MySQL. But I doubt it. This forum is designed to point people in the right directions rather than write code for you.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #30
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Absolutely, no problem. I'm not offended or upset either.

    We're here because we like helping people with these kinds of problems. It's not an intrusion.
    Really, it's only frustrating when someone expects us to provide a complete solution (possibly on a deadline) while requiring no effort from them.

    (To everyone reading this thread, if that last sentence sounds like you, take heed! You're not looking for help, you're looking to HIRE!)

    If you put forth the effort - even if it's just the effort to understand the answers you're given - we're happy to help. You're learning something, and that is our goal. Don't be apologetic. As Daniel says, needing to learn something is Not a Bad Thing.

    -------------------
    Having said that, I would sincerely encourage you to learn about this sort of stuff. PHP and MySQL are ubiquitous on the internet; knowing the basics can be nothing but an advantage. If you really are in a position where you can't learn [for now], you would do well to find a good back-end developer that you can build a relationship with and go to for one-off tasks like this.
    Last edited by traq; 12-04-2012 at 12:59 AM.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

Similar Threads

  1. Replies: 0
    Last Post: 10-21-2011, 06:41 PM
  2. retrieve the data from sql to textbox
    By kiranbvsn in forum PHP
    Replies: 0
    Last Post: 02-20-2010, 05:53 AM
  3. Content Slider & retrieve data from mysql
    By ajloun in forum MySQL and other databases
    Replies: 1
    Last Post: 02-15-2010, 11:04 PM
  4. Replies: 4
    Last Post: 03-04-2009, 02:36 PM
  5. Replies: 21
    Last Post: 08-30-2007, 08:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •