Re: [PHP-DB] Re: Newbie Questions
Well, I have this: $result=mysql_query('SELECT * FROM $table ORDER BY lastname, street, housenum ASC'); if u're trying to use variables like $table in the query (which i think u are), they need to be in double quotes : not single quotes. so the line should be: $result=mysql_query(SELECT * FROM $table ORDER BY lastname, street, housenum ASC); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: Newbie Questions
On Thu, 2 Sep 2004, Torsten Roehr wrote: 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']; } Well, I have this: $result=mysql_query('SELECT * FROM $table ORDER BY surname, street, housenumber ASC'); while ($row=mysql_fetch_assoc($result)) { echo $row['surname'].' '.$row['firstname'].' '.$row['housenumber'].' '.$row['street']; } and I get Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/.fanny/pjh/4seasonsatmapleton.org/4sam/directory/showForm-mod.php on line 26 Line 26 is the while statement. Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: Newbie Questions
On Sun, 5 Sep 2004, Pete Holsberg wrote: Well, I have this: $result=mysql_query('SELECT * FROM $table ORDER BY lastname, street, housenum ASC'); while ($row=mysql_fetch_assoc($result)) { echo $row['lastname'].' '.$row['firstname'].' '.$row['housenum'].' '.$row['street']; } and I get Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/.fanny/pjh/4seasonsatmapleton.org/4sam/directory/showForm-mod.php on line 26 Line 26 is the while statement. blush I have to learn to keep a 3x5 card with my column headings nearby!! But having corrected that, I'm running into another problem. I added: if (!$result) { echo Could not successfully run query ($sql) from DB: . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo No rows found, nothing to print so am exiting; exit; } And they output nothing nowm so I assume that there are things to print. But the while statement produces nothing also. Also, I think I misunderstood something someone saod earlier. Is it true that the above mysql_query call does not change the way the database is stored by simply sorts the copy that's in memory? Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: Newbie Questions
On Sun, 5 Sep 2004, Pete Holsberg wrote: blush I have to learn to keep a 3x5 card with my column headings nearby!! But having corrected that, I'm running into another problem. Additional blushing CASE-SENSITIVITY, Dummy! ;-) sigh -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: Newbie Questions
On Fri, 3 Sep 2004, Hutchins, Richard wrote: -Original Message- From: Pete Holsberg [mailto:[EMAIL PROTECTED] Sent: Friday, September 03, 2004 11:59 AM Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Re: Newbie Questions On Thu, 2 Sep 2004, Torsten Roehr wrote: 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']; } I want to display the sorted database. Which makes more sense: sorting the database table itself (either by address or by name), or sorting the array? Coming in late on this topic, but... Database. SELECT firstname, lastname, address FROM TABLENAME ORDER BY lastname ASC; Use ASC or DESC to order your query results. When you iterate over the result as Torsten indicated, everything will be in the order you specify. In the database table itself, right? Does it make more sense to do that than to leave the database alone, read it into an array and then sort it anyway I want (there will be at least two different sorted lists I want it to produce)? Check out the MySQL docs for all the information you'll ever need on sorting and/or grouping results from a query. :-) That's like saying check out 'man' for everything you want to know about Unix commands. :-) Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Newbie Questions
SELECT firstname, lastname, address FROM TABLENAME ORDER BY lastname ASC; Use ASC or DESC to order your query results. When you iterate over the result as Torsten indicated, everything will be in the order you specify. In the database table itself, right? Does it make more sense to do that than to leave the database alone, read it into an array and then sort it anyway I want (there will be at least two different sorted lists I want it to produce)? Sorting in the database should always be the preferred way - should be quicker than doing it in the application in 9 out of 10 times. Regards, Torsten Roehr -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Newbie Questions
On Sat, 4 Sep 2004, Torsten Roehr wrote: SELECT firstname, lastname, address FROM TABLENAME ORDER BY lastname ASC; Use ASC or DESC to order your query results. When you iterate over the result as Torsten indicated, everything will be in the order you specify. In the database table itself, right? Does it make more sense to do that than to leave the database alone, read it into an array and then sort it anyway I want (there will be at least two different sorted lists I want it to produce)? Sorting in the database should always be the preferred way - should be quicker than doing it in the application in 9 out of 10 times. Thank you. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Newbie Questions
On Thu, 2 Sep 2004, Torsten Roehr wrote: 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']; } I want to display the sorted database. Which makes more sense: sorting the database table itself (either by address or by name), or sorting the array? Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: Newbie Questions
Coming in late on this topic, but... Database. SELECT firstname, lastname, address FROM TABLENAME ORDER BY lastname ASC; Use ASC or DESC to order your query results. When you iterate over the result as Torsten indicated, everything will be in the order you specify. Check out the MySQL docs for all the information you'll ever need on sorting and/or grouping results from a query. Rich -Original Message- From: Pete Holsberg [mailto:[EMAIL PROTECTED] Sent: Friday, September 03, 2004 11:59 AM Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Re: Newbie Questions On Thu, 2 Sep 2004, Torsten Roehr wrote: 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']; } I want to display the sorted database. Which makes more sense: sorting the database table itself (either by address or by name), or sorting the array? Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Newbie Questions
On Wed, 1 Sep 2004, Pete Holsberg wrote: On Wed, 1 Sep 2004, Torsten Roehr wrote: Pete Holsberg [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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? Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Newbie Questions
Pete Holsberg [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Wed, 1 Sep 2004, Pete Holsberg wrote: On Wed, 1 Sep 2004, Torsten Roehr wrote: Pete Holsberg [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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
Re: [PHP-DB] Re: Newbie Questions
On Wed, 1 Sep 2004, Torsten Roehr wrote: Hi Peter, please see my comments below: Pete Holsberg [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm just getting started with PHP and MySQL (how do you say that, my ess kew wll, my sequel, ???). my ess kew wll is the correct pronounciation - after all you know how to spell SQL, don't you? ;) I have a background with C programming and many years ago, I played with dBASE. 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. 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 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. 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! :-) Best regards, Torsten Roehr Thanks, Torsten. Looks like excellent advice. Pete -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php