How can i echo/insert a specific result from a query?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MM

    How can i echo/insert a specific result from a query?

    Hi, I don't know PHP..i use dreamweaver and now i realise it is far from
    enough.
    This code selects from a previous page where the users entered some votes
    and select the 7 products they vote the most.
    I want to be able to make them vote again but with the same products for a
    different question.
    If i could echo each of the results from the query, i could insert each of
    the votes to a new table in the DB (MySql).

    Here's the code...


    <? session_start() ;
    $session_id = session_id();
    ?>
    <?php require_once('C onnections/mariz.php'); ?>
    <?php
    mysql_select_db ($database_mari z, $mariz);
    $result = mysql_db_query( "mariz","SE LECT * FROM table1 WHERE session_id =
    '$session_id' ORDER BY votos1 DESC limit 7");
    while($row = mysql_fetch_arr ay($result)) {
    echo $row["marcas"];
    echo $row["votos1"];
    }
    mysql_free_resu lt($result);
    ?>

    ---------------

    Thanks,

    Manuel


  • Pedro Graca

    #2
    Re: How can i echo/insert a specific result from a query?

    MM wrote:[color=blue]
    > Here's the code...
    >
    >
    ><? session_start() ;
    > $session_id = session_id();
    > ?>
    ><?php require_once('C onnections/mariz.php'); ?>
    ><?php
    > mysql_select_db ($database_mari z, $mariz);
    > $result = mysql_db_query( "mariz","SE LECT * FROM table1 WHERE session_id =
    > '$session_id' ORDER BY votos1 DESC limit 7");
    > while($row = mysql_fetch_arr ay($result)) {
    > echo $row["marcas"];
    > echo $row["votos1"];
    > }
    > mysql_free_resu lt($result);
    > ?>[/color]

    This looks promising ...
    If your table table1 has

    marcas | votos1
    --------+--------
    one | 333
    two | 17
    three | 12
    four | 4

    running that script will output

    one333two17thre e12four4

    you just need a little more HTML formatting to get a nicer looking
    result :)

    Try

    <?php
    # ...
    echo '<table>';
    while($row = mysql_fetch_arr ay($result)) {
    echo '<tr>';
    echo '<td>', $row["marcas"], '</td>';
    echo '<td>', $row["votos1"], '</td>';
    echo '</tr>';
    }
    echo '</table>';
    # ...
    ?>


    substitute (or add to) the <table>, <tr> and <td>
    for <form> and <input> fields
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Dan Tripp

      #3
      Re: How can i echo/insert a specific result from a query?

      Pedro Graca wrote:
      [color=blue]
      > <?php
      > # ...
      > echo '<table>';
      > while($row = mysql_fetch_arr ay($result)) {
      > echo '<tr>';
      > echo '<td>', $row["marcas"], '</td>';
      > echo '<td>', $row["votos1"], '</td>';[/color]
      ^ ^
      | |

      Those commas should be periods, no?

      - Dan

      Comment

      • John Dunlop

        #4
        Re: How can i echo/insert a specific result from a query?

        Dan Tripp wrote:
        [color=blue]
        > Pedro Graca wrote:
        >[color=green]
        > > echo '<td>', $row["votos1"], '</td>';[/color]
        > ^ ^
        > | |
        >
        > Those commas should be periods, no?[/color]

        No. They *could* be. Either is acceptable; even a mixture of commas
        and periods is acceptable. Commas separate parameters. Changing
        them to periods results in a single parameter.

        See example 1:


        --
        Jock

        Comment

        • Pedro Graca

          #5
          Re: How can i echo/insert a specific result from a query?

          Dan Tripp wrote:[color=blue]
          > Pedro Graca wrote:
          >[color=green]
          >> <?php
          >> # ...
          >> echo '<table>';
          >> while($row = mysql_fetch_arr ay($result)) {
          >> echo '<tr>';
          >> echo '<td>', $row["marcas"], '</td>';
          >> echo '<td>', $row["votos1"], '</td>';[/color]
          > ^ ^
          > | |
          >
          > Those commas should be periods, no?[/color]

          // print three things
          echo '<td>', $arr['index'], '</td>';

          // prints the concatenation of three things
          echo '<td>' . $arr['index'] . '</td>';

          // prints a interpolated string
          echo "<td>${arr['index']}</td>";



          All these are perfectly valid.

          I prefer the first because it's easier for me to see what it does
          and, as an added bonus, it's the faster of them.
          --
          --= my mail box only accepts =--
          --= Content-Type: text/plain =--
          --= Size below 10001 bytes =--

          Comment

          Working...