PF2G Posted November 25, 2011 Share Posted November 25, 2011 Hello, PHPFreaks I'm doing a website about a music school, in this moment i'm working the list of instruments: <?php $username = "root"; $password = ""; $hostname = "localhost"; $database = "esola_musica"; $connect = mysql_connect($hostname, $username, $password) or die("Erro na ligação à BD."); mysql_select_db($database,$connect) or die(mysql_error()); $sql_imagem = "SELECT cod_curso, image_curso, nome_curso FROM curso ORDER BY nome_curso ASC"; $i=0; echo "<table width = 90% height = 45% align = center>"; $executa=mysql_query($sql_imagem,$connect); while($dados=mysql_fetch_array($executa)) { $i+=1; if ($i == 1) { echo "<tr> <td align = center>"; } else { echo "<td align = center>"; } echo "<a href='curso_guitarra.php'>"; echo "<img src=\"".$dados['image_curso']."\"/> <br /> ".$dados['nome_curso']; echo "</a>"; if ($i == 4) { echo "</td> </tr>"; $i=0; } else { echo "</td>"; } } echo "</table>"; ?> what i want is to link the images to their respective study plan. Like, if i click on electric guitar it opens its study plan*. *STUDY PLAN is what the students will learn in the instrument lessons Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/ Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 Do you have a question? Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291117 Share on other sites More sharing options...
PF2G Posted November 25, 2011 Author Share Posted November 25, 2011 I tried, when i click in electric guitar: if ($dados [cod_curso] == 1){ echo "<a href='curso_guitarra.php'>"; echo "<img src=\"".$dados['image_curso']."\"/> <br /> ".$dados['nome_curso']; echo "</a>"; } And opens the guitar objectives. But it doesn't work... Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291119 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 You're going to need to define "dosen't work". What happens, versus what you would expect to happen? Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291120 Share on other sites More sharing options...
PF2G Posted November 25, 2011 Author Share Posted November 25, 2011 when i put: if ($dados [cod_curso] == 1){ echo "<a href='curso_guitarra.php'>"; echo "<img src=\"".$dados['image_curso']."\"/> <br /> ".$dados['nome_curso']; echo "</a>";} only appears the guitar image. What i want is to appears the complete table and when i click in the guitar image it opens other page with guitar information, got it? Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291122 Share on other sites More sharing options...
PF2G Posted November 27, 2011 Author Share Posted November 27, 2011 Someone can help? It's urgent, plz. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291648 Share on other sites More sharing options...
richiec Posted November 27, 2011 Share Posted November 27, 2011 echo "<a href=\"curso_guitarra.php\"><img src=\"".$dados['image_curso']."\"/><br />".$dados['nome_curso']"</a>"; Updated, had an error in it. Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291662 Share on other sites More sharing options...
gerkintrigg Posted November 28, 2011 Share Posted November 28, 2011 If I were to do it, I'd use a while loop to output all records that match your criteria and probably skip some of the echo stuff and just have something like this: ?><a href='curso_guitarra.php'><img src="<?php echo $dados['image_curso'];?>"/> <br /> <?php echo $dados['nome_curso'];?></a><?php that way you will be able to see the format of the data in your program (like Dreamweaver) to make sure that any errors you have is in the PHP and not basic HTML formatting (which can be very messy in tables, the way you're doing it). Just a thought and it might help. Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291693 Share on other sites More sharing options...
PF2G Posted November 28, 2011 Author Share Posted November 28, 2011 If I were to do it, I'd use a while loop to output all records that match your criteria and probably skip some of the echo stuff and just have something like this: ?><a href='curso_guitarra.php'><img src="<?php echo $dados['image_curso'];?>"/> <br /> <?php echo $dados['nome_curso'];?></a><?php that way you will be able to see the format of the data in your program (like Dreamweaver) to make sure that any errors you have is in the PHP and not basic HTML formatting (which can be very messy in tables, the way you're doing it). Just a thought and it might help. Tell me if i'm correct. If i understand you'te telling me: $x=0 //number of instruments (for exemple, 5 instruments) while($i<=5) { if ($dados [cod_curso] == 1) { echo "<a href=\"curso_guitarra.php\"><img src=\"".$dados['image_curso']."\"/><br />".$dados['nome_curso']"</a>"; } } ?> Is that it? I never worked with while loop in PHP... Thank You Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1291816 Share on other sites More sharing options...
richiec Posted November 28, 2011 Share Posted November 28, 2011 You need to $i++ at the end to then make $i go up by one each time untill it gets to 5 and then it will stop. However since you have another use for $i in the script define it as something else, maybe thats what the $x was but you just didn't change it in the while function. $x=0; //number of instruments (for exemple, 5 instruments) while($x < 5) { if ($dados [cod_curso] == 1) { echo "<a href=\"curso_guitarra.php\"><img src=\"".$dados['image_curso']."\"/><br />".$dados['nome_curso']"</a>"; } $x++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/251785-link-image-php/#findComment-1292009 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.