Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_fetch_row() Error's out 2

Status
Not open for further replies.

WilliamMute

Programmer
Jan 4, 2006
117
Hi,

Dont know if you can help, but I am quite stuck and have been for quite a while now, for the life of me, I just cant understand why am getting the following error
Code:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/fhlinux205/s/springrise.net/user/htdocs/cart_view.php on line 55

on the following script:

Code:
mysql_select_db($database_Connection, $Connection);
$query = "SELECT SUM(".$this->products.".product_price*" .
             $this->springrisecart.quantity .") as subtotal,
             SUM(subtotal) as total
             FROM ".$this->springrisecart."," .
             $this->products."
             WHERE session='".$this->cart_id."' AND
             ".$this->springrisecart.".id = " .
             $this->springrisecart.".product_id
             GROUP BY ".$this->springrisecart.".product_id";
   $result = mysql_query($query);
   $row = mysql_fetch_row($result);
   return $row['total'];
   $Final = $result;


The error seems to be coming from the line:

$row = mysql_fetch_row($result);
   return $row['total'];

Any help would be appreciated please

Thank you ever so much.
 
hard code a session id that you know works instead of the $cart_id.
 


session: aa4b0358a65b0141be2a35270b5d1a2b
product id : 48
name: Wristwatch bracelet

session: aa4b0358a65b0141be2a35270b5d1a2b
product id : 49
name: bracelet wristwatch

session: aa4b0358a65b0141be2a35270b5d1a2b
product id : 34
name: Wedding Necklace

session: aa4b0358a65b0141be2a35270b5d1a2b
product id : 34
name: Wedding Necklace
 
there you go then. that looks right, no?

you might want to add the word DISTINCT after the word SELECT to eliminate duplicate lines as a finishing touch?

or have i misunderstood your aim?
 
Yes I get you but why isn't the while loop giving out the result on the body of the page? and why isn't my sessionID working ($cart_id) because that is what am looking for.

Thanks god!
 
WilliamMute... it looks to me like you're darn close here... so I hate to throw a monkey wrench in any works, but have you concerned using basic SQL (like the above) and doing the lifting in PHP?

I.E. do like the above, but have your loop do all the subtotalling and totalling... so it goes something like this:

Code:
$total = 0;
$subtotals = array();
$quantities = array();
$info = array();
while ($row=mysql_fetch_assoc($result)):
  $total += $row['price'];
  if (!isset($quantities[$row['id']]))
  { 
    $quantities[$row['id']] = 0;
    $subtotals[$row['id']] = 0;
    $info[$row['id']]['name'] = $row['product_name'];
  }
  $quantities[$row['id']]++;
  $subtotals[$row['id']] += $row['price'];

endwhile;

Obviously the above cannot be cut and pasted into your application, since you're not currently returning all those values in your query... but my point is, the SQL aggregate functions are great, and work well, and simplify alot of code for you... but it seems to me that the aggregates you were trying originally don't actually mesh with your table design, and that perhaps brute force is a better approach... plus it lets you do more along the way.

Anyway, just an idea... best of luck with it whichever path you choose, but may I humble suggest that before you worry too much more about implementing the solution you clearly state your goals, this thread is suffering from shifting requirements. And then, clearly state some DB structure... I mean, so far jpadie has been able to succesfully guess at alot of that because it's a pretty standard ERD apparently, but it would likely save everyone alot of timet o just have the information.
 
you might want to add the word DISTINCT after the word SELECT to eliminate duplicate lines as a finishing touch?

Careful, without knowing the DB schema for sure it's hard to say, but multiple rows may indicate quantity.
 
skiflyer - unless i'm mistaken William has fixed the totalling aspect of this thread. we perhaps should have started another one.

on your second post - the aim was to retrieve the name etc of an item in the basket. quantity is irrelevant.

Williammute: I don't understand your last post. where is the while loop outputting the result that you pasted if it is not to your page? to convert this to your original loop you would use:
Code:
<?
$sql = "
SELECT products.product_name, products.product_dimension, products.product_price, products.image, products.id, springrisecart.quantity 
FROM springrisecart 
INNER JOIN 
  products 
  ON 
    products.id = springrisecart.product_id
WHERE 
   springrisecart.`session`='$cart_id'";
$Recordset1 = mysql_query($sql) or die ("Query error: ".mysql_error());
 echo "<table>";
 while ( $row_Recordset1 = mysql_fetch_assoc($Recordset1) ) :
   $class = ($class === "even_row") ? "odd_row" : "even_row";     { ?>
   
      <tr class=<?=$class?>>
        <td><a href="[URL unfurl="true"]http://www.springrise.net/single_item.php?id=<?=$row_Recordset1[/URL]['id']?>"><?=$row_Recordset1['product_name']?></a></td>
        <td><?=$row_Recordset1['product_dimension']?></td>
        <td><?=$row_Recordset1['product_id']?></td>
        <td><?=row_Recordset1['product_price']?></td>
        <td><img src="products/<?=$row_Recordset1['image']?>.jpg" alt="Your Product" height="25" width="28"></td>
        <td>&nbsp;</td>
      </tr>
    <?php 
} 
endwhile; 
echo "</table>";
?>
 
williammute: the only reasons that your current session id is not working are:

1. you have started a new session that is not captured in the db as having products; or
2. the current session has not products; or
3. the cookie is not getting thru.

try echoing out the incoming cookie value to determine the answer.
 
PHP & MySQL god!!!! you done it again...... God I could jump and kiss the sky! Thank you Thank You Thank You, ur simply the best!

Thank you jpadie
Thank you Skiflyer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top