Jump to content

Link image PHP


PF2G

Recommended Posts

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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++;
   }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.