Hello,

Imagine that you are new to PHP, have just made a page you are proud of, and are ready to make a website out of it...

you spend 2 weeks learning Drupal, expecting to put your code in the middle of it...

then it hits you.

if you want make a content type with a PHP script, you have to learn to make PHP modules with Hook / Info / List / View / node insert/ node update / node Theme / Arrays / Validate / @param / @result / $url / watchdog / hook node / hook block / Switch / t(bla !bla)

Surely this is a good way to prevent aspiring web programmers from using Drupal. it's an evil learning curve!

i need 4 tables and 5 node types to run my website, but in drupal it cant be done without learning about 40 kinds of hooks... That's effing impossible doods! what am i supposed to do now? read the whole 350 page "make a module" book of advanced drupal coding, and then realise i still cant get my head round it on my own?

it's only 20 lines of PHP! come on how do i make a PHP content type!

Comments

ludo1960’s picture

see your 20 lines of code? hmm have you enabled the PHP filter in admin section?

dutchound’s picture

Here is the code:



if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

// sending query
$result = mysql_query("SELECT points,ROUND(SUM(pts),1),Count(pts) FROM main GROUP BY points ORDER BY SUM(pts) DESC");
if (!$result) {
die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h4>-={$table}=-</h4>";
echo "<table border='0'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td><h4>{$field->name}</h4></td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";

echo "</tr>\n";
}
mysql_free_result($result);


ludo1960’s picture

Does the code execute?

The drupal way is here http://api.drupal.org/api/group/database/6

yelvington’s picture

Actually, the Drupal way is to figure out what the business case is, then look at the already existing toolkit, and discover (in 99 percent of the cases) that the work is already done for you and you don't have to code anything at all! This is the biggest learning curve that newbies have with Drupal: Unlearning what you think you know. PHP should be your last resort, not the first tool you reach for.

dutchound’s picture

yes the code works nicely, it's a table with a form that can imput comma seperated values.

I will try with View.

I want to really tailor the website.

It seems joomla has 2-3 modules for developing PHP modules, for google ads, flash, amazon code snippets, i am going to try them out now! but i dunno why they wouldnt exist in Drupal ?:)