So i have this script, instead of having the output as what is in th script below, i would like to have it in a table i have had a couple of gos at this and failed......MISERABLY!!!. Could anyone help me out with an example. ps there are more fields to add but once i have an example i coulf figure it out from that maybe?<i have left out the top of the script for obviuos reasons> Thanx everydude!!
---------------------------------------------------------------------------------------

echo("<li>Can't connect to $HOST as $USER");
echo("<li>mysql Error: ".mysql_error());
die;
}

// select database
if (!mysql_select_db($DATABASE,$conn)) {
echo("<li>We were unable to select database $DATABASE");
die;
}

// if everything successful create query
// this selects all rows where the type is the one you chose in the dropdown
// * means that it will select all columns, ie name and type as i said above
echo "<table>";
$sql_query = "SELECT * FROM base_data WHERE ParishName LIKE '$chooser'";

// get the data from the database
$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());

// output data
while ($details = mysql_fetch_array($result, MYSQL_ASSOC)) {
// print out the name
echo('Parish: '.$details['ParishName'].' - ');
// print out the type
echo('Owner Occupier Household: '.$details['OwnerOccupierHousehold'].'<br>');
}

// close mysql connection
mysql_close($conn);

}

?>

Recommended Answers

All 7 Replies

There is a "table" started already and I think it doesn't belong...

// if everything successful create query
// this selects all rows where the type is the one you chose in the dropdown
// * means that it will select all columns, ie name and type as i said above
echo "<table>"; //<----------------------------------DELETE!!!
$sql_query = "SELECT * FROM base_data WHERE ParishName LIKE '$chooser'";

Hope this helps:

<?

/*Single result per table*/
// output data
while ($details = mysql_fetch_array($result, MYSQL_ASSOC)) {
	//start table
	echo "<table>";
	
	//start row and column
	echo "<tr><td>";
		//print out name
		echo('Parish: '.$details['ParishName'].' - ');
	//end column and row
	echo "</td></tr>";
	
	//start row and column
	echo "<tr><td>";
		// print out the type
		echo('Owner Occupier Household: '.$details['OwnerOccupierHousehold'].'<br>');
	//end column and row
	echo "</td></tr>";
	
	//end table
	echo "</table>";
}

/************************************************************/

/*Multple results per table(each in a row)*/
	
//start table
echo "<table>";

// output data
while ($details = mysql_fetch_array($result, MYSQL_ASSOC)) {
	
	//start row and column
	echo "<tr><td>";
		//print out name
		echo('Parish: '.$details['ParishName'].' - ');
	//end column and start new column
	echo "</td><td>";
		// print out the type
		echo('Owner Occupier Household: '.$details['OwnerOccupierHousehold'].'<br>');
	//end column and row
	echo "</td></tr>";
}

//end table
echo "</table>";
?>

Parse error: syntax error, unexpected $end in /home/sites/miraclehosting.co.uk/public_html/scdc.php on line 189.......Is this normal? (only joking didnt want you to take offence there) the only thing on line 189 is the end </html> tag.any more suggestions

that error usually means that one of the } (curly brackets) is mismatched or missing... do you mind putting your entire code here or at http://www.rafb.net/paste/ ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="scdc.php" method="post" name="chooser">
  <label>Select Parish </label>     
  <select name="chooser" id="chooser">
    <option value="Abington Pigotts">Abington Pigotts</option>
    <option value="Arrington">Arrington</option>

    <option value="Barbraham">Barbraham</option>
    <option value="Balsam">Balsam</option>
    <option value="Bar Hill">Bar Hill</option>
    <option value="Barrington">Barrington</option>
    <option value="Barton">Barton</option>
    <option value="Bassinbourn-Cum-Kneesworth">Bassingbourn-Cum-Kneesworth</option>

    <option value="Bourne">Bourne</option>
    <option value="Boxorth">Boxworth</option>
    <option value="Caldecote">Caldecote</option>
    <option value="Carlton">Carlton</option>
    <option value="Castle Camps">Castle Camps</option>
    <option value="Caxton">Caxton</option>

    <option value="Comberton">Comberton</option>
    <option value="Conington">Conington</option>
    <option value="Coton">Coton</option>
    <option value="Cottenham">Cottenham</option>
    <option value="Croxton">Croxton</option>
    <option value="Croydon">Croydon</option>

    <option value="Dry Draton">Dry Draton</option>
    <option value="Duxford">Duxford</option>
    <option value="Elsworth">Elsworth</option>
    <option value="Eltisley">Eltisley</option>
    <option value="Fen Ditton">Fen Ditton</option>
    <option value="Fen Drayton">Fen Drayton</option>

    <option value="Fowlmere">Fowlmere</option>
    <option value="Foxton">Foxton</option>
    <option value="Fulbourn">Fulbourn</option>
    <option value="Gamlingay">Gamlingay</option>
    <option value="Girton">Girton</option>
    <option value="Grantchester">Grantchester</option>

    <option value="Graveley">Graveley</option>
    <option value="Great Abinton">Great Abington</option>
    <option value="Great Eversden">Great Eversden</option>
    <option value="Great Shelford">Great Shelford</option>
    <option value="Great Wilbraham">Great Wilbraham</option>
    <option value="Guilden Morden">Guilden Morden</option>

    <option value="Hardwick">Hardwick</option>
    <option value="Harlton">Harlton</option>
    <option value="Harston">Harston</option>
    <option value="Haslingfield">Haslingfield</option>
    <option value="Hatley">Hatley</option>
    <option value="Hauxton">Hauxton</option>

    <option value="Heydon">Heydon</option>
    <option value="Hildersham">Hildersham</option>
    <option value="Hinxton">Hinxton</option>
    <option value="Histon">Histon</option>
    <option value="Horningsea">Horningsea</option>
    <option value="Horseheath">Horseheath</option>

    <option value="Ickleton">Ickleton</option>
    <option value="Impington">Impington</option>
    <option value="Kingston">Kingston</option>
    <option value="Landbeach">Landbeach</option>
    <option value="Linton">Linton</option>
    <option value="Litlington">Litlington</option>

    <option value="Little Abington">Little Abington</option>
    <option value="Little Chishill">Little Chishill</option>
    <option value="Little Eversden">Little Eversden</option>
    <option value="Little Gransden">Little Gransden</option>
    <option value="Little Shelford">Little Shelford</option>
    <option value="Little Wilbraham &amp; Six Mile Bottom">Little Wilbraham &amp; Six Mile Bottom</option>

    <option value="Lolworth">Lolworth</option>
    <option value="Longstanton">Longstanton</option>
    <option value="Longstowe">Longstowe</option>
    <option value="Madingley">Madingley</option>
    <option value="Melbourne">Melbourne</option>
    <option value="Meldreth">Meldreth</option>

    <option value="Milton">Milton</option>
    <option value="Newton">Newton</option>
    <option value="Oakington">Oakington</option>
    <option value="Orwell">Orwell</option>
    <option value="Over">Over</option>
    <option value="Pampisford">Pampisford</option>

    <option value="Papwoerth Everard">Papworth Everard</option>
    <option value="Rampton">Rampton</option>
    <option value="Sawston">Sawston</option>
    <option value="Shepreth">Shepreth</option>
    <option value="Shingay-Cum-Wendy">Shingay-Cum-Wendy</option>
    <option value="Shudy Camps">Shudy Camps</option>

    <option value="Stapleford">Stapleford</option>
    <option value="Steeple Morden">Steeple Morden</option>
    <option value="Swavesey">Swavesey</option>
    <option value="Tadlow">Tadlow</option>
    <option value="Teversham">Teversham</option>
    <option value="Thriplow">Thriplow</option>

    <option value="Toft">Toft</option>
    <option value="Waterbeach">Waterbeach</option>
    <option value="Westwick">Westwick</option>
    <option value="West Wickham">West Wickham</option>
    <option value="West Wratting">West Wratting</option>
    <option value="Weston Colville">Weston Colville</option>

    <option value="Whaddon">Whaddon</option>
    <option value="Whittlesford">Whittlesford</option>
    <option value="Willingham">Willingham</option>
    <option value="Wimpole">Wimpole</option>
  </select>
  <input type="Submit" name="select" value="select"> 
</form>


<?php

// get variable after selecting something from the dropdown with name 'chooser'
$select = $_POST['select'];

// if something has been chosen
if (!empty($select)) {

// get the chosen value
$chooser = $_POST['chooser'];

// select the type from the database
// database connection details (change to whatever you need)
$HOST = 'localhost';
$DATABASE = '*****';
$USER = '*****';
$PASSWORD = '******';

// connect to database
if(!$conn=mysql_connect('localhost','*****','*****')) {
echo("<li>Can't connect to $HOST as $USER");
echo("<li>mysql Error: ".mysql_error());
die;
}

// select database
if (!mysql_select_db($DATABASE,$conn)) {
echo("<li>We were unable to select database $DATABASE");
die;
}

// if everything successful create query
// this selects all rows where the type is the one you chose in the dropdown
// * means that it will select all columns, ie name and type as i said above
$sql_query = "SELECT * FROM base_data WHERE ParishName LIKE '$chooser'";

// get the data from the database
$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());

/*Multple results per table(each in a row)*/
//start table
echo "<table>";
// output data
while ($details = mysql_fetch_array($result, MYSQL_ASSOC)) {
//start row and column
echo "<tr><td>";
//print out name
echo('Parish: '.$details['ParishName'].' - ');
//end column and start new column
echo "</td><td>";
// print out the type
echo('Owner Occupier Household: '.$details['OwnerOccupierHousehold'].'<br>');
//end column and row
echo "</td></tr>";
//end table
}
echo "</table>";
?>

There you go keep looking at cant find it cause myresearch told me the same thing about the curly brackets pehaps it comes with experience.

you need an extra curly bracket at the bottom because this if (!empty($select)) { is still open

So i have this script, instead of having the output as what is in th script below, i would like to have it in a table i have had a couple of gos at this and failed......MISERABLY!!!. Could anyone help me out with an example. ps there are more fields to add but once i have an example i coulf figure it out from that maybe?<i have left out the top of the script for obviuos reasons> Thanx everydude!!
---------------------------------------------------------------------------------------
echo("<li>Can't connect to $HOST as $USER");
echo("<li>mysql Error: ".mysql_error());
die;
}

// select database
if (!mysql_select_db($DATABASE,$conn)) {
echo("<li>We were unable to select database $DATABASE");
die;
}

// if everything successful create query
// this selects all rows where the type is the one you chose in the dropdown
// * means that it will select all columns, ie name and type as i said above
echo "<table>";
$sql_query = "SELECT * FROM base_data WHERE ParishName LIKE '$chooser'";

// get the data from the database
$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());

// output data
while ($details = mysql_fetch_array($result, MYSQL_ASSOC)) {
// print out the name
echo('Parish: '.$details.' - ');
// print out the type
echo('Owner Occupier Household: '.$details.'<br>');
}

// close mysql connection
mysql_close($conn);

}

?>

yes u can easily create table in php, I am explaing it below with some sort of codes...

<?php
...
some sort of codes here
...
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table> <!--table with 2 rows and 2 coloumns save this file with index.php-->
<?php
...
some sort of codes here
...
?>
<?php
{

    {
		echo("<li>Can't connect to $HOST as $USER");
		echo("<li>mysql Error: ".mysql_error());
		die;
    }

	// select database
	if (!mysql_select_db($DATABASE,$conn)) 
	   {
		  echo("<li>We were unable to select database $DATABASE");
		  die;
	   }
	
	// if everything successful create query
	// this selects all rows where the type is the one you chose in the dropdown
	// * means that it will select all columns, ie name and type as i said above
		echo "<table>";
		$sql_query = "SELECT * FROM base_data WHERE ParishName LIKE '$chooser'";
	
	// get the data from the database
		$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());
	
	// output data
	while ($details = mysql_fetch_array($result, MYSQL_ASSOC))
		 {
			// print out the name
			echo('Parish: '.$details['ParishName'].' - ');
			// print out the type
			echo('Owner Occupier Household: '.$details['OwnerOccupierHousehold'].'<br>');
		 }
	
	// close mysql connection
	mysql_close($conn);

}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.