Difference between revisions of "MySQL PHP"
From KOP KB
(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 = ' | + | $host = 'hostname'; |
− | $user = ' | + | $user = 'username'; |
− | $pass = ' | + | $pass = 'pass'; |
− | $db = ' | + | $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(" | + | 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 | + | $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>"; | ||
− | // | + | |
+ | // 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[ | + | // 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();
?>