Foros del Web » Programando para Internet » PHP »

Error con un condicional y no se porque!

Estas en el tema de Error con un condicional y no se porque! en el foro de PHP en Foros del Web. Mi problema es este, y llevo horas dandole vueltas y no consigo solucinarlo. El condigo que tengo es este <table cellpadding="0" cellspacing="0" border="0" style="height:258px"> <tr> ...
  #1 (permalink)  
Antiguo 04/11/2008, 10:12
 
Fecha de Ingreso: junio-2007
Mensajes: 10
Antigüedad: 16 años, 10 meses
Puntos: 0
Error con un condicional y no se porque!

Mi problema es este, y llevo horas dandole vueltas y no consigo solucinarlo.
El condigo que tengo es este

<table cellpadding="0" cellspacing="0" border="0" style="height:258px">
<tr>
<td style="height:55px; border:1px solid #fcf9f2; border-width:0 0 0 25px" class="vam">'.$p_name.'</td>
</tr>
<tr>
<td style="height:114px " class="pic" align="center">'.$p_pic.'</td>
</tr>
<tr>
<td style="height:27px; border:1px solid #fcf9f2; border-width:0 0 0 25px" class="vam">'.$p_price.'</td>
</tr>
<tr>
<td style="height:62px; border:1px solid #fcf9f2; border-width:0 0 0 15px" ><a href="' . tep_href_link('product_info.php?products_id='.$p_i d) . '">'.tep_image_button("button_details.gif").'</a>
<br style="line-height:2px"><a href="'.tep_href_link("products_new.php","action=b uy_now&products_id=".$p_id).'">'.tep_image_button( 'button_add_to_cart1.gif').'</a></td>


</tr>
</table></td></tr></table>');

y lo unico que quiero es ponerle una condicional a la imagen del carrito para controlar el stock pero me da error : Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/jocrfs27/public_html/baurora/includes/modules/product_listing.php on line 185(donde la linea 185 es el condicional)

<table cellpadding="0" cellspacing="0" border="0" style="height:258px">
<tr>
<td style="height:55px; border:1px solid #fcf9f2; border-width:0 0 0 25px" class="vam">'.$p_name.'</td>
</tr>
<tr>
<td style="height:114px " class="pic" align="center">'.$p_pic.'</td>
</tr>
<tr>
<td style="height:27px; border:1px solid #fcf9f2; border-width:0 0 0 25px" class="vam">'.$p_price.'</td>
</tr>
<tr>
<td style="height:62px; border:1px solid #fcf9f2; border-width:0 0 0 15px" ><a href="' . tep_href_link('product_info.php?products_id='.$p_i d) . '">'.tep_image_button("button_details.gif").'</a>
<br style="line-height:2px">
If ($listing['products_quantity']<>0) //linea 185
{
<a href="'.tep_href_link("products_new.php","action=b uy_now&products_id=".$p_id).'">'.tep_image_button( 'button_add_to_cart1.gif').'</a></td>
}else{
$lc_text = tep_image_button('out_stock.gif', IMAGE_BUTTON_OUT_STOCK) . '&';
}

</tr>
</table></td></tr></table>');

Gracias por vuestra atencion!!!
  #2 (permalink)  
Antiguo 04/11/2008, 10:15
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Error con un condicional y no se porque!

Veo que te falta usar las etiquetas de <?php, es por eso que te da el error, si lo estas haciendo todo dentro de un echo, vas a tener que separar e imprimir hasta antes del if() y despues del if() para procesarlo correctamente.

Saludos.
  #3 (permalink)  
Antiguo 04/11/2008, 12:08
 
Fecha de Ingreso: junio-2007
Mensajes: 10
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: Error con un condicional y no se porque!

Ya, pero esque lineas mas arriba del codigo que he puesto ya viene el <?php abierto, y no veo lineas atras donde se cierra, solo se cierra posteriormente, pego parte del codigo para que lo veas,la zona marcada con asteriscos es donde tengo el problema, gracias!


<?php //aqui se abre como se puede veer
}
$info_box_contents = array();
$list_box_contents = array();
$my_row = 0;
$my_col = 0;

for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
switch ($column_list[$col]) {
case 'PRODUCT_LIST_MODEL':
$lc_text = TABLE_HEADING_MODEL;
$lc_align = '';
break;
case 'PRODUCT_LIST_NAME':
$lc_text = TABLE_HEADING_PRODUCTS;
$lc_align = '';
break;
case 'PRODUCT_LIST_MANUFACTURER':
$lc_text = TABLE_HEADING_MANUFACTURER;
$lc_align = '';
break;
case 'PRODUCT_LIST_PRICE':
$lc_text = TABLE_HEADING_PRICE;
$lc_align = 'right';
break;
case 'PRODUCT_LIST_QUANTITY':
$lc_text = TABLE_HEADING_QUANTITY;
$lc_align = 'right';
break;
case 'PRODUCT_LIST_WEIGHT':
$lc_text = TABLE_HEADING_WEIGHT;
$lc_align = 'right';
break;
case 'PRODUCT_LIST_IMAGE':
$lc_text = TABLE_HEADING_IMAGE;
$lc_align = 'center';
break;
case 'PRODUCT_LIST_BUY_NOW':
$lc_text = TABLE_HEADING_BUY_NOW;
$lc_align = 'center';
break;
}

if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
$lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
}

$list_box_contents[0][] = array('align' => $lc_align,
'params' => 'class="productListing-heading"',
'text' => '&nbsp;' . $lc_text . '&nbsp;');
}

if ($listing_split->number_of_rows > 0) {
$rows = 0;
$listing_query = tep_db_query($listing_split->sql_query);
while ($listing = tep_db_fetch_array($listing_query)) {
$rows++;

if (($rows/2) == floor($rows/2)) {
$list_box_contents[] = array('params' => 'class="productListing-even"');
} else {
$list_box_contents[] = array('params' => 'class="productListing-odd"');
}

$cur_row = sizeof($list_box_contents) - 1;

for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
$lc_align = '';

switch ($column_list[$col]) {
case 'PRODUCT_LIST_MODEL':
$lc_align = '';
$lc_text = '&nbsp;' . $listing['products_model'] . '&nbsp;';
break;
case 'PRODUCT_LIST_NAME':
$lc_align = '';
if (isset($HTTP_GET_VARS['manufacturers_id'])) {
$p_name = $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
} else {
$p_name = $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
}
break;
case 'PRODUCT_LIST_MANUFACTURER':
$lc_align = '';
$lc_text = '&nbsp;<a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a>&nbsp;';
break;
case 'PRODUCT_LIST_PRICE':
$lc_align = 'right';
if (tep_not_null($listing['specials_new_products_price'])) {
$p_price = $lc_text = '<s>' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>&nbsp; <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
} else {
$p_price = $lc_text = '<span class="productSpecialPrice">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
}
break;
case 'PRODUCT_LIST_QUANTITY':
$lc_align = 'right';
$lc_text = '&nbsp;' . $listing['products_quantity'] . '&nbsp;';
break;
case 'PRODUCT_LIST_WEIGHT':
$lc_align = 'right';
$lc_text = '&nbsp;' . $listing['products_weight'] . '&nbsp;';
break;
case 'PRODUCT_LIST_IMAGE':
$lc_align = 'center';
if (isset($HTTP_GET_VARS['manufacturers_id'])) {
$p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
} else {
$p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
}
break;
case 'PRODUCT_LIST_BUY_NOW':
$lc_align = 'center';
If ($listing['products_quantity']<>0){
}else{
$lc_text = tep_image_button('out_stock.gif', IMAGE_BUTTON_OUT_STOCK) . '&nbsp;';
}
break;
}

$product_query = tep_db_query("select products_description, products_id from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$listing['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
$product = tep_db_fetch_array($product_query);

$p_desc = substr(strip_tags($product['products_description']), 0, MAX_DESCR_1);
$p_id = $product['products_id'];
/* $list_box_contents[$cur_row][] = array('align' => $lc_align,
'params' => '',
'text' => $lc_text); */

}

$info_box_contents[$my_row][$my_col] = array('align' => 'center',
'params' => ' style="width:33%;"',
'text' => '<table cellpadding="0" cellspacing="1" border="0"><tr><td>
<table cellpadding="0" cellspacing="0" border="0" style="height:258px">
<tr>
<td style="height:55px; border:1px solid #fcf9f2; border-width:0 0 0 25px" class="vam">'.$p_name.'</td>
</tr>
<tr>
<td style="height:114px " class="pic" align="center">'.$p_pic.'</td>
</tr>
<tr>
<td style="height:27px; border:1px solid #fcf9f2; border-width:0 0 0 25px" class="vam">'.$p_price.'</td>
</tr>
<tr>
<td style="height:62px; border:1px solid #fcf9f2; border-width:0 0 0 15px" ><a href="' . tep_href_link('product_info.php?products_id='.$p_i d) . '">'.tep_image_button("button_details.gif").'</a><br><br style="line-height:2px">

************************************************** *************
if($listing['products_quantity']<>0) //linea 185
{ echo "<a href="'.tep_href_link("products_new.php","action=b uy_now&products_id=".$p_id).'">'.tep_image_button( 'button_add_to_cart1.gif').'</a></td>";
}else{
$lc_text = tep_image_button('out_stock.gif', IMAGE_BUTTON_OUT_STOCK) . '&'; }
************************************************** ***************
</tr>
</table></td></tr></table>');

$my_col ++;
if ($my_col > 2) {
$my_col = 0;
$my_row ++;
}
}

new contentBox($info_box_contents);
// new productListingBox($list_box_contents);
} else { ?>


Si el error fuera del echo marcaria la linea del echo, de todas formas ai lo e puesto para probarlo pero me sigue fallando, el problema sigue marcandolo en el if ponga lo k ponga en el echo. Gracias!
  #4 (permalink)  
Antiguo 04/11/2008, 12:15
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Error con un condicional y no se porque!

sigues sin entender.... si lo que estas imprimiendo es una cadena de texto...

simplemente, no puedes meter una condicional de ese modo (y a fuerza bruta) dentro de una cadena de texto

debes salir de ella, hacer tu comparación y continuar imprimiendo... osea, no debes y ni siquiera hay forma de meter un IF dentro de una cadena??!!

lo que puedes hacer es un if-then-else corto....

Código:
'text' => '<foo>' . ($ok == true? 'todo OK': 'no es OK?!') . '<bar/>',
'bazz' => ...
COND ? TRUE : FALSE

sugiero tomes un manual de PHP y leas bastante, suerte!
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:53.