Can someone PLZ help me with myscript?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gpittingale
Forum Newbie
Posts: 12
Joined: Fri Jan 23, 2009 5:58 am

Can someone PLZ help me with myscript?

Post by gpittingale »

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

}

?>
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Can someone PLZ help me with myscript?

Post by papa »

How would you like the table to look like?

It's pretty basic HTML which I recommend you to learn for future projects. :)
gpittingale
Forum Newbie
Posts: 12
Joined: Fri Jan 23, 2009 5:58 am

Re: Can someone PLZ help me with myscript?

Post by gpittingale »

Well to be fair i am very good with html ,its php i am new to i did try creating a table from html and calling the arrays(?) from inside it but i got a error message back.
But i would like the table to look like this:
Parish Overview
</td>Number of homes<td> <td>% of total in parish </td> <td>Overall CO2 emissions per annum 2007/08</td>
Owner 1,556 87.76% 37,932
Social 89 5.02% 2,170
Private 128 7.22% 3,120

Total in parish 1773 43,222

By % By Number
Pre 1945 21.33% 378
1945-64 31.33% 555
1965 onwards 47.37% 840
1,774
Number of energy champions 7

Person data
Number of persons in Parish 4,237 Number of school age children 607
Number of working persons in parish 2,484

Baseline Position
Government target 4 par
Bar Hill 10 Today's level
Current situation 6 over par
Tonnes per person 10.20 tonnes
----------------------------------------------------------------------------------------------------------------------
well i hope that you can get the general jist if its any help in answering the post i can write html tables if you can tell me simple way to intergate it with php
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Can someone PLZ help me with myscript?

Post by papa »

Code: Select all

<?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
 
$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());
?>
 
<table border=1>
<tr> 
<th>ParishName</th> <th>OwnerOccupierHousehold</th>
</tr>
<?php
 
// output data
while ($details = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr>';
// print out the name
echo '<td>'.$details['ParishName'].'</td>';
// print out the type
echo '<td>'.$details['OwnerOccupierHousehold'].'</td>';
echo '</tr>';
}
 
// close mysql connection
mysql_close($conn);
}
?>
</table>
To help you get on track hopefully
gpittingale
Forum Newbie
Posts: 12
Joined: Fri Jan 23, 2009 5:58 am

Re: Can someone PLZ help me with myscript?

Post by gpittingale »

Dude you area legend!! cheers bubba.
Post Reply