Jump to content

Getting Data


williamh26

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Hi guys i have an error in my previos database. This is the bible database :

 

db1.jpg

This is my data

 

rv1960.jpg

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:

 

untilnow.jpg

 

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 by williamh26
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

dd.jpg

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

Link to comment
Share on other sites

But you aren't passing the libro_id in the link :facewall:

 

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 by Christian F.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.