473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with query

155 100+
I have a Bible database and I need help writing the query a little bit of styling.

I want to display all the books and chapters (which will be linked to another page -passage.php) that will display all the verses in that chapter. Here's waht I'd like it to look like:
[PHP]http://www.biblegateway.com/versions/?action=getVersionInfo&vid=49[/PHP]

I've tried this but it goes all the way across the screen and I get like 28+ of each chapter. That times 50 chapters for Genesis...
[PHP]<table width='95%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<th>Book</th>
<th>Chapters</th>
</tr>
<tr>


<?php
include("includes/dbinfobible.inc.php");
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT book FROM bibleasv WHERE book='Genesis'";
$result=mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$book = stripslashes($row['book']);
}
echo "
<td style='white-space: nowrap;'>$book</td>
<td>
";


$query="SELECT chapter FROM bibleasv WHERE book='$book'";
$result=mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');
$num=mysql_numrows($result);
$i=0;
while ($i < $num)
{
$chapter = mysql_result($result,$i,"chapter");

echo "<a href='passage.php?file=$chapter'>$chapter</a>&nbsp;&nbsp;&nbsp;&nbsp;";

++$i;
}
?>

</tr>
</table>[/PHP]

How to I get the chapters to drop down to another line instead of going across the screen?
Feb 2 '08 #1
2 1535
DavidPr
155 100+
Part of the problem with the excessive number of chapters with the same number, being displayed is that the .sql file puts every verse in separately. So Genesis Chapter 1 has 31 verses and Chapter 2 has 25 verses and so on.

So when I run my query using either:
[PHP]$query="SELECT chapter FROM bibleasv WHERE book='$book'";
$result=mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');
$num=mysql_numrows($result);
$i=0;
while ($i < $num)
{
$chapter = mysql_result($result,$i,"chapter");

echo "<a href='passage.php?file=$chapter'>$chapter</a>&nbsp;&nbsp;&nbsp;&nbsp;";

++$i;
} [/PHP]
or
[PHP]$query="SELECT chapter FROM bibleasv WHERE book='$book'";
$result=mysql_query($query) or die('Error, query failed mysql said <b>'.mysql_error().'</b>');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$chapter = stripslashes($row['chapter']);
echo "<a href='passage.php?file=$chapter'>$chapter</a>&nbsp;&nbsp;&nbsp;&nbsp;";
}
mysql_free_result($result);
?>[/PHP]
It displays Chapter "1" for each verse.

Here's one line of the sql file:
[PHP]INSERT INTO bibleasv VALUES (32, 1, 'Genesis', 2, 1, 'verse goes here');[/PHP]
And here's the table makeup: id, number, book, chapter, verse, text

How should I write the query to only show Chapters: 1, 2, 3, 4, ...?
Feb 2 '08 #2
code green
1,726 Expert 1GB
How to I get the chapters to drop down to another line instead of going across the screen?
Just replace the NONE breaking spaces with a break '<br>'[PHP]while ($i < $num)
{
$chapter = mysql_result($result,$i,"chapter");
echo "<a href='passage.php?file=$chapter'>$chapter</a><br>";
++$i;
} [/PHP]
Feb 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
5
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
3
by: mcmahonb | last post by:
Hey people... I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my...
4
by: n | last post by:
Hello! Here is a problem I hope you can point me to a solution. It Problem: A teacher needs to know which lesson to teach. A school has a curriculum with 26 lessons, A-Z. For a given class,...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.