0

Hello.

I have gone through various checks, and I can't seem to figure this one out...

while($row_sizes = mysql_fetch_array($sql_sizes));
					{	
						$sizes = $row_sizes['size'];
						$product_list .= count($sizes);
						$product_list .= "<li>".$sizes."</li>";
					}

Its not outputting any sizes. However, my count($sizes) outputs 0. And that shouldn't because I have

$sql_colors = mysql_query("SELECT * FROM colors WHERE $id = product_id");
		$sql_sizes = mysql_query("SELECT * FROM size WHERE $id = product_id");
while($row_colors = mysql_fetch_array($sql_colors))
					{
						$colors = $row_colors['color'];
						$product_list .= "<li>".$colors."</li>";

					}

And the color portion in my code works! But not the size!? Its exactly the same coding, but just had different words?

Can someone help me detect what I'm missing?

Thanks

4
Contributors
11
Replies
12
Views
6 Years
Discussion Span
Last Post by andrewliu
0

I also tried outputting product_id with

$row_sizes['product_id'];

but that doesn't work either. I thought it would be the mysql_fetch_array, but it looks right to me?

0

Check you connection string, trim database names, see if firewall is not blocking any MySQL port. If that dont work, use die statement and post the exception here, if you cant figure out.

do like this:

$sql = "your_query";
	$con = mysql_connect(your_connection_string) or die("error ".mysql_error());
	if (!$con)
  	{
  		die('Could not connect: ' . mysql_error()."\n");
  	}
  	mysql_select_db("your_database", $con);
  	$result = mysql_query($sql);
  	if (!$result)
  	{
  		die('error in query: ' . mysql_error()."\n");
  	}
  	while($row = mysql_fetch_array($result))
  	{
  		//stuff	
  	}
	mysql_close($con);

maybe this will give you an idea of what is happening :)

0

why not try

$sql_colors = mysql_query("SELECT * FROM `colors` WHERE `id` ='$product_id'");
$sql_sizes = mysql_query("SELECT * FROM `size` WHERE `id` ='$product_id'");

that is assuming that product_id is a variable ( e.g. $product_id = $_GET[id]; )
might fix it

Edited by public-image: n/a

0

I think your mysql query is just a little confused, assuming you are saying that you are trying to get the id from the `product_id` you would use this code:

$sql_colors = mysql_query("SELECT * FROM `colors` WHERE `product_id`='$id'");
$sql_sizes = mysql_query("SELECT * FROM `size` WHERE `product_id`='$id'");

Hope that fixes it :)

0

:( I wished that was the case. But it doesn't seem like that worked. I mixed it up as well but still not producing what its supposed to

0
while($row_sizes = mysql_fetch_array($sql_sizes));
					{	
						$sizes = $row_sizes['size'];
						$product_list .= count($sizes);
						$product_list .= "<li>".$sizes."</li>";
					}

your main error now that I see it is:

you have a ; after your while

it should be

while($row_sizes = mysql_fetch_array($sql_sizes)){
	
						$sizes = $row_sizes['size'];
						$product_list .= count($sizes);
						$product_list .= "<li>".$sizes."</li>";
					}

Edited by public-image: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.