MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 11th, 2004, 07:12 PM
cmnevada cmnevada is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 cmnevada User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql query problem

Let me explain you the whole set-up.
There are 2 tables which i need to work on for this query--- "proj_cont"
and "contact". proj_cont is a table with only 2 fields pid,cid. which is used
to associate projects with contacts. Now i want to delete all those
associations for which the notes field in contact table is blank(null).
so in effect it should delete all rows in proj_cont table whose cid =
contactid(notes=blank).
When i run this query it gives me the rows i need.
SELECT contact.contactid FROM contact WHERE contact.notes = " "

I am trying to run this query and it is giving me error 1064.
i am new to mysql so can anybody help me with this query or give me another query which will work.

$query= "SELECT contact.contactid FROM contact WHERE contact.notes = " " ";
$getvalue = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($getvalue);

for($i=0; $i < $num_rows; $i++)
{
$row = mysql_fetch_array($getvalue);
DELETE * FROM proj_cont WHERE cid = "$row[i]";

}

Reply With Quote
  #2  
Old April 11th, 2004, 08:04 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Note that a blank field is different to a NULL field. If you want to search for NULL fields, then your query needs to look like:
"WHERE foo IS NULL"
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old April 12th, 2004, 11:41 AM
cmnevada cmnevada is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 cmnevada User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I tried putting null, but Its still not working. Infact the echo statement gives me the number of rows correctly.
so i guess the problem is in for loop. can anybody help me with it.

$query= "SELECT contact.contactid FROM contact WHERE contact.notes = ' ' ";
$getvalue = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($getvalue);
echo "$num_rows<br>"

for($i=0; $i < $num_rows; $i++)
{
$row = mysql_fetch_array($getvalue);
DELETE FROM proj_cont WHERE cid = "$row[i]";

}

Reply With Quote
  #4  
Old April 12th, 2004, 07:37 PM
crudesys crudesys is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: California
Posts: 25 crudesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
is your delete statement in a variable? and then executed with mysql_query ?

Reply With Quote
  #5  
Old April 12th, 2004, 07:47 PM
crudesys crudesys is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: California
Posts: 25 crudesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by cmnevada

for($i=0; $i < $num_rows; $i++)
{
$row = mysql_fetch_array($getvalue);
DELETE FROM proj_cont WHERE cid = "$row[i]";

}

as i have understood about
$row = mysql_fetch_array($getvalue);

$row[0] ---> the value of the first field/column retrieved
$row[1] ---> the value of the second field/column retrieved
....
$row[i] ----> the value of the n field/column retrieved

since your query retrieved only 1 field, when it increments 'i' (from 0 to 1)
$row[1] does not exist.

you can try to use a while loop to do the fetching

while ($row = mysql_fetch_array($getvalue))
{
$sqlDelete = "DELETE FROM proj_cont WHERE cid = '$row[0]'";
$mysql_query($sqlDelete) or die (mysql_error());
}

i may be wrong, i may be right. make things work in the test first before doing it in the real thing. good luck

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql query problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway