Mysql Query

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
tomnoble
Forum Commoner
Posts: 28
Joined: Tue Jun 15, 2010 1:18 pm

Mysql Query

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Mysql Query

Post 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']);
}
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.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Mysql Query

Post 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());
}
?>
tomnoble
Forum Commoner
Posts: 28
Joined: Tue Jun 15, 2010 1:18 pm

Re: Mysql Query

Post 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
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Mysql Query

Post 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.
Post Reply