Forum Moderators: coopster

Message Too Old, No Replies

Could anyone help with a php mysql mysql fetch assoc(): supplied error

         

Christico

9:41 pm on May 22, 2007 (gmt 0)

10+ Year Member



$query = "SELECT c.CustomerID, c.Title, c.Forenames, c.Surname, c.Address1, \\
c.Town, c.Postcode, c.Telephone, c.Email, o.OrderID, o.Orderdate, \\
AS orders, a.AuthorID, a.Authorname AS authors, b.BookID, \\
b.Booktitle, b.RRP, b.Ourprice, b.Cost AS Books, od.Serialkey, \\
od.Qty, od.Paidflag AS orderdetail FROM customers AS c \\
JOIN customer AS c ON o.CustomerID = c.CustomerID \\
JOIN orderdetails AS od ON o.OrderID = od.OrderID \\
JOIN books AS b ON od.BookID = b.BookID \\
JOIN authors AS a ON b.AuthorID = a.AuthorID WHERE \\
CustomerID = '".$customerID."' ORDER by c.CustomerID";
$result = mysql_query($query,$conn);
//$row = mysql_num_rows($result);

while($row = mysql_fetch_assoc($result)) {
foreach ($row as $fieldname => $fieldvalue) {
echo $values[]=$fieldvalue;
}
}

This is where my problem occurs a "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Apache2\htdocs\TibcoGI\JSXAPPS\QSSBooks\getCustomerRecords.php on line 78" occurs when I try to run the script. If anyone could help I sure would appreciate it. I have spent a full day trying to figure out what could be the problem. I just can't seem to move forward with it.

cameraman

10:02 pm on May 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not very good at joins, but one thing I see off the bat is a comma at o.Orderdate, AS orders
You're also doing FROM customers AS c and then FROM customer AS c - I don't know whether or not that would cause an error. The extra comma definitely will, though.

Christico

7:21 am on May 23, 2007 (gmt 0)

10+ Year Member



Thanks cameraman, I have fixed those errors but I am still getting the same error message. This is also true for the mysql_fetch_assoc() command. I saw a post that had a similar problem to mine and I have tried to relate it but with no success. The post included input from coopster, who seemed to know in detail what the problem was. I am however very thankful for your help cameraman, just hope one of the moderators looks at this post, hopefully coopster.

Christico

9:36 am on May 23, 2007 (gmt 0)

10+ Year Member



$customerID = 3;
$query = "SELECT c.CustomerID, c.Title, c.Forenames, c.Surname, c.Address1,
c.Town, c.Postcode, c.Telephone, c.Email, o.OrderID, o.Orderdate,
a.AuthorID, a.Authorname, b.BookID, b.Booktitle, b.RRP, b.Ourprice,
b.Cost, od.Serialkey, od.Qty, od.Paidflag FROM customer AS c
JOIN orders AS o ON c.CustomerID = o.CustomerID
JOIN orderdetail AS od ON o.OrderID = od.OrderID
JOIN books AS b ON od.BookID = b.BookID
JOIN authors AS a ON b.AuthorID = a.AuthorID WHERE
c.CustomerID = '".$customerID."' ORDER by c.CustomerID";

$result = mysql_query($query,$conn);
$row = mysql_num_rows($result);

while($row = mysql_fetch_assoc($result)) {
foreach ($row as $fieldname => $fieldvalue) {
echo $values[]=$fieldvalue;
}
}

This does it but I don't know if there are any better ways of doing it. In terms of performance I am not convinced, thanks for your reply cameraman.

coopster

12:53 pm on May 30, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Christico.

As far as performance goes you can always use the MySQL EXPLAIN [dev.mysql.com] statement to get your query optimized.