igotregistered Posted December 3, 2012 Share Posted December 3, 2012 Hi, new guy gettting started with 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. 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 for any help. <?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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/ Share on other sites More sharing options...
gristoi Posted December 3, 2012 Share Posted December 3, 2012 select * from _mytable where title LIKE "%John Doe%" Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397144 Share on other sites More sharing options...
igotregistered Posted December 3, 2012 Author Share Posted December 3, 2012 (edited) Hi @gristoi. Thank you for the reply. So would this be correct? <?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 _mytable where title LIKE "%Bobby Robins%") 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>"; ?> Edited December 3, 2012 by igotregistered Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397173 Share on other sites More sharing options...
gristoi Posted December 3, 2012 Share Posted December 3, 2012 pretty much yeah, but if its only the title and link you need then do: SELECT title, link FROM ........ Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397179 Share on other sites More sharing options...
igotregistered Posted December 3, 2012 Author Share Posted December 3, 2012 It's not all of the verbiage in the title I only want the script to pull fights for only one name out of the title, specifically Bobby Robins. Then all of his fights will populate on his own page. Right now my table has 30 thousand various fights from thousands of different fighters. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397182 Share on other sites More sharing options...
Jessica Posted December 3, 2012 Share Posted December 3, 2012 $result = mysql_query("SELECT * FROM _mytable where title LIKE "%Bobby Robins%") Would give a syntax error. Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397192 Share on other sites More sharing options...
igotregistered Posted December 3, 2012 Author Share Posted December 3, 2012 Hi Jessica, yes it does give a syntax error. The script works perfectly but it pulls every single fight in the database into the page. I need to specify by name, this way only that person's fights propagate. Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397221 Share on other sites More sharing options...
Jessica Posted December 3, 2012 Share Posted December 3, 2012 For one thing you should be using a unique ID for each person, and using that instead of a name. Secondly, the error is with your string concatenation. Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397226 Share on other sites More sharing options...
igotregistered Posted December 3, 2012 Author Share Posted December 3, 2012 The video script I'm using is a custom script which was made by a developer for vbulletin. I paid for it. It's similar to a youtube script. Basically all I have is category, title, description, keywords. That's it. Thats why the names of the players are all mixed in with each other in the title matchups. They're all categorized by the league they play in. Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397229 Share on other sites More sharing options...
igotregistered Posted December 3, 2012 Author Share Posted December 3, 2012 It's working now Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397236 Share on other sites More sharing options...
Barand Posted December 3, 2012 Share Posted December 3, 2012 The "Mark Solved" button is at the top of the page Quote Link to comment https://forums.phpfreaks.com/topic/271528-get-data-from-1-table/#findComment-1397284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.