php code to retrieve latest data from mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TKB
    New Member
    • Nov 2006
    • 8

    php code to retrieve latest data from mysql

    I have the following code and I want to retrieve the latest data from mysql and have it inside a table I have created. Could anyone tell me what's wrong with it?

    Thank you in advance for your effort.

    <td>Category Name :
    </td>
    <td><?php
    $query= "SELECT * FROM categories;
    $result = mysql_query($qu ery);
    $num=mysql_numr ows($result);
    mysql_close();
    if ($num>1) {
    $to=1;
    }else{
    $to=$num;
    }
    $i=0;
    while($i<$to){
    $categoryname=m ysql_result($re sult,$i,categor yname);
    $i++;
    }
    ?></td>
    </tr>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Put your code within code, php or html tags, so we can read it! (see Posting Guidelines at top of this forum).

    Ronald :cool:

    Comment

    • TKB
      New Member
      • Nov 2006
      • 8

      #3
      Originally posted by ronverdonk
      Put your code within code, php or html tags, so we can read it! (see Posting Guidelines at top of this forum).

      Ronald :cool:

      I'm sorry for the mistake.

      I have re-written a code with which I want each time a member logs in and places an order when they click on the view my order button to have results according to their username and password. Could you please help me out?
      [php]
      <?php
      $_SESSION['logged_in'] = TRUE;
      $query = "SELECT * FROM categories";
      $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
      ?>
      <select name="categoryn ame" id="categorynam e">
      <option value="">&nbsp; </option>
      <?php
      while ($line = mysql_fetch_arr ay($result, MYSQL_NUM))
      {
      echo "<option value=\"".$line[0]."\"> ".$line[1]." </option>" ;
      }
      mysql_free_resu lt($result);

      ?>
      </select>[/php]
      Edited to make it READABLE! - Ronald :cool:

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by TKB
        I'm sorry for the mistake.

        I have re-written a code with which I want each time a member logs in and places an order when they click on the view my order button to have results according to their username and password. Could you please help me out?
        [php]
        <?php
        $_SESSION['logged_in'] = TRUE;
        $query = "SELECT * FROM categories";
        $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
        ?>
        <select name="categoryn ame" id="categorynam e">
        <option value="">&nbsp; </option>
        <?php
        while ($line = mysql_fetch_arr ay($result, MYSQL_NUM))
        {
        echo "<option value=\"".$line[0]."\"> ".$line[1]." </option>" ;
        }
        mysql_free_resu lt($result);

        ?>
        </select>[/php]
        Edited to make it READABLE! - Ronald :cool:
        Do I understand correctly that you want, after a user has clicked on one of the items in the selection list, to display a list of what they have ordered?

        And, if so, do you want that (a) immediately after the select option is clicked or (b) after the user hits the submit button?
        In the former case (a) you need JavaScript to capture the onclick event, in the latter case (b) you can just handle it via this same script using PHP.

        Ronald :cool:

        Comment

        • TKB
          New Member
          • Nov 2006
          • 8

          #5
          What I want is after a user hits the submit button to display a list of what he/she has ordered.I'm dealing only with php code hence the b paragraph is of my concern.

          Awaiting your response with many thanks.

          TKB

          Originally posted by ronverdonk
          Do I understand correctly that you want, after a user has clicked on one of the items in the selection list, to display a list of what they have ordered?

          And, if so, do you want that (a) immediately after the select option is clicked or (b) after the user hits the submit button?
          In the former case (a) you need JavaScript to capture the onclick event, in the latter case (b) you can just handle it via this same script using PHP.

          Ronald :cool:

          Comment

          Working...