williamh26 Posted October 25, 2012 Share Posted October 25, 2012 Hi guys I have the following tables: table: capitulo capitulo_id autoincrement libro_id capitulo table: rv1960 id versiculo texto I have the following code in which i want to populate all the versiculo(vers) and texto from each capitulo(chapter) what i acomplish is populate the vers from all chapters , i just show all vers from each chapter. this is the query i use <?php //variable $versiculo = $_GET['cat']; $query="SELECT versiculo, texto from rv1960 where id = $versiculo"; $result=mysql_query($query); if(mysql_num_rows($result)>0){ echo"<table border='0' align='center' cellpadding='2' cellspacing='2' width='100%'>"; while($row=mysql_fetch_array($result,MYSQL_ASSOC)){ $versiculo = $row['versiculo']; $texto = $row['texto']; echo "<tr>"; echo "<td VALIGN='TOP'><font size='2' color='#FFFFFF' face='Verdana' color='red'>$versiculo</font></td>"; echo"<td VALIGN='TOP'><font size='2' face='Verdana' color='#FFFFFF'>$texto</font></td>"; echo "</tr>"; } echo"</table>"; } ?> can help me pleases thanks Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/ Share on other sites More sharing options...
Christian F. Posted October 25, 2012 Share Posted October 25, 2012 $versiculo = $_GET['cat']; $query="SELECT versiculo, texto from rv1960 where id = $versiculo"; If you translate these lines to plain English (or your native language), you'll soon discover why that is. In short, you're telling the script to get the verses and texts for one specific chapters (categories?), which is exactly what you get. If you want it all, you need to specify that you want everything (or rather, not limit the result). Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1387782 Share on other sites More sharing options...
williamh26 Posted October 27, 2012 Author Share Posted October 27, 2012 (edited) Hi guys i have an error in my previos database. This is the bible database : This is my data I want to populate versiculo + texto from each capitulo that is in each id_libro. Explanation: Until now I been populated the two main books of the bible ---> Old Testament and New Testament if I click on the Old testament, it will show all the books on it, Genesis..etc... then I click on Genesis and populate all the 50 chapters on it, Chapter 1, 2, 3..... 50. then if I click on Chapter 1 of Genesis I want to populate the vers and the text contain on that respective Chapter. However I populate all the vers and text of all chapters on Genesis book when I click Chapter 1, instead of only 31 vers that contain chapter 1 of Genesis. See the Picture below: it continues....... I using the following query: <?php $id_libro = $_GET['cat']; $query="SELECT versiculo,texto from rv1960 where id_libro =$id_libro "; $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $versiculo =$row['versiculo']; $texto =$row['texto']; echo "<h3>$versiculo -- $texto</h3><br>"; echo"<p>"; } ?> Can you guys please help me ... this is the first time I using SQL. Thanks Edited October 27, 2012 by williamh26 Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1388075 Share on other sites More sharing options...
Barand Posted October 27, 2012 Share Posted October 27, 2012 You will need to find those versiculo that are in a particular libro and capitulo $query="SELECT versiculo,texto from rv1960 where id_libro =$id_libro and capitulo = $capitulo"; Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1388094 Share on other sites More sharing options...
williamh26 Posted November 1, 2012 Author Share Posted November 1, 2012 Hi.. thank you very much I tryed but i gets the following patern: Capitulo 1 of Genesis (which is fine), however when click in Capitulo 2 (chapter 2 genesis) it jumps to Chapter 2 of Exodus (capitulo dos Exodo) instead of Genesis Chapter 2. <?php $capitulo = $_GET['cat']; $id_libro = $_GET['cat']; $query="SELECT versiculo,texto,capitulo from rv1960 where id_libro =$id_libro and capitulo = $capitulo "; $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $versiculo =$row['versiculo']; $capitulo =$row['capitulo']; $texto =$row['texto']; echo "<h3>$versiculo -- $texto</h3><br>"; echo"<p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389141 Share on other sites More sharing options...
Barand Posted November 1, 2012 Share Posted November 1, 2012 $capitulo = $_GET['cat']; $id_libro = $_GET['cat']; Both set to same value ie 'cat' Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389148 Share on other sites More sharing options...
williamh26 Posted November 1, 2012 Author Share Posted November 1, 2012 I put i little video in you tube this is the link Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389149 Share on other sites More sharing options...
williamh26 Posted November 1, 2012 Author Share Posted November 1, 2012 i delete $capitulo $Get_['cat']; and it give me the following error Undefined variable: capitulo in C:\wamp\www\Iglesia viviente\includes\escritura.inc.php on line 12 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Iglesia viviente\includes\escritura.inc.php on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389190 Share on other sites More sharing options...
williamh26 Posted November 1, 2012 Author Share Posted November 1, 2012 <?php $id_libro = $_GET['cat']; $query="SELECT versiculo,texto,capitulo from rv1960 where id_libro =$id_libro and capitulo= $capitulo"; $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $versiculo =$row['versiculo']; $capitulo =$row['capitulo']; $texto =$row['texto']; echo "<h3>$versiculo -- $texto</h3><br>"; echo"<p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389191 Share on other sites More sharing options...
Barand Posted November 1, 2012 Share Posted November 1, 2012 capitulo and id_libro both need values - just not the same one every time. You were always setting them both to the capitulo value so when you moved to chapter 2 you also moved to book 2. Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389258 Share on other sites More sharing options...
williamh26 Posted November 1, 2012 Author Share Posted November 1, 2012 Hi Barand... i dont know much about sql....how i will do that.... thanks Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389297 Share on other sites More sharing options...
Barand Posted November 1, 2012 Share Posted November 1, 2012 It has nothing to do with sql side. Your problem is the one I pointed out earlier in your php code. $capitulo = $_GET['cat']; $id_libro = $_GET['cat']; Both are picking up the same input value. $id_libro needs to be set to the value that was input for the book. Sorry but I'm running out of ways to say this. Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389308 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 hi, sorry but i am new a this..... this is what you trying to tell me?? <?php $capitulo =$_GET['id_libro']; $id_libro = $_GET['cat']; $query="SELECT id_libro,texto,versiculo, capitulo from rv1960 where id_libro =$id_libro and capitulo = $capitulo"; $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $id_libro =$row['id_libro']; $versiculo =$row['versiculo']; $capitulo =$row['capitulo']; $texto =$row['texto']; echo "<h3>$versiculo -- $texto</h3><br>"; echo"<p>"; } ?> i hve an error: undefine id_libro Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389470 Share on other sites More sharing options...
Barand Posted November 2, 2012 Share Posted November 2, 2012 (edited) What is the link when someone clicks on "Genesis Capitulo 1" ? It should be something like <a href='scriptname.php?id_libro=1&cat=1'>Genesis Capitulo 1</a> Edited November 2, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389476 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 is this http://localhost/Iglesia%20viviente/index.php?content=escritura&cat=1 Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389478 Share on other sites More sharing options...
Barand Posted November 2, 2012 Share Posted November 2, 2012 (edited) If you only have cat=1, how does it know which libro? edit: Needs to be http://localhost/Iglesia%20viviente/index.php?content=escritura&cat=1&id_libro=1 Edited November 2, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389479 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 by libro_id... Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389480 Share on other sites More sharing options...
Barand Posted November 2, 2012 Share Posted November 2, 2012 by libro_id... But you aren't passing the libro_id in the link Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389481 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 this is my database structure.. table: biblia table:libros table:capitulos table:rv1960 testamento_id libro_id capitulo_id id nombre testamento_id libro_id id_libro nombre capitulo capitulo versiculo texto Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389482 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 i have --> escritura and cat so if u understant correctly i used the get method $escritura =$_GET['escritura']; $cat = $_GET['cat']; so <?php $capitulo =$_GET['libro_id']; $id_libro = $_GET['cat']; $query="SELECT texto,versiculo,capitulo from rv1960 where id_libro =$id_libro and capitulo = $capitulo"; $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $versiculo =$row['versiculo']; $texto =$row['texto']; echo "<h3>$versiculo -- $texto</h3><br>"; echo"<p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389506 Share on other sites More sharing options...
Christian F. Posted November 2, 2012 Share Posted November 2, 2012 (edited) But you aren't passing the libro_id in the link If you want help, then you need to read (and understand) what people are telling you. Otherwise we're just wasting our time, and you'll end up with no-one interested in helping you. May I also suggest that you read through this article, for your own benefit. Edited November 2, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389589 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 Sorry hear that... like I said i am not an expert..... sorry waste your time, i just wanna learn from my mistakes . any ways this is what i think you asked me to do, please just tell me if i am wrong I have to retrieve the value of id_libro, capitulo, versiculo and texto from rv1960 table via Get Method <a href=\"index.php?content=texto&cat=$capitulo_id&libro_id=$libro_id\">Capitulo</a> $cat = $_GET['cat]'; $capitulo_id = $_GET['capitulo_id']; $id_libro = $_GET['id_libro']; Its that rigt??? Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389642 Share on other sites More sharing options...
Christian F. Posted November 2, 2012 Share Posted November 2, 2012 Almost. You're defining the capitulo_id as cat in the URL, thus you'll have to use $_GET['cat'] to get the correct number. Like this: $capitulo_id = intval ($_GET['cat']); $id_libro = intval ($_GET['id_libro']); As you can see the indices in the $_GET array are defined by the name of the key (the part before the =) in the URL. These does not need to be the same as the variable name you give them, but it makes things easier if you define a clear relation between them by using the same or similar names. I've used intval () in the code above to ensure that you get a number, and not some SQL injection string. Helps to keep your scripts safe, when dealing with numerical input. Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389653 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 nice it works.... this is the code <a href=\"index.php?content=escritura&cat=$capitulo_id&libro_id=$libro_id\">Capitulo</a> then escritura.inc.php <?php $capitulo_id = intval ($_GET['cat']); $libro_id = intval ($_GET['libro_id']); $query="SELECT * from rv1960 where capitulo_id = $capitulo_id and libro_id= $libro_id "; $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $libro_id =$row['libro_id']; $versiculo =$row['versiculo']; $texto =$row['texto']; echo "<h3>$versiculo -- $texto</h3><br>"; echo"<p>"; } ?> So, Now it gets all the texto and vesiculo but only from Genesis and not the rest.... what i have to do?? thank you again you the best Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389766 Share on other sites More sharing options...
williamh26 Posted November 2, 2012 Author Share Posted November 2, 2012 Quote Link to comment https://forums.phpfreaks.com/topic/269884-getting-data/#findComment-1389770 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.