Jump to content

Would Appreciate help! (mysql query)


Jonathan Harvey

Recommended Posts

Hey All,I have a query that needs to be executed. The problem is simple, it doesn't work. I've tried all variations of the code, and for the life of me I can't get it to work. I've been workin on this for three hours and haven't figured it out.Here is the Code:

$con = mysql_connect("localhost","[myusernamewouldgohere]","[mypasswouldgohere");if (!$con)  {  die('Could not connect: ' . mysql_error());  }    mysql_select_db("teambuz_drupal", $con);      if(isset($_GET['Product_Name']) && isset($_GET['Low_Price']) && isset($_GET['High_Price']))   {   	  	$results = mysql_query("SELECT * FROM `node` WHERE `title`='Home'");  	$output = mysql_fetch_array($results);  	  	while ($row = mysql_fetch_array($results)) {   print $row['nid'];	 	  }  	print 'test';  	print $_GET[Product_Name];  	  	  	  }  elseif(isset($_GET['Product_Name'])){    print 'yes';    }  else  {  	  	print 'You need to debug';  }  

The code is running on a page in drupal. The code needs to connect to the database used by drupal, and then needs to access the table "node". Inside the table "node", there is the field "title", and I need to be able to extract the values from this.In the code above, I've used a static value, this is just for testing. Once figured out, I would use a $_GET value.I believe drupal indexes the tables in it's database...But I'm a noob, so I couldn't tell you yes or no, and I also don't know how to work with indexed tables.Thanks.

Link to comment
Share on other sites

can you say What exactly is not working? any errors?

Link to comment
Share on other sites

can you say What exactly is not working? any errors?
Thanks for the reply; There are no errors thrown....There is just no output. I've literally been sitting here testing different variations for hours, about to pull my hair out, I just can't get it to work.In case you need a little ellaboration, the code (or at least the part I'm having trouble with), is supposed to go into the node table, select the rows where title='Home', then return the array of results.Then for each result, print out the node id ('nid') for that result.
Link to comment
Share on other sites

I found out the answer to my question, and thought I would post it for all the php noobs like me (the advanced user probably already knew this)The problem wasn't with my query, it was with my php syntax. There wasn't an error so I didn't suspect this at first, but when I took the while loop out of the if statement, the output worked properly.The new code is this:

$con = mysql_connect("localhost","[myusername]","[mypassword]");if (!$con)  {  die('Could not connect: ' . mysql_error());  }    mysql_select_db("teambuz_drupal", $con);      if(isset($_GET['Product_Name']) && isset($_GET['Low_Price']) && isset($_GET['High_Price']))   {   	  	$results = mysql_query("SELECT * FROM node WHERE title='Home'");    	print 'test';  	print $_GET[Product_Name];  	  	   }  	    	    elseif(isset($_GET['Product_Name'])){    print 'yes';    }  else  {  	  	print 'You need to debug';  }  while ($row = mysql_fetch_array($results)) {   print $row['nid'];	 	  }

and it works like a charm.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...