Re: Re: Newbie Questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Pete Holsberg" <pjh@xxxxxxxx> wrote in message
news:Pine.GSO.4.10.10409021151120.21834-100000@xxxxxxxxxxxxxxxxxx
> On Wed, 1 Sep 2004, Pete Holsberg wrote:
>
> > On Wed, 1 Sep 2004, Torsten Roehr wrote:
> >
> > > "Pete Holsberg" <pjh@xxxxxxxx> wrote in message
> > > news:Pine.GSO.4.10.10409011359210.7843-100000@xxxxxxxxxxxxxxxxxx
> > > >
> > > > I want to set up a directory with the following fields:
> > > >
> > > > surname
> > > > firstname
> > > > spousename
> > > > housenumber
> > > > street
> > > > phone
> > > > email (contents is either an email address or a minus sign)
> > >
> > > IMHO a great way to get started with MySQL is
> > > installing/using phpMyAdmin. It's a web frontend
> > > administartion interface. It makes creating/editing
> > > tables and records quite easy and will also show the
> > > SQL commands - so you can learn from them. You can get
> > > it here:
> > >
> > > http://www.phpmyadmin.net/
> > >
> > > Put it into a *protected* directory on your server. You
> > > only have to put your MySQL access values into the
> > > config file and off you go.
>
> My ISP has it availble.
>
> > > > I'd like to present a webpage to give the view these
> > > > choices:
> > > >
> > > > 1) viewing the entire directory sorted by surname
> > > > 2) viewing the entire directory sorted by street and then
> > > > by housenumber, i.e., by address
> > > > 3) viewing all of the entire records of all who meet a
> > > > simple criterion: piece of an email address (eg, "comcast"
> > > > would list everyone that had comcast in the eail field),
> > > > piece of and of the names or streets, etc.
> > >
> > > Read yourself through the manual of the mysql functions:
> > > http://de3.php.net/manual/en/function.mysql-connect.php
>
> Um, I looked there and it's overwhelming!
>
>
> > > > I have "PHP and MySQL for Dummies". The only thing I
> > > > haven't seen that (I think) I need for the above is
> > > > how to sort on two fields.
> > >
> > > This is easily done by seperating the columns by comma:
> > >
> > > SELECT * FROM table ORDER BY surname, firstname
> > >
> > > This will first sort by surname and within equal
> > > surnames by firstname.
>
> Thanks.
>
> > > > Can anyone help me get started? It seems like a
> > > > pretty easy things to do. Perhaps if someone has
> > > > already done this, they might share their stuff with
> > > > me. I'm much better at hacking away at other people's
> > > > stuff than developing my own from scratch! :-)
>
> I think I need just a little push in the right direction.
> After I send the above SELECT command, how do I get the
> result to appear on a web page?

mysql_query() will return a result set. There are different functions to
extract the rows from it. I would recommend mysql_fetch_assoc() - it returns
an associative array of the current row/record set where the field names of
your table become the keys of the array. So if you select firstname,
lastname you will get an array like this:

array('firstname' => 'My firstname', 'lastname' => 'My lastname')

Just loop through your result set to output/process the data. Try this:

$result = mysql_query('SELECT firstname, lastname FROM table');

while ($row = mysql_fetch_assoc($result)) {

    echo $row['firstname'] . ' ' . $row['lastname'];
}

Hope this helps. regards, Torsten

> Thanks.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux