Problem displaying mysql records:

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

    #1

    Problem displaying mysql records:

    Hello,

    I wondered if anyone could offer some guidance, I trying to write a
    php script to connect to a database, and display the records in a
    table.

    I found the code here in a php4 text, and when I run this directly
    through the php intrupeter, the line Successfully connected is display
    and 4 as the number of rows.

    The database table we connect to, has three field username, firstname,
    surname.

    When I tried a while loop, to display the data in a table. No values
    were displayed.

    Could anyone possibly demonstrate how to display the username,
    firstname, surname values in a basic table?

    Thank you


    <?php
    function db_connect(){
    global $MYSQL_ERRNO, $MYSQL_ERROR;

    $link_id = mysql_connect(" localhost","use r04", "password04 ");

    if(!$link_id){
    $MYSQL_ERROR = "Connection failed";
    return 0;
    }
    else if(empty($dbnam e) && !mysql_select_d b("database04") ){
    $MYSQL_ERROR = mysql_error();
    return 0;
    } else return $link_id;
    }

    !$link_id = db_connect();
    if(!$link_id) die(error_messa ge('Error connecting'));

    $result = mysql_query("SE LECT * FROM users");
    if(!$result) error_message(' Error in selection');
    else echo "Successful ly connected. ";

    $query_data = mysql_fetch_arr ay($result);
    $total_records = $query_data[0];

    if(!$total_reco rds) error_message(' No records');
    else echo "$total_records .";
    ?>
  • Sadara

    #2
    Re: Problem displaying mysql records:

    Antoni wrote:[color=blue]
    > Hello,
    >
    > I wondered if anyone could offer some guidance, I trying to write a
    > php script to connect to a database, and display the records in a
    > table.
    >
    > I found the code here in a php4 text, and when I run this directly
    > through the php intrupeter, the line Successfully connected is display
    > and 4 as the number of rows.
    >
    > The database table we connect to, has three field username, firstname,
    > surname.
    >
    > When I tried a while loop, to display the data in a table. No values
    > were displayed.
    >
    > Could anyone possibly demonstrate how to display the username,
    > firstname, surname values in a basic table?
    >
    > Thank you
    >
    >
    > <?php
    > function db_connect(){
    > global $MYSQL_ERRNO, $MYSQL_ERROR;
    >
    > $link_id = mysql_connect(" localhost","use r04", "password04 ");
    >
    > if(!$link_id){
    > $MYSQL_ERROR = "Connection failed";
    > return 0;
    > }
    > else if(empty($dbnam e) && !mysql_select_d b("database04") ){
    > $MYSQL_ERROR = mysql_error();
    > return 0;
    > } else return $link_id;
    > }
    >
    > !$link_id = db_connect();
    > if(!$link_id) die(error_messa ge('Error connecting'));
    >
    > $result = mysql_query("SE LECT * FROM users");
    > if(!$result) error_message(' Error in selection');
    > else echo "Successful ly connected. ";
    >
    > $query_data = mysql_fetch_arr ay($result);
    > $total_records = $query_data[0];
    >
    > if(!$total_reco rds) error_message(' No records');
    > else echo "$total_records .";
    > ?>[/color]

    try:

    while ($query_data = mysql_fetch_arr ay($result)) {
    echo $query_data['username'].'|'.$query_dat a['firstname'].
    '|'.$query_data['surname'] ;
    }

    sadara

    Comment

    • Antoni

      #3
      Re: Problem displaying mysql records:

      Thank you for replying.

      I managed to display the mysql data in a table.

      I resolved this by providing the position of each data item in the
      rows, such as $query_data[0];

      My php version did not seems to like $query_data["username"];

      Anyway its working now.

      Comment

      • Antoni

        #4
        Re: Problem displaying mysql records:

        Thank you for replying.

        I managed to display the mysql data in a table.

        I resolved this by providing the position of each data item in the
        rows, such as $query_data[0];

        My php version did not seems to like $query_data["username"];

        Anyway its working now.

        Comment

        • Antoni

          #5
          Re: Problem displaying mysql records:

          Thank you for replying.

          I managed to display the mysql data in a table.

          I resolved this by providing the position of each data item in the
          rows, such as $query_data[0];

          My php version did not seems to like $query_data["username"];

          Anyway its working now.

          Comment

          • Antoni

            #6
            Re: Problem displaying mysql records:

            Thank you for replying.

            I managed to display the mysql data in a table.

            I resolved this by providing the position of each data item in the
            rows, such as $query_data[0];

            My php version did not seems to like $query_data["username"];

            Anyway its working now.

            Comment

            Working...