Difference between revisions of "MySQL PHP"

From KOP KB
Jump to: navigation, search
(Created page with "<syntaxhighlight lang="php"> <? //connection information $host = 'mysqlv108'; $user = 'chsalezip'; $pass = 'Ch54l351nC'; $db = 'chsalezip'; $conn = mysql...")
 
Line 3: Line 3:
 
//connection information
 
//connection information
  
  $host = 'mysqlv108';
+
  $host = 'hostname';
  
     $user = 'chsalezip';
+
     $user = 'username';
  
     $pass = 'Ch54l351nC';
+
     $pass = 'pass';
  
     $db = 'chsalezip';
+
     $db = 'dbname';
  
 
     $conn = mysql_connect($host, $user, $pass);
 
     $conn = mysql_connect($host, $user, $pass);
 
//connection needs db name below
 
//connection needs db name below
mysql_select_db("chsalezip", $conn);
+
mysql_select_db("dbname", $conn);
 +
//This is just if your using information from a search form
 
$search = $_POST["tZip"];
 
$search = $_POST["tZip"];
 
// after the from is whatever table you are attempting to pull data from
 
// after the from is whatever table you are attempting to pull data from
$connstring = "SELECT * FROM distributors WHERE searchZip LIKE '$search' " ;
+
$connstring = "SELECT * FROM tablename WHERE columnname LIKE '$search' " ;
 
$result = mysql_query($connstring);
 
$result = mysql_query($connstring);
 
?>
 
?>
Line 23: Line 24:
 
<?
 
<?
 
echo "<h1>Stores Near You:</h1>";
 
echo "<h1>Stores Near You:</h1>";
// after each bold is a column name so its appears organized
+
 
 +
// Checks to make sure it actually brings a result, so to whether show them or to say out of luck or similar issue
 
if(mysql_num_rows($result) == 0) {
 
if(mysql_num_rows($result) == 0) {
 
     echo "Sorry there appears to be no stores in your immediate area.";
 
     echo "Sorry there appears to be no stores in your immediate area.";
Line 34: Line 36:
  
 
     // something else to display the content
 
     // something else to display the content
echo "<h4>$nt[sName]</h4>$nt[sAdd]<br />$nt[sCity]<br />$nt[sZip], $nt[sState]<br />$nt[sPhone]";
+
    // this displays the content how you want it depending on the theme of what their doing will depend on what you do here for html
 +
echo "<h4>$nt[cnam1]</h4>$nt[cnam2]<br />$nt[cnam3]<br />$nt[cnam4], $nt[cnam5]<br />$nt[cnam6]";
 
   }
 
   }
 
echo "<br />";
 
echo "<br />";

Revision as of 22:28, 4 August 2014

<?
//connection information

 $host = 'hostname';

    $user = 'username';

    $pass = 'pass';

    $db = 'dbname';

    $conn = mysql_connect($host, $user, $pass);
	//connection needs db name below
mysql_select_db("dbname", $conn);
//This is just if your using information from a search form
$search = $_POST["tZip"];
// after the from is whatever table you are attempting to pull data from
$connstring = "SELECT * FROM tablename WHERE columnname LIKE '$search' " ;
$result = mysql_query($connstring);
?>

 	 	
<?
echo "<h1>Stores Near You:</h1>";

// Checks to make sure it actually brings a result, so to whether show them or to say out of luck or similar issue
if(mysql_num_rows($result) == 0) {
     echo "Sorry there appears to be no stores in your immediate area.";
   }
else{
while($nt=mysql_fetch_array($result)){
echo "<br />";
echo "<br />";
// for each $nt has a correlated column name to display

     // something else to display the content
     // this displays the content how you want it depending on the theme of what their doing will depend on what you do here for html
	 echo "<h4>$nt[cnam1]</h4>$nt[cnam2]<br />$nt[cnam3]<br />$nt[cnam4], $nt[cnam5]<br />$nt[cnam6]";
   }
echo "<br />";
echo "<br />";
}

echo mysql_error();
mysql_close();
?>