alapimba Posted December 29, 2006 Share Posted December 29, 2006 Hello,I need to echo diferent links depending of an item on a database, but i don't know how to write the code.I guess i'm almost there and must be just a need of ( ) ' " ; in the right places...Can anyone help me?I wrote this:[code=php:0]<?php $tipo = $row_rs_clientes_detail['tipo']; if ($tipo='pilotos') echo "<a href='perfil_clientes.php?id=$row_rs_clientes_detail['id'];&tipo=$row_rs_clientes_detail['tipo'];'> perfil</a>"; if ($tipo='equipas') echo "<a href='apresentacao_clientes.php?id=$row_rs_clientes_detail['id'];&tipo=$row_rs_clientes_detail['tipo'];'> apresentação</a>"; if ($tipo='organizadores') echo "<a href='apresentacao_clientes.php?id=$row_rs_clientes_detail['id'];&tipo=$row_rs_clientes_detail['tipo'];'> apresentação</a>"; ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32167-need-help-with-if-and-else/ Share on other sites More sharing options...
wildteen88 Posted December 29, 2006 Share Posted December 29, 2006 It'll be easier and better if you used a switch rather than if statements. Like so:[code]$tipo = $row_rs_clientes_detail['tipo'];switch($tipo){ case 'pilotos': echo '<a href="perfil_clientes.php?id=' . $row_rs_clientes_detail['id'] . '&tipo=' . $tipo .'">perfil</a>'; break; case 'equipas': echo '<a href="apresentacao_clientes.php?id=' . $row_rs_clientes_detail['id'] . '&tipo=' . $tipo . '">apresentação</a>'; break; case 'organizadores': echo '<a href="apresentacao_clientes.php?id=' . $row_rs_clientes_detail['id'] . '&tipo=' . $tipo . '">apresentação</a>'; break;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32167-need-help-with-if-and-else/#findComment-149303 Share on other sites More sharing options...
kenrbnsn Posted December 29, 2006 Share Posted December 29, 2006 You need to use the "==", not "=" in the "if" statement. The "==" is the comparison operator, the "=" is the assignment operator. There is a difference. You also have single quotes within strings delimited by single quotes. Another way to write this would be to use a switch statement:[code]<?php$href= '';switch ($tipo) { case 'pilotos': $href= '<a href="perfil_clientes.php?id=' . $row_rs_clientes_detail['id'] . '&tipo=' . $row_rs_clientes_detail['tipo'] . "> perfil</a>" break; case 'equipas': $href = '<a href="apresentacao_clientes.php?id=' . $row_rs_clientes_detail['id'] . '&tipo=' . $row_rs_clientes_detail['tipo'] . '"> apresentação</a>'; break; case 'organizadores': $href = '<a href="apresentacao_clientes.php?id=' . $row_rs_clientes_detail['id'] '&tipo=' . $row_rs_clientes_detail['tipo'] . '"> apresentação</a>'; break;}echo $href;?>[/code]Wildteen beat me to it...Ken Quote Link to comment https://forums.phpfreaks.com/topic/32167-need-help-with-if-and-else/#findComment-149304 Share on other sites More sharing options...
glenelkins Posted December 29, 2006 Share Posted December 29, 2006 [code]<?php $tipo = $row_rs_clientes_detail['tipo'];switch ($tipo) { case "pilotos": echo "<a href='perfil_clientes.php?id=" . $row_rs_clientes_detail['id'] . "&tipo=" . $row_rs_clientes_detail['tipo'] . "'>Perfil</a>"; break; case "equipas": echo "<a href='apresentacao_clientes.php?id=" . $row_rs_clientes_detail['id'] . "&tipo=" . $row_res_clientes_detail['tipo'] . "'>Apresentação</a>"; break; case "organizadores": echo "<a href='apresentacao_clientes.php?id=" . $row_rs_clientes_detail['id'] . "&tipo=" . $row_res_clientes_detail['tipo'] . "'>Apresentação</a>"; break;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32167-need-help-with-if-and-else/#findComment-149305 Share on other sites More sharing options...
glenelkins Posted December 29, 2006 Share Posted December 29, 2006 lol 3 very similar responses at the same time!! wow spoiled for choice! Quote Link to comment https://forums.phpfreaks.com/topic/32167-need-help-with-if-and-else/#findComment-149306 Share on other sites More sharing options...
alapimba Posted December 29, 2006 Author Share Posted December 29, 2006 i knew it was simpleThanks for your help guys :) Quote Link to comment https://forums.phpfreaks.com/topic/32167-need-help-with-if-and-else/#findComment-149338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.