2 Replies - 1561 Views - Last Post: 23 May 2012 - 07:11 AM Rate Topic: -----

#1 PF2G  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 15-November 11

Seperate products by its material

Posted 23 May 2012 - 04:13 AM

Hi,

i'm doing a search system where you search the reference of a product and it shows a list of all results, but i have one prolem. Is that i can't do the seperation of the products by its material:

	$ref=$_GET['q2'];
	
	$query_prod="SELECT * FROM produtos WHERE referencia LIKE '%".$ref."%' ORDER BY ordem ASC";
    $produt=mysql_query($query_prod, $futura);
	$row_produt=mysql_fetch_assoc($produt);
    $count=mysql_num_rows($produt);  
	
	$query_idprod="SELECT * FROM produtos WHERE id_produto='".$row_produt['id_produto']."'";
	$idprod = mysql_query ($query_idprod, $futura);
	$row_idprod=mysql_fetch_assoc($idprod);
	
	$query_categ_list = "SELECT * FROM materiais WHERE id_material='".$row_idprod['id_material']."' ORDER BY ordem ASC";
	$categ_list = mysql_query($query_categ_list, $futura) or die(mysql_error());
	$row_material = mysql_fetch_assoc($categ_list);
	$totalRows_categ_list = mysql_num_rows($categ_list);
	
	$sel_categ="SELECT * FROM janelas";
	$categ=mysql_query($sel_categ,$futura);
	$row_categ=mysql_fetch_assoc($categ);
	
	$query_cores = "SELECT * FROM janelas WHERE id_categoria='".$row_categ['id_categoria']."'";
	$cores = mysql_query($query_cores, $futura) or die(mysql_error());
	$row_cores = mysql_fetch_assoc($cores);
	$totalRows_cores = mysql_num_rows($cores);

	$query_cores = "SELECT * FROM janelas WHERE id_categoria='".$row_categ['id_categoria']."'";
	$cores = mysql_query($query_cores, $futura) or die(mysql_error());
	$row_cores = mysql_fetch_assoc($cores);
	$totalRows_cores = mysql_num_rows($cores);


<?PHP

do{
?>
	<td width="631" valign="top" class="texto_pretobig2" style="padding-bottom:10px;"><div class="bomfundo" style="background-color:<?php echo $row_cores['cor']; ?>;">
		<table width="570" border="0" cellspacing="0" cellpadding="0">
			<strong>RESULTADOS DE PESQUISA ::</strong>
			<br/>
			<br/>
			<?php 
				do{
			?>
					<!--HERE IS WHERE I SAY WHAT IS THE MATERIAL-->
					<tr>
						<td colspan="2" class="div_topo">
							<a name="cat<?php echo $row_material['id_material']; ?>"></a>&nbsp; <strong>PRODUTOS :: <span class="texto2"><?php echo $row_material['material']; ?></span></strong>
						</td>
					</tr>

					<tr>
						<td colspan="2" height="16"></td>
					</tr>
					
					<?PHP
						do{
							$query_verimg = "SELECT * FROM produtos_img WHERE id_produto='".$row_produt['id_produto']."' ORDER BY default_ DESC";
							$verimg = mysql_query($query_verimg, $futura) or die(mysql_error());
							$row_verimg = mysql_fetch_assoc($verimg);
							
					?>
					<tr>
									<td width="160" height="95" valign="top">
										<a href="ver_produto.php?id_produto=<?php echo $row_produt['id_produto']; ?>&amp;id_categoria=<?php echo $row_produt['id_material']; ?>"><?php if($row_verimg['imagem']!="") { ?><img src="http://www.plasticos-futura.com/timthumb.php?src=http://www.plasticos-futura.com/produtos/<?php echo $row_verimg['imagem']; ?>&w=134px&h=98px&zc=1&q=100" width="134" height="98" style="border:1px solid #cccccc;" /><?php } else { ?><img src="imagens/futura.jpg" width="134" height="98" style="border:1px solid #cccccc;" /><?php } ?></a>
									</td>
									
									<td valign="top" class="texto_pretobig2">
										<strong>REFERÊNCIA: </strong><?php echo $row_produt['referencia']; ?><br />
										<strong>DESCRIÇÃO:</strong> <?php echo $row_produt['nome']; ?>
										<br/>
										<br/>
										<br/>
										<div id="a_img">
											<a href="ver_produto.php?id_produto=<?php echo $row_produt['id_produto']; ?>&id_categoria=<?php echo $row_produt['id_material']; ?>" class="a_img">Mais imagens</a>
										</div>
									</td>
								</tr>
								
								<tr>
									<td width="160" height="10" style="border-bottom:1px dashed #e0e0e0;">&nbsp;</td>
									<td height="10" style="border-bottom:1px dashed #e0e0e0;">&nbsp;</td>
								</tr>

								
								<tr>
									<td width="160" height="10"></td>
									<td height="10"></td>
								</tr>
								
							<?PHP					
						} while($row_produt = mysql_fetch_assoc($produt));
				} while ($row_material=mysql_fetch_assoc($categ_list));
			?>
		</table>
Se não encontrar o produto que procura, por favor <a href="investigacao-desenvolvimento.php">contacte-nos</a>.
	</td>
<?PHP
} while($row_produt = mysql_fetch_assoc($produt));
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Seperate products by its material

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3391
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: Seperate products by its material

Posted 23 May 2012 - 07:03 AM

hm, where do I start ...

first of all, the $cores query is duplicate - delete that.

second, nested queries? yeah, I see why that gives problems. you should make a sketch how it should look in the end, because now it’s all very confusing what goes where (due to the nesting).
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: Seperate products by its material

Posted 23 May 2012 - 07:11 AM

Let's not omit the security issues created here:
	$ref=$_GET['q2'];
	
	$query_prod="SELECT * FROM produtos WHERE referencia LIKE '%".$ref."%' ORDER BY ordem ASC";


First, $x = $_GET['x'] is always a waste of cycles. You already have the value in $_GET, so why copy it to another variable? If you saw this in a tutorial then stop using it.
Second, putting user supplied data directly into a query is begging to be hacked. You have a choice: learn to scrub variables (difficult) so that you can continue using outdated, insecure, and soon to be deprecated mysql_* functions or learn to use prepared statements (much easier).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1