Select

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luigi Donatello Asero

    Select

    Hi!

    Can I use this code to show data of column of a certain database
    on the page which I create by writing the following code?
    <?php

    $open = mysql_connect(" localhost", "user", "password") ;

    $data = mysql_db_query( "nameofthedatab ase", "SELECT * FROM nameofthetable
    WHERE nameofthecolumn 1 ORDER BY namneofthecolum n2");

    while ($rad = mysql_fetch_arr ay ($data)) {

    print "<B>";
    print $rad["nameofthecolum n1"];
    print " ";
    print $rad["nameofthecolum n2"];
    print "</B><BR>";
    print "City:";
    print " ";
    print $rad["City"];
    print "<P>";

    }
    ?>



    --
    Luigi ( un italiano che vive in Svezia)









  • Gregory Dean

    #2
    Re: Select

    On 2/7/05 6:24 PM, in article 9NSNd.16713$d5. 136006@newsb.te lia.net, "Luigi
    Donatello Asero" <jaggillarfotbo ll@telia.com> wrote:
    [color=blue]
    > Hi!
    >
    > Can I use this code to show data of column of a certain database
    > on the page which I create by writing the following code?
    > <?php
    >
    > $open = mysql_connect(" localhost", "user", "password") ;
    >
    > $data = mysql_db_query( "nameofthedatab ase", "SELECT * FROM nameofthetable
    > WHERE nameofthecolumn 1 ORDER BY namneofthecolum n2");
    >
    > while ($rad = mysql_fetch_arr ay ($data)) {
    >
    > print "<B>";
    > print $rad["nameofthecolum n1"];
    > print " ";
    > print $rad["nameofthecolum n2"];
    > print "</B><BR>";
    > print "City:";
    > print " ";
    > print $rad["City"];
    > print "<P>";
    >
    > }
    > ?>
    >
    >[/color]

    The "*" in your SELECT statement will return every column in your database.

    $data = mysql_db_query( "nameofthedatab ase", "SELECT nameofthecolumm n1,
    nameofthecolumn 2 FROM nameofthetable) ;

    You can still use the conditional logic "WHERE nameofthecolumn 1 = something"

    You can also still sort the recordset "ORDER BY nameofthecolumn 2"

    -Greg

    Comment

    • Luigi Donatello Asero

      #3
      Re: Select


      "Gregory Dean" <gdean@datapex. com> skrev i meddelandet
      news:BE2D7FFA.4 185%gdean@datap ex.com...[color=blue]
      > On 2/7/05 6:24 PM, in article 9NSNd.16713$d5. 136006@newsb.te lia.net,[/color]
      "Luigi[color=blue]
      > Donatello Asero" <jaggillarfotbo ll@telia.com> wrote:
      >[color=green]
      > > Hi!
      > >
      > > Can I use this code to show data of column of a certain database
      > > on the page which I create by writing the following code?
      > > <?php
      > >
      > > $open = mysql_connect(" localhost", "user", "password") ;
      > >
      > > $data = mysql_db_query( "nameofthedatab ase", "SELECT * FROM[/color][/color]
      nameofthetable[color=blue][color=green]
      > > WHERE nameofthecolumn 1 ORDER BY namneofthecolum n2");
      > >
      > > while ($rad = mysql_fetch_arr ay ($data)) {
      > >
      > > print "<B>";
      > > print $rad["nameofthecolum n1"];
      > > print " ";
      > > print $rad["nameofthecolum n2"];
      > > print "</B><BR>";
      > > print "City:";
      > > print " ";
      > > print $rad["City"];
      > > print "<P>";
      > >
      > > }
      > > ?>
      > >
      > >[/color]
      >
      > The "*" in your SELECT statement will return every column in your[/color]
      database.


      Does that mean that if I use "*" in my SELECT statement
      I should get all the data which are already in the database?
      I tried to send data from a form to the database and to fetch them
      afterwards but no data was shown.
      I only got the data by e-mail.
      The code which I used to send them was:


      <?php if (!isset
      ($_POST['Fornamn']))
      {$Fornamn = $_POST ['Fornamn);}
      else{$Fornamn = 'not set';}
      if (!isset($_POST['Efternamn']))
      {$Efternamn = $_POST ['Efternamn'];}
      else{$Efternamn = 'not set';}



      $connection = mysql_connect(" mysql.scaiecat-spa-gigi.com", "scaiecat_? ",
      "123456")
      or die ("Kunde inte skapa koppling!");
      mysql_select_db ("scaiecat_? ") or die ("Kunde inte välja databas");
      $laggTill="INSE RT INTO formulär
      (Förnamn, Efternamn) Values ('$Fornamn', '$Efternamn');
      mysql_query($la ggTill) or die ("Det gick inte att lägga till information!");
      mysql_close ($connection);
      ?>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">


      <html lang="sv">



      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

      <meta name="keywords" content="Formul äret, förfrågan, semesterbostäde r i
      Italien, semesterboende, turistlägenhete r, boende i Italien för
      fritidsändamål ">
      <meta name="descripti on" content="Formul äret för förfrågan om
      semesterbostäde r i Italien">


      <LINK rel="alternate"
      type="text/html"
      href="../it/benvenuti.html" hreflang="it"
      lang="it" title="Benvenut i alla Scaiecat Spa Gigi">
      <LINK rel="alternate"
      type="text/html"
      href="../fr/bienvenue.html" hreflang="fr"
      lang="fr" title="Bienvenu e à la Scaiecat Spa Gigi ">
      <LINK rel="alternate"
      type="text/html"
      href="../sv/valkommen.html" hreflang="fr"
      lang="fr" title="Bienvenu e à la Scaiecat Spa Gigi ">

      <LINK rel="alternate"
      type="text/html"
      href="../de/willkommen.html " hreflang="de"
      lang="en" title="Willkomm en bei Scaiecat Spa Gigi">



      <link rel=stylesheet href="form2.css " type="text/css">


      <title> Scaiecat Spa Gigi-Formulär för förfrågan om semesterbostäde r i
      Italien</title>






      </head>
      <body>


      <FORM METHOD=POST ACTION="/cgi-bin/formmail.cgi">






      <div id="normal">

      <INPUT TYPE=HIDDEN NAME=recipient
      VALUE="luigi-donatello-asero@scaiecat-spa-gigi.com">




      <DIV CLASS="formular ">


      <LABEL FOR="Fornamn">F örnamn</LABEL>


      <INPUT TYPE="TEXT" NAME="fnamn" id="Fornamn"><b r>

      <LABEL FOR="Efternamn" >Efternamn</LABEL>
      <INPUT TYPE="TEXT" NAME="Efternamn " id="Efternamn" >



      När du klickar på knappen "Skicka" och skickar detta formulär ger du ditt
      samtycke till behandling av dina personuppgifter och bekräftar att du tagit
      del av och godkänner villkoren för förmedling av hyresrätter till bostäder
      för fritidsändamål som anges på denna webbplats.
      <INPUT TYPE=SUBMIT VALUE=Skicka>
      <INPUT TYPE=RESET VALUE=Radera>
      </div>
      </div>
      </FORM>




      </BODY>
      </HTML>



      --
      Luigi ( un italiano che vive in Svezia)








      Comment

      • Gregory Dean

        #4
        Re: Select

        On 2/8/05 9:59 AM, in article _s4Od.16766$d5. 136170@newsb.te lia.net, "Luigi
        Donatello Asero" <jaggillarfotbo ll@telia.com> wrote:
        [color=blue]
        > Does that mean that if I use "*" in my SELECT statement
        > I should get all the data which are already in the database?
        > I tried to send data from a form to the database and to fetch them
        > afterwards but no data was shown.
        > I only got the data by e-mail.[/color]

        Ok, a couple of issues here. First, I assumed you were connecting to a MS
        SQL server but now I realize you are using mySQL. And, some of these
        questions maybe better suited for a PHP forum. But meanwhile, I suggest the
        following:

        After the INSERT statement, query the mySQL database and verify the record
        exists. Your email cgi is using the data from the form fields so there is no
        way to tell if the INSERT statement worked.

        The "*" means RETURN ALL COLUMNS but the conditional logic determines the
        RECORDS that are returned. In the earlier example: " WHERE nameofthecolumn 1"
        would control which records are retuned in the query. Remove and "WHERE"
        statement and get the entire table returned.

        You can email me directly concerning PHP issues.

        -Greg

        Comment

        Working...