jopereira Posted March 2, 2013 Share Posted March 2, 2013 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? Quote Link to comment Share on other sites More sharing options...
jopereira Posted March 2, 2013 Author Share Posted March 2, 2013 anyone?! Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 2, 2013 Share Posted March 2, 2013 Your SQL statement is only selecting id #1 because you explicitly say so. Quote Link to comment Share on other sites More sharing options...
jopereira Posted March 2, 2013 Author Share Posted March 2, 2013 Your SQL statement is only selecting id #1 because you explicitly say so. i know.. i just put it there cuz i dont know what to put i think it's some parameter that passes the id, which relates it to the row of the table i want Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted March 2, 2013 Share Posted March 2, 2013 (edited) Here is a hint, $_GET the id from the query string you passed. You also need to implement proper debugging steps, use Jessica's signature for that! Edited March 2, 2013 by AyKay47 Quote Link to comment Share on other sites More sharing options...
jopereira Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) 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 March 2, 2013 by jopereira Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 2, 2013 Share Posted March 2, 2013 Look in the manual under $_GET Quote Link to comment Share on other sites More sharing options...
jopereira Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) 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 March 2, 2013 by jopereira Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted March 2, 2013 Share Posted March 2, 2013 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 2, 2013 Share Posted March 2, 2013 Assuming ref is numeric $ref = intval($_GET['ref']); $sql = "SELECT * from eventos where id_eventos=$ref"; ... Quote Link to comment Share on other sites More sharing options...
jopereira Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) 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 March 2, 2013 by jopereira Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 2, 2013 Share Posted March 2, 2013 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 Quote Link to comment Share on other sites More sharing options...
jopereira Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) 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 March 2, 2013 by jopereira Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 2, 2013 Share Posted March 2, 2013 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"? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 2, 2013 Share Posted March 2, 2013 As Jessica pointed out you querystring uses "id" href=\"list_event.php?id=$ref\" So you would need $ref = intval($_GET['id']); $sql = "SELECT * from eventos where id_eventos=$ref"; Quote Link to comment Share on other sites More sharing options...
jopereira Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) 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 March 2, 2013 by jopereira Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted March 3, 2013 Share Posted March 3, 2013 (edited) 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 March 3, 2013 by AyKay47 Quote Link to comment 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.