Jump to content

Listing items with different links


jopereira

Recommended Posts

I've got 3 listed items, like this:

 

Item one

 

Item two

 

Item three

 

each one of this items have a link, but all the 3 items are different rows from the same table, but all the links open the same

 

how can I distinct each one of the links?

I got this code:

<?PHP
//echo "<link href='default.css' rel='stylesheet' type='text/css' media='all' />";
$conn = mysql_connect("localhost", "root", "") or die("Impossivel conectar");

if($conn)
	{
		mysql_select_db("eventos", $conn);	
		} 
		$sql = "SELECT id_eventos, nome FROM eventos";		
		$rs = mysql_query($sql, $conn);		
		$num = mysql_num_rows($rs);
		if($num > 0)
		{
			//echo "<table border=0 cellpadding=0 cellspacing=0>\n";

			while($dados = mysql_fetch_array($rs))
			{
				$ref 	= $dados["id_eventos"];
				$nome 	= $dados["nome"];
			/*	$img = $dados["imagens"];
				echo"		<tr>";
				echo"		<td>$ref</td>";
				echo"		<td>$desc</td>";
				echo"		<td>$pvp</td>";
				echo"		<td>$func</td>";
				echo"		<td>$garant</td>";*/
			//	echo "<td>";
			
				//echo "<li><a href=\"mostra_evento.php?id=$ref\"></li>";
				echo"<li><a href=\"listar_imagem.php?id=$ref\">$nome</a></li>";
				//echo"</td>";		
				//echo"	</tr>\n";
			}
	   	}
   // echo "</table>\n";
?>
<?PHP
$conn = mysql_connect("localhost", "root", "") or die("Impossivel conectar");

if($conn)
	{
		mysql_select_db("eventos", $conn);	
		}  
		$sql = "SELECT * from eventos where id_eventos=1;		
		$rs = mysql_query($sql, $conn);		
		$num = mysql_num_rows($rs);
		if($num > 0)
		{
			echo "<table border=0 cellpadding=0 cellspacing=0>\n";
			echo "<table border=0 cellpadding=3 cellspacing=0>
			<tr>
			<td>Nº de Evento</td>
			<td>Nome</td>
			<td>Descrição</td>
			<td>Requisitos</td>
			<td>Data</td>
			<td>Vencedor</td>
			</tr>";
			while($dados = mysql_fetch_array($rs))
			{
				$ref 	= $dados["id_eventos"];
				$nome 	= $dados["nome"];
				$desc    = $dados["descricao"];
				$req   = $dados["requisitos"];
				$data = $dados["data"];
				$vence   = $dados["vencedor"];
				//$img = $dados["imagens"];
				echo"		<tr>";
				echo"		<td>$ref</td>";
				echo"		<td>$nome</td>";
				echo"		<td>$desc</td>";
				echo"		<td>$req</td>";
				echo"		<td>$data</td>";
				echo"		<td>$vence</td>";
				echo "<td>";
				echo"<a href=\"listar_imagem.php?id=$id\"></a>";
				
				echo"</td>";		
				echo"	</tr>\n";
			}
	   	}
		echo "</table>";
    echo "</table>\n";
?>

can you help?

Link to comment
Share on other sites

i'm complity a newbie..

i barely can do a log in system, mutch less debugg. i read what she said, and I understand a good hint to discover the error is to echo where they happear, but.. reading is different than doing :/

 

btw can you give me more detail info about that $get?

Edited by jopereira
Link to comment
Share on other sites

Look in the manual under $_GET

i read into some info about $_GET but I found nothing i could use

 

my next guess it's in the script responsible to list the items I got this

echo"<li><a href=\"list_event.php?id=$ref\">$name</a></li>";

and on the script responsible to load its info is:

$sql = "SELECT * from eventos where id_event=$ref";
...

echo"<a href=\"list_event.php?id=$ref\"></a>";

i think this $ref parameter could help, but how it is now it gives the error:

 

 

Notice: Undefined variable: ref in C:\xampp\htdocs\xampp\eventos\list_event.php on line 8

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\eventos\list_event.php on line 10

Edited by jopereira
Link to comment
Share on other sites

 

Assuming ref is numeric

 

 

$ref = intval($_GET['ref']);
 
$sql = "SELECT * from eventos where id_eventos=$ref";
 
...

it is a INT value, auto incremet, and I did as you said, but it keeps saying:

 

Notice: Undefined index: ref in C:\xampp\htdocs\xampp\eventos\listar_imagem.php on line 8

Edited by jopereira
Link to comment
Share on other sites

Your url is sending id, not ref.

 

Try to think about it logically instead of simply claiming you don't understand it. If you read the documentation on $_GET it's pretty clear.

 

http://www.php.net/manual/en/reserved.variables.get.php

nope.. I already saw that and corrected

id_eventos is the value that distincts the line of my table (the primary key) and the variable that holds its value is $ref

look (pay attention to the <-----------------------------):

<?PHP
//echo "<link href='default.css' rel='stylesheet' type='text/css' media='all' />";
$conn = mysql_connect("localhost", "root", "") or die("Impossivel conectar");

if($conn)
	{
		mysql_select_db("eventos", $conn);	
		} 
		$sql = "SELECT id_eventos, nome FROM eventos";		
		$rs = mysql_query($sql, $conn);		
		$num = mysql_num_rows($rs);
		if($num > 0)
		{
			//echo "<table border=0 cellpadding=0 cellspacing=0>\n";

			while($dados = mysql_fetch_array($rs))
			{
				$ref 	= $dados["id_eventos"]; <----------------------------------
				$nome 	= $dados["nome"];
			/*	$img = $dados["imagens"];
				echo"		<tr>";
				echo"		<td>$ref</td>";
				echo"		<td>$desc</td>";
				echo"		<td>$pvp</td>";
				echo"		<td>$func</td>";
				echo"		<td>$garant</td>";*/
			//	echo "<td>";
			
				//echo "<li><a href=\"mostra_evento.php?id=$ref\"></li>";
			        echo"<li><a href=\"listar_imagem.php?id_eventos=$ref\">$nome</a></li>";<--------------------------
				//echo"</td>";		
				//echo"	</tr>\n";
			}
	   	}
   // echo "</table>\n";
?>
<?PHP
$conn = mysql_connect("localhost", "root", "") or die("Impossivel conectar");

if($conn)
    {
        mysql_select_db("eventos", $conn);    
        }
        $ref = intval($_GET['id_eventos']);<----------------------------------
        $sql = "SELECT * from eventos where id_eventos=$ref";        <----------------------------------
        $rs = mysql_query($sql, $conn);        
        $num = mysql_num_rows($rs);
        if($num > 0)
        {
            echo "<table border=0 cellpadding=0 cellspacing=0>\n";
            echo "<table border=0 cellpadding=3 cellspacing=0>
            <tr>
            <td>Nº de Evento</td>
            <td>Nome</td>
            <td>Descrição</td>
            <td>Requisitos</td>
            <td>Data</td>
            <td>Vencedor</td>
            </tr>";
            while($dados = mysql_fetch_array($rs))
            {
                $ref     = $dados["id_eventos"];
                $nome     = $dados["nome"];
                $desc = $dados["descricao"];
                $req = $dados["requisitos"];
                $data = $dados["data"];
                $vence = $dados["vencedor"];
                //$img = $dados["imagens"];
                echo"        <tr>";
                echo"        <td>$id_eventos</td>";
                echo"        <td>$nome</td>";
                echo"        <td>$descricao</td>";
                echo"        <td>$requisitos</td>";
                echo"        <td>$data</td>";
                echo"        <td>$vencedor</td>";
                echo "<td>";
                
                echo"</td>";        
                echo"    </tr>\n";
            }
         }
echo "</table>\n";
?>
Edited by jopereira
Link to comment
Share on other sites

Your URL says id.

 

Look at the example in the documentation. And think about it.

If you go to a URL ending in id=5 and you want to get 5, what would you need to "GET"?

do'h

damn I missed the logical thing.. I thought I had already changed that id, but I actually didn't //.-

I realy appreciate the way all you people help here, it's such a shame that some teachers dont do that way, resulting in my unknowledge and "personal hate" for php, when it is so easy when you get thing done

 

sorry for beeing dumb :/

 

my issue is solved here

thanks!

Edited by jopereira
Link to comment
Share on other sites

Sigh, $_GET['id'] on the receiving page will hold the value you are looking for. Just make sure to cast it to an int data type before using it in the SQL statement.

 

If only you would have read it when I posted it.

Edited by AyKay47
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.