ChrisMartino Posted September 1, 2009 Share Posted September 1, 2009 Hey there im looking for some help, i need to make a code so it looks in the database for some data ( a line of text like this "home/servers/$username" and if that line dosent exit it echos "You do not have any game servers click here to buy one" Link to comment https://forums.phpfreaks.com/topic/172717-how-to-look-in-a-database-for-some-info-and-echo-that-data/ Share on other sites More sharing options...
LordLanky Posted September 1, 2009 Share Posted September 1, 2009 Can you say more regarding the layout of the tables? what column is the data in? For example, in table MYTABLE containing a column SEARCHME, i would: mysql_query ("SELECT * FROM MYTABLE WHERE SEARCHME LIKE '%home/servers/$username%'", $db); Link to comment https://forums.phpfreaks.com/topic/172717-how-to-look-in-a-database-for-some-info-and-echo-that-data/#findComment-910408 Share on other sites More sharing options...
LordLanky Posted September 1, 2009 Share Posted September 1, 2009 And... sorry.... to echo that data, here's an example: $strSearch = "Some Text to Search"; $sqlStr = "SELECT * FROM usrtable WHERE usrcolumn LIKE '%".$strSearch."%'"; $sqlRes = mysql_query ($sqlStr, $db); #Count the number of results $intRes = mysql_count_results ($sqlRes); #If there are results if ($intRes) { #Loop through the result set for ($i=0; $i<$intRes; $i++) { #Echo all the data $strToEcho = mysql_result ($sqlRes, $i, "usrcolumn"); echo $strToEcho; } } Link to comment https://forums.phpfreaks.com/topic/172717-how-to-look-in-a-database-for-some-info-and-echo-that-data/#findComment-910413 Share on other sites More sharing options...
ChrisMartino Posted September 1, 2009 Author Share Posted September 1, 2009 how would i echo "you currently dont have any game servers on you're account" if it carnt find the data? Link to comment https://forums.phpfreaks.com/topic/172717-how-to-look-in-a-database-for-some-info-and-echo-that-data/#findComment-910495 Share on other sites More sharing options...
ChrisMartino Posted September 1, 2009 Author Share Posted September 1, 2009 heres a pic of the table i would like to store the data in is this the right type of colum to store a line of text and echo it?, becasuse the basic idea is every time someone buys a server it saves were there server files are in the database and you echo that data and if they havent got that line in the database (means they havent bought a server) it echos "You currenley have no game servers head over to packages to buy one". Link to comment https://forums.phpfreaks.com/topic/172717-how-to-look-in-a-database-for-some-info-and-echo-that-data/#findComment-910500 Share on other sites More sharing options...
squiblo Posted September 1, 2009 Share Posted September 1, 2009 is this something that you are looking for? <?php $connect = mysql_connect("localhost","username","password") or die ("Couldn't connect"); mysql_select_db("database name") or die ("Couldn't find db"); $query = mysql_query("SELECT * FROM databasename WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbhasserver = $row['hassserver']; } if ($dbhasserver = "") { echo "You currenley have no game servers head over to packages to buy one."; } else echo $hassserver; } else die("user does not exist"); ?> Link to comment https://forums.phpfreaks.com/topic/172717-how-to-look-in-a-database-for-some-info-and-echo-that-data/#findComment-910519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.