[CS-FSLUG] sql queries

David McGlone d.mcglone at att.net
Sat Dec 20 16:11:20 CST 2008


Hi all,

I've been brushing up on my PHP and MySQL and I'm trying to create something. 
:-)

That something is, a database full of text with each ID of the database 
appearing on certain pages. I have accomplished this, but I am having problems 
restricting what appears on each page.  for instance: I have a table named 
site_text and in that table I have 3 fields ID sub_heading and 
sub_heading_text. Let's say I just want the first 2 sub_heading's and 
sub_heading_text id's 1 and 2 to appear on the index page and sub_heading and 
sub_heading_text id 3 to appear on a different page. How could I accomplish 
this? currently what I have come up with is showing all 3 id's on the index 
page.

Here's the query I'm using:

$query = "SELECT * FROM all_text";
$result = @mysql_query($query);

while ($row = @mysql_fetch_array($result))
{
    echo "<h1><span> $row[sub_heading]</span></h1>";

    echo "$row[sub_heading_text]";
  }

This is displaying as I expected, but it is adding the 3rd row that I do not 
want.

I changed the while loop to an if statement, but got no results. I was 
probably doing it wrong. Also if I take out the while loop, then all the ID's 
that I want to appear on 1 page will not display past the first ID.

Any Ideas?


Thanks,
-- 
David M.
http://www.dmcentral.net




More information about the Christiansource mailing list