By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 1,922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

Error in mysql_fetch_assoc()

P: 2
I am trying to get the following code to work, and I am having some problems:

The code goes for actually 110 lines, but I have dismissed what is not needed.
The connection and all that works for another table with the database, and what is used to fetch the information is used elsewhere in the script. Its only when I add row "82" (number 16 here) it produces the error. It will not extract any of the information, and it wont update any of the information, because the primary key (the date) that is extracted from the fetch_assoc on line 82 is used elsewhere to update the sales number for that date.

It returns "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\setlastpurchase.php on line 82" when I try and run the script. The script is to take a date that is within a mysql table and added one to the sales for that date, because that information will be used for marketing purposes. I am trying to get it to extract the number of sales for the date of the "call" or ticket. It takes the total number of sales, and adds one to that so that it will continuously give us a number of how many sales for a particular date. If anyone could help me resolve this issue, it would be much appreciated.

btw the structure of the "marketing" table is as follows:
`Month` int(2) NOT NULL,
`Day` int(2) NOT NULL,
`Year` int(4) NOT NULL,
`Sales` int(10) NOT NULL,
`Date` datetime NOT NULL,
PRIMARY KEY (`Date`)

[PHP]
<?php
$cfg['mysql_server'] = 'localhost';
$cfg['database'] = 'mailinglist';
$cfg['user'] = 'root';
$cfg['passwordbase'] = '';
$db = @mysql_connect($cfg['mysql_server'], $cfg['user'], $cfg['passwordbase']);
//////////////includied to show where $calldate is from////////////////
while ($query = "SELECT * FROM `mailinglist`.`calls` WHERE `processed` = 0")
{
$result = @mysql_query($query, $db);
$row = mysql_fetch_assoc($result);
$calldate = $row["Date"];
$callday = dateconvert($calldate, 4);
$callmonth = dateconvert($calldate, 3);
$callyear = dateconvert($calldate, 2);
/////////////////////////////////////////////////////////////////////
$result8 = @mysql_query("SELECT * FROM 'mailintlist'.`marketing` WHERE `Date` = '$calldate' LIMIT 0, 1", $db);
//Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\setlastpurchase.php on line 82 (next line)//
$row8 = mysql_fetch_assoc($result8);
$oldsalesmarketing = $row8["Sales"];
$marketingdate = $row8["Date"];
if (!$marketingdate)
{// Run query
mysql_query("INSERT INTO `marketing`(`Date`, 'Month', 'Day', 'Year', 'Sales') VALUES('$calldate', '$callmonth', '$callday', '$callyear', '1')", $db);
echo "<br>WAS Empty";
$newsalesmarketing = 1;
}
else
{
echo "<br>Not Empty";
$newsalesmarketing = $oldsalesmarketing + 5;
$query6 = "UPDATE `mailinglist`.`marketing` SET `Sales` = '$newsalesmarketing' WHERE `marketing`.`Date` = '$marketingdate'";
$result6 = @mysql_query($query6, $db);
}
}
mysql_close();
?>[/PHP]
Jul 3 '07 #1
Share this Question
Share on Google+
5 Replies


kovik
Expert 100+
P: 1,044
Then there is an error with the result.

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query($query) or echo(mysql_error());
  2. if(!is_resource($result))
  3. {
  4.     echo gettype($result);
  5. }
Jul 3 '07 #2

ak1dnar
Expert 100+
P: 1,584
Thread title changed Ajaxrand
[Please Read why!]

Earlier: mysql_fetch_assoc error, so easy, yet not so... PLEASE HELP
Recent: Error in mysql_fetch_assoc()


Jul 4 '07 #3

dafodil
100+
P: 392
$result8 = @mysql_query("SELECT * FROM 'mailintlist'.`marketing` WHERE `Date` = '$calldate' LIMIT 0, 1", $db);



Men look at the name of the db... it's mailinglist not mailinlist....

It should be like this....

$result8 = @mysql_query("SELECT * FROM 'mailingtlist'.`marketing` WHERE `Date` = '$calldate' LIMIT 0, 1", $db);

Please try agin...

thanks....
Jul 4 '07 #4

dafodil
100+
P: 392
Men look at the name of the db... it's mailinglist not mailinlist....

It should be like this....

$result8 = @mysql_query("SELECT * FROM 'mailingtlist'.`marketing` WHERE `Date` = '$calldate' LIMIT 0, 1", $db);

Please try agin...

thanks....
I mean mailinglist sorry for the wrong code... (typographical error)

Here is the correct code...

$result8 = @mysql_query("SELECT * FROM 'mailinglist'.`marketing` WHERE `Date` = '$calldate' LIMIT 0, 1", $db);
Jul 4 '07 #5

P: 2
I mean mailinglist sorry for the wrong code... (typographical error)

Here is the correct code...

$result8 = @mysql_query("SELECT * FROM 'mailinglist'.`marketing` WHERE `Date` = '$calldate' LIMIT 0, 1", $db);

Well actually, I tried it with out the 'mailinglist'. before the name of the table, and still got the error. I dont know if that typo was the same throughout my troubleshooting, but I do know that I will try it on Thursday when I get back to work.

Thanks for your help,
Dustin
Jul 4 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.