Page 1 of 1
Mysql Query
Posted: Wed Jul 07, 2010 2:36 pm
by tomnoble
Hi all,
I know Im probably being thick here but there is something wrong with my code:
Code: Select all
<?php
mysql_connect("localhost", "dbuser", "dbpass") or die("Connection Failed");
mysql_select_db("db")or die("Connection Failed");
Echo "test";
$result=mysql_query("SELECT * FROM drupal_node WHERE type = 'product'");
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array( $result )
Echo $row['nid'];
?>
I need to look in the table drupal_node, in the column type. Where the type = "product" I need to return the value "nid" from the "nid" column associated with that record.
For every "nid" I get back, I need to run Delete_Node("nid").
Kind Regards
Tom
Re: Mysql Query
Posted: Wed Jul 07, 2010 2:44 pm
by AbraCadaver
Code: Select all
$result = mysql_query("SELECT nid FROM drupal_node WHERE type = 'product'"); //just get nid not *
//$row = mysql_fetch_array($result); //this doesn't belong
while($row = mysql_fetch_array( $result )) {
Delete_Node($row['nid']);
}
Re: Mysql Query
Posted: Wed Jul 07, 2010 2:44 pm
by Jade
Is delete node a function or do you just want to delete that nid from the database?
Code: Select all
<?php
mysql_connect("localhost", "dbuser", "dbpass") or die("Connection Failed");
mysql_select_db("db")or die("Connection Failed");
Echo "test";
$result=mysql_query("SELECT * FROM drupal_node WHERE type = 'product'");
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array( $result )
{
//if its a function uncomment the line below
//delete_node($row['nid']);
//if you want to delete that nid from the database uncomment the line below
//mysql_query("DELETE FROM drupal_node WHERE type='product' and nid='" . $row['nid'] . "'") or die (mysql_error());
}
?>
Re: Mysql Query
Posted: Wed Jul 07, 2010 2:48 pm
by tomnoble
Delete node is a pre written function yes. Im wondering, is there a way I can put a hyperlink on a normal HTML form, that when pressed, runs PHP code at the top of that page. As I dont really want to link to another page if I can help it as it will mean running loads of includes.
For example, if I have a a hyperlink called "click here" and I want it to run a function on that page called "test_function", what would I have to do?
Kind Regards
Tom
Re: Mysql Query
Posted: Thu Jul 08, 2010 9:47 am
by Jade
If you don't want to reload the page you'll have to use AJAX. Otherwise the only other way is to have the hyperlink open a popup window which runs your PHP script and then closes when it's done running but that will also require some Javascript.