Advanced Search

Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: PHP Retrieve data from DB Table

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

    Default PHP Retrieve data from DB Table

    I'd like to retrieve player results from a table in my vbulletin database table called _vbullthread. The results would ultimately print to the players own page.

    I'm using this script (below) to retrieve the info but the script breaks after I try to run it. There is only one field in the table which has the info the script needs. It is the "Title" field. All values in said field within the database are entered like this....... Bob Smith vs John Doe May 2, 2001 Sports team vs Sports team

    PHP Code:
        <html>
    <head>

    <title>Player Info</title>

    </head>
    <body>

    <?php

    //connect to the database
    mysql_connect ("10.x.x.x","username","pw") or die ('Cannot connect to MySQL: ' mysql_error());
    mysql_select_db ("database_name") or die ('Cannot connect to the database: ' mysql_error());

    //query
    $query mysql_query("select name_Bob, name_smith from _vbullthread") or die ('Query is invalid: ' mysql_error());

    //write the results

    while ($row mysql_fetch_array($query)) {
    echo 
    $row['name_first'] . " " $row['name_last'] . "
    "
    ;
        
    // close the loop
    }

    ?>

    </body>
    </html>
    This script isn't working. I keep getting this message:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/x/o/v/owner/html/bob_smith.php(47) : eval()'d code on line 21

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

    Default

    There is no eval()'d code in the code you posted.


    Beyond that, there are several issues that you would do well to address:
    • # If at all possible, you should avoid using the mysql_* functions. #
      ext/mysql is outdated and scheduled for deprecation.
      It is no longer recommended for new projects, and existing code should be updated to avoid performance and security problems.

      Using ext/mysqli or the PDO class is recommended.
      Read more about choosing an API on php.net.
      .
    • I don't know if that's your real username/password or not, but if it is, you should obfuscate it.
      .
    • In your question, you say you want to select the Title column from the database.
    • In your code, you attempt to select the name_Bob and name_smith columns.
    • Subsequently, you attempt to use the name_first and name_last columns (which, obviously, would not exist) from your query result.


    Could you please clarify, specifically, what you want to accomplish? Make sure you post the code that is relevant to your problem.

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

    Default

    Hi Traq, I sent you my website address in PM.

    What I want to do is....

    When I add specific players video's to my video portal. I would like to make custom pages with the players statistics, (outside of the video portal) and have only their video's automatically retrieve from the same table the videos live on.

    I would like the data parsed from the table to be retrieved by player name.

    Thank you for your help.

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

    Default

    Could you please post the relevant part of bob_smith.php that uses the eval() function?

    As far as the DB goes, does this 'player_stats' table exist already? Or do you need to create it? What is the structure of the video table?

    Quote Originally Posted by igotregistered
    Hi Traq, I sent you my website address in PM.
    Is there some reason you don't want the link posted here? You might benefit from other users being able to see it, and offer advice.

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

    Default

    ok, it's nhlfightclub.com/hockeyfights

    It's setup like a youtube clone. The table the video data is in, is "_vbullthread". There's only one field which has the data. It's the "title" field.

    I'm not sure what you mean by what part of bob_smith do I want to use? I'm sorry I'm not familiar with writing scripts, I'm only familiar with designing sites.

    I want to build several pages, each dedicated to 1 specific player. As fights are added to the video portal through this page nhlfightclub.com/vbtube_add.php?do=add&pt=0

    I would like the specific player I add video's for to have their videos automatically populate on their custom profile page I make. Like this one
    nhlfightclub.com/dave_brown.php#dave1

    I hope that's more descript, I'm sorry if I wasn't providing enough info. I truly appreciate the help.

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

    Default

    Quote Originally Posted by igotregistered View Post
    I'm not sure what you mean by what part of bob_smith do I want to use? I'm sorry I'm not familiar with writing scripts, I'm only familiar with designing sites.
    I was referring to your script where the error was encountered:
    Quote Originally Posted by igotregistered
    Code:
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/x/o/v/owner/html/bob_smith.php(47) : eval()'d code on line 21
    As far as what you want to build, I understand your goal. What we would need to know is how everything is currently arranged, and what info we need to have in order to accomplish your goal.

    For example, if all of the info is stored together in one field in the database, there is very little hope for being able to use/search it. It's simply not useful stored like this:
    Code:
    table
    | Title                                                        |
    +--------------------------------------------------------------+
    | Bob Smith vs John Doe May 2, 2001 Sports team vs Sports team |
    It would need to be stored in an organized way, more like:
    Code:
    table
    | player1   | player2  | team1   | team2     | date       |
    +-----------+----------+---------+-----------+------------+
    | Bob Smith | John Doe | My Team | Your Team | 2001-05-01 |
    There are a lot of other things to consider - it's not impossibly complex, but there are many things involved. You need to do a lot of planning so you know how everything will work together. If, as you said above, you're not very familiar with programming, you would definitely need to learn before you attempted something like this.

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

    Default

    Hi Traq, thank you for your explanation. Yes in fact the data is stored exactly as your reference

    Code:
    table
    | Title                                                        |
    +--------------------------------------------------------------+
    | Bob Smith vs John Doe May 2, 2001 Sports team vs Sports team |
    I'm not actually looking to be as detailed as your second reference. All I want is for whoever I make a customized page for, ie. "Bob Smith". Just for his fights to populate in certain order. Just as long as they populate on his custom page. every time one of his fights are added in the video portal. The video portal is a script I bought, and it's ioncubed. So there's no way for me to alter how data is entered when a new video is added.

    Thank you

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

    Default

    Quote Originally Posted by igotregistered View Post
    not actually looking to be as detailed as your second reference. All I want is for whoever I make a customized page for, ie. "Bob Smith". Just for his fights to populate in certain order. Just as long as they populate on his custom page...
    It's not a matter of being "detailed" or having "fancy" features: properly organizing the data (as in my second example) makes it possible to reliably search for & find the correct records:
    Code:
    SELECT whatever FROM the_table WHERE the_field = 'Bob Smith'
    However, if all the data is lumped together in one field, you can't do that. You'd have to do
    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).

    Quote Originally Posted by igotregistered View Post
    ...Yes in fact the data is stored exactly as your reference...
    What does the rest of the table look like? How are the videos actually stored/found? You might be able to create a work-around (or parse and reorganize the data into something usable), but that would be less reliable (maybe not possible at all).

    Setting aside the "portal script," you need to know both a) what information you need, as well as b) what information is available to you, before you can start this project. Then, you can start working out how to approach your goal. Right now, you have nowhere to start from. You're in for a big learning experience.


    **********
    p.s.
    Quote Originally Posted by igotregistered View Post
    The video portal is a script I bought, and it's ioncubed.
    My sincere advice is to stay away from scripts that are "encrypted." Transparency is a sign of a good program. The more time an author spends on obfuscation, the less time they're spending on making the script good. (The simple fact that the script stores its data in one big lump in the DB makes me question its quality.) Obfuscation also adds another layer of complexity, is another source of bugs or instability, slows program execution down, and just generally looks "shady." Don't fool yourself: they are not trying to "protect their hard work." They are trying to lock you into returning to them (and paying again!) every time you want something changed or need something fixed.

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

    Default

    Hmmm, some interesting info there traq. Maybe I shouldn't venture off into using a script then.

    So it appears my only option is to manually code each players video, on their own page? I was hoping I could automate it someway so that I didn't have to manually add each fight every time they have one. If you have any other suggestions to some how automate the process, I'm willing to try.

    Thank you

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

    Default

    Well, I'm certainly not trying to "scare you away" from the idea - I was sincere in saying that it would be a learning experience (A Good Thing), and that I'd be happy to help you along the way. I'm just trying to help you understand that it's more complex than it might appear, and that you may need to do more preparatory work than you imagined (including a fair amount of "basics" with PHP and MySQL).

    So far, we need more info about how the videos, and the information about them, are stored. And your original question (about the error message) has gotten sidetracked. Let me know what you'd like to do!

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
  •