Jump to content

How to look in a database for some info and echo that data


ChrisMartino

Recommended Posts

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"

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);

 

 

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;
}
}

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".

 

dasdsadadas.jpg

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");
?>

Archived

This topic is now archived and is closed to further replies.

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