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!
<?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").
$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']);
}
Last edited by AbraCadaver on Wed Jul 07, 2010 2:44 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
<?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());
}
?>
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?
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.