Professional Web Applications Themes

newbie question: reading from mysql - PHP Development

Hi, I am trying to read some info from my mysql tables and display it. This is what I have now which works: $select = "SELECT `name` FROM `company` WHERE category = 'Fun';"; $result = mysql_query($select)or die("Invalid query: " . mysql_error()); while ($row = mysql_fetch_assoc($result)) { print $row['name'].'<br>'; That prints out my fun company, but say I want to display more info such as the address, etc. How would I go about that? Thanks in advance!...

  1. #1

    Default newbie question: reading from mysql

    Hi,

    I am trying to read some info from my mysql tables and display it.

    This is what I have now which works:

    $select = "SELECT `name` FROM `company` WHERE category = 'Fun';";
    $result = mysql_query($select)or die("Invalid query: " . mysql_error());

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

    print $row['name'].'<br>';

    That prints out my fun company, but say I want to display more info such as
    the address, etc. How would I go about that?

    Thanks in advance!


    John Guest

  2. #2

    Default Re: newbie question: reading from mysql


    "John" <gt2243amail.gatech.edu> wrote in message
    news:bjc0va$q6h$1news-int.gatech.edu...
    > Hi,
    >
    > I am trying to read some info from my mysql tables and display it.
    >
    > This is what I have now which works:
    >
    > $select = "SELECT `name` FROM `company` WHERE category = 'Fun';";
    > $result = mysql_query($select)or die("Invalid query: " . mysql_error());
    >
    > while ($row = mysql_fetch_assoc($result)) {
    >
    > print $row['name'].'<br>';
    >
    > That prints out my fun company, but say I want to display more info such
    as
    > the address, etc. How would I go about that?
    Add in the field names you want to extract, or use '*' to extract all fields
    in a record

    SELECT name,address,phone,contact,email,category FROM company WHERE
    company.category='fun'
    .....
    print $row["name"]
    print $row["address"]
    print $row["phone"]
    print $row["contact"]
    print $row["email"]
    print $row["category"]

    or

    SELECT * FROM company WHERE company.category='fun'

    >
    > Thanks in advance!
    >
    >

    Richard Hockey Guest

  3. #3

    Default Re: newbie question: reading from mysql

    "Richard Hockey" <richardhockeydsl.pipex.com> wrote in message
    news:3f599ac6$0$247$cc9e4d1fnews.dial.pipex.com.. .
    > Add in the field names you want to extract, or use '*' to extract all
    fields
    > in a record
    >
    > SELECT name,address,phone,contact,email,category FROM company WHERE
    > company.category='fun'
    > ....
    > print $row["name"]
    > print $row["address"]
    > print $row["phone"]
    > print $row["contact"]
    > print $row["email"]
    > print $row["category"]
    >
    > or
    >
    > SELECT * FROM company WHERE company.category='fun'

    Thanks, but what if it's in two different tables? For instance I have
    company info in the company table, and then products listed in a products
    table, etc. I want to print the company name and the company products.



    John Guest

  4. #4

    Default Re: newbie question: reading from mysql

    In article <3f599ac6$0$247$cc9e4d1fnews.dial.pipex.com>,
    [email]richardhockeydsl.pipex.com[/email] says...
    >
    > "John" <gt2243amail.gatech.edu> wrote in message
    > news:bjc0va$q6h$1news-int.gatech.edu...
    > > Hi,
    > >
    > > I am trying to read some info from my mysql tables and display it.
    > >
    > > This is what I have now which works:
    > >
    > > $select = "SELECT `name` FROM `company` WHERE category = 'Fun';";
    > > $result = mysql_query($select)or die("Invalid query: " . mysql_error());
    > >
    > > while ($row = mysql_fetch_assoc($result)) {
    > >
    > > print $row['name'].'<br>';
    > >
    > > That prints out my fun company, but say I want to display more info such
    > as
    > > the address, etc. How would I go about that?
    >
    > Add in the field names you want to extract, or use '*' to extract all fields
    > in a record
    >
    > SELECT name,address,phone,contact,email,category FROM company WHERE
    > company.category='fun'
    > ....
    > print $row["name"]
    > print $row["address"]
    > print $row["phone"]
    > print $row["contact"]
    > print $row["email"]
    > print $row["category"]
    >
    > or
    >
    > SELECT * FROM company WHERE company.category='fun'
    Also, see extract()

    Cheers
    --
    Quod subigo farinam

    $email =~ s/oz$/au/o;
    A: Because it messes up the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet?
    David Robley Guest

  5. #5

    Default Re: newbie question: reading from mysql

    Message-ID: <bjc7np$svu$1news-int.gatech.edu> from John contained the
    following:
    >> SELECT * FROM company WHERE company.category='fun'
    >
    >
    >Thanks, but what if it's in two different tables? For instance I have
    >company info in the company table, and then products listed in a products
    >table, etc. I want to print the company name and the company products.
    Do you have the company ID as a foreign key in the product table?

    SELECT* FROM company,products WHERE company.catid=products.catid;

    --
    Geoff Berrow
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
    Geoff Berrow Guest

  6. #6

    Default Re: newbie question: reading from mysql

    "Geoff Berrow" <$bl$ckdog.co.uk> wrote in message
    news:hudjlvkc138uk3tif49nq3onm852atg8bn4ax.com...
    >
    > Do you have the company ID as a foreign key in the product table?
    >
    > SELECT* FROM company,products WHERE company.catid=products.catid;
    Thanks but what if I have more than one company?

    For instance, among all the companies, I just want info from fun company and
    nofun company. I want to get just the name of the company and products they
    provide. Is there a way I can combine the WHERE stuff?

    For instance:

    SELECT 'name','product' FROM 'company','products' WHERE
    category='fun',company.catid=products.catid';

    Is that right? I'm guessing no cuz I get the following error:

    Invalid query: You have an error in your SQL syntax. Check the manual that
    corresponds to your MySQL server version for the right syntax to use near
    'company.catid=products.catid' at line 1



    John Guest

  7. #7

    Default Re: newbie question: reading from mysql

    Message-ID: <bjdh4p$gd8$1news-int.gatech.edu> from John contained the
    following:
    >SELECT 'name','product' FROM 'company','products' WHERE
    >category='fun',company.catid=products.catid';
    >
    >Is that right? I'm guessing no
    You guess correctly. :-)

    SELECT name,product FROM company,products WHERE
    category='fun' AND company.catid=products.catid;

    It might be an idea to try a few SQL tutorials or get a book. Also it's not
    really a PHP topic.

    --
    Geoff Berrow
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
    Geoff Berrow Guest

  8. #8

    Default Re: newbie question: reading from mysql

    "Geoff Berrow" <$bl$ckdog.co.uk> wrote in message
    news:kvjklvc2kqcsnfro6d0p557f1m2f30md5b4ax.com...
    >
    > SELECT name,product FROM company,products WHERE
    > category='fun' AND company.catid=products.catid;
    >
    > It might be an idea to try a few SQL tutorials or get a book. Also it's
    not
    > really a PHP topic.
    >
    whoops! my fault, thanks :-)


    John Guest

Similar Threads

  1. newbie question with php and mysql
    By levels in forum Macromedia Dynamic HTML
    Replies: 4
    Last Post: August 25th, 12:18 PM
  2. Creating datasource with mysql- newbie question
    By Hydrowizard in forum Coldfusion Database Access
    Replies: 1
    Last Post: January 13th, 08:17 PM
  3. help newbie with reading XML problem
    By hsin in forum Macromedia Flash
    Replies: 2
    Last Post: January 28th, 11:51 PM
  4. newbie question: using DBI, DBI::mysql
    By sstark@nospam.com in forum PERL Modules
    Replies: 0
    Last Post: November 9th, 10:06 PM
  5. newbie php MySQL table question
    By Noel Ferguson in forum PHP Development
    Replies: 0
    Last Post: July 24th, 08:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139