I have a small problem that I cannot seem to figure out. I am trying to retrieve data from my database and display it in the browser. I get no errors that I cannot connect to my database. And no errors from the insert query or mysql? Check this small bit of code out. Any ideas? It might not be my code?
<?php # fileimport.php
include ('mysql_connect.php'); //database connection
//Load file into variable for tab sorting.
$listingres = file('Listings-Residential.txt');
//Use explode function to put tabbed array into the variable $string.
//explode can only use strings, the foreach statement will process
//each element in the array.
foreach($listingres as $record) // $listingres is the array you got from file()
{ $record=trim($record); // Otherwise the newline character will still be on the end of the line
$fields = explode("\t", $record); // Do stuff with the $fields array.
// Insert all of the 125 different variables into database
$query = "INSERT INTO residential (mls, class, type, area, asking_price,
city, state, zip, status, sale_rent, bedrooms, fullbath, halfbath, garage,
gar_type, yr_built, sqft, counties, number_acres, agent_id, agent_name,
agent_phone, listingoffice1_id, listingoffice1_name, listingoffice1_phone,
listingagent2_id, listingagent2_name, listingagent2_phone, listingoffice2_id,
listingoffice2_name, listingoffice2_phone, comp_sa, comp_ba, year_built,
sqft_total, sqft_howmeas, lot_size, township, listing_date, expiration_date,
legal_1, legal_2, parcel, bath_upper, bath_main, bath_lower, rooms_lrsize,
rooms_lrlevel, rooms_drsize, rooms_drlevel, rooms_frsize, rooms_frlevel,
rooms_kitsize, rooms_kitlevel, beds_1size, beds_1level, beds_2size,
beds_2level, beds_3size, beds_3level, beds_4size, beds_4level, rooms_utilsize,
rooms_utillvl, rooms_description, rooms_othsize, rooms_othlvl,
other_desc, other_size, other_level, other_desc2, other_size2, other_level2,
terms, fh_flood, fh_heatbud, zoning, lock_box, subdivision, directions_1,
directions_2, original_price, assumable, accelerate, qualify, equity_amount,
assumption_payment_amount)
VALUES ($fields[1],$fields[2],$fields[3],$fields[4],$fields[5], $fields[6],
$fields[7],$fields[8],$fields[9],$fields[10],$fields[11],$fields[12],
$fields[13],$fields[14],$fields[15],$fields[16],$fields[17],$fields[18],
$fields[19],$fields[20],$fields[21],$fields[22],$fields[23],$fields[24],
$fields[26],$fields[27],$fields[28],$fields[29],$fields[30],$fields[31],
$fields[32],$fields[33],$fields[34],$fields[35],$fields[36],$fields[37],
$fields[38],$fields[39],$fields[40],$fields[41],$fields[42],$fields[43],
$fields[44],$fields[45],$fields[46],$fields[47],$fields[48],$fields[49],
$fields[50],$fields[51],$fields[52],$fields[53],$fields[54],$fields[55],
$fields[56],$fields[57],$fields[58],$fields[59],$fields[60],$fields[61],
$fields[62],$fields[63],$fields[64],$fields[65],$fields[66],$fields[67],
$fields[68],$fields[69],$fields[70],$fields[71],$fields[72],$fields[73],
$fields[74],$fields[75],$fields[76],$fields[77],$fields[78],$fields[79],
$fields[80],$fields[81],$fields[82],$fields[83],$fields[84],$fields[85],
$fields[86],$fields[87],$fields[88],$fields[89],$fields[90],$fields[91])";
//print $query . "<br>"; //Print out the values of the query
$result = mysql_query($query); //Run the query
//print_r($fields); //Print out readable data about string
//echo '<br><br><br>';
}
$query1 = mysql_query("SELECT * FROM residential"); // test query
while($row = mysql_fetch_array($query1)) { // put results into an array
echo "Name: " . $row["mls"] . "<br>"; // field name is mls
echo "Email: " . $row["city"] . "<br>"; // field name is city
}
?>
<?php #Connect to idx database, residential table
//Set the database access information as constants
define ('DB_USER','root');
define ('DB_PASSWORD','assmonkey');
define ('DB_HOST','localhost');
define ('DB_NAME','idx');
//Make the connection and then select the database.
mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die (mysql_error() );
mysql_select_db(DB_NAME) OR die (mysql_error() );
?>