[CS-FSLUG] sql queries

David McGlone d.mcglone at att.net
Sun Dec 21 09:50:14 CST 2008


On Saturday 20 December 2008 5:25:40 pm Timothy Butler wrote:
> Do you have a column that has a numerical id in it, perhaps an index
> column so we can tell for sure which row is row 1 and which is row 2?

I assumed it would be the id field. it auto increments. 

the db layout is, field 1 the id, field 2 sub_heading and field 3 is the text 
that matches that sub_heading called sub_heading_text.
>
> 	-Tim
>
> On Dec 20, 2008, at 4:11 PM, David McGlone wrote:
> > 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?


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




More information about the Christiansource mailing list