SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Can any one tell me that how I can retrieve the data from the database. And then print it in the table. I'm using the PHP3 and my sql.

    I Realy need your help

    Thank you
    Aneal

  2. #2
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you already created a database? Do you know the names of the tables that you want to retrieve the information from?

    It sounds like you don't have any previous experience with PHP and mySQL. Your best bet would be to read your way through this tutorial on SitePoint:

    www.webmasterbase.com/article.php/228

    That will teach you pretty much everything you need to know about accesing mySQL databases using PHP.

    If you just want to view tables in a database that has already been created your best bet is a tool called phpMyAdmin. This is an easy to install script that will allow you to access and view all of the tables in your database, as well as edit information and create new databases / tables / fields. Download it from this site:

    www.phpwizards.net

    If that hasn't answered your query you'll need to be more specific in what you need help with.

    Cheers,

    Skunk

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you are right I'm working on my first project and using the PHP and Mysql. Tried all the manuals and books but no one tells how to get the data from database to pring multiple rows by using the only one query or the sql statement.

    Here is what I'm doing:

    include "database_connect.php3";
    $link = connect_dbs($hostname, $username, $password, $dbname);

    $result = mysql_query("select * from user");

    echo"<table>\n";
    while ($row=mysql_fetch_array($result))
    {
    printf("<tr><td>".$row["student"],"</td>");

    printf("<td>".$row["content"],"</td>");
    printf("<td>".$row["uniqueness"],"</td>");
    printf("<td>".$row["visual"],"</td>");
    printf("<td>".$row["graphics"],"</td>");
    printf("<td>".$row["layout"],"</td>");
    printf("<td>".$row["info"],"</td>");
    printf("<td>".$row["nav"],"</td>");
    printf("<td>".$row["speed"],"</td>");
    printf("<td>".$row["useful"],"</td>");
    printf("<td>".$row"[satisfied"],"</td></tr><br>\n");
    reset ($row);
    }
    echo"</table>";
    mysql_free_result($result);

    It is printing the output, not problem. The second part of my code is I want to print the two more tables with the same query but with the different while loop. How is it posible.
    Aneal

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can't. If you want to print out information from another table, you have to use another query and another while loop (see below). Also, you are incorrectly using the printf() function to display the table. You should use echo instead:

    echo '<tr><td>' . $row['student'] . '</td>';

    Also, when strings do not contain variables, you should use single quotes.
    Code:
    $result = mysql_query("select * from user"); 
    
    echo"<table>\n"; 
    while ($row=mysql_fetch_array($result)) 
    { 
    printf("<tr><td>".$row["student"],"</td>"); 
    printf("<td>".$row["content"],"</td>"); 
    printf("<td>".$row["uniqueness"],"</td>"); 
    printf("<td>".$row["visual"],"</td>"); 
    printf("<td>".$row["graphics"],"</td>"); 
    printf("<td>".$row["layout"],"</td>"); 
    printf("<td>".$row["info"],"</td>"); 
    printf("<td>".$row["nav"],"</td>"); 
    printf("<td>".$row["speed"],"</td>"); 
    printf("<td>".$row["useful"],"</td>"); 
    printf("<td>".$row"[satisfied"],"</td></tr><br>\n"); 
    } 
    echo"</table>"; 
    
    $result = mysql_query("select * from table2"); 
    
    echo"<table>\n"; 
    while ($row=mysql_fetch_array($result)) 
    { 
    printf("<tr><td>".$row["student"],"</td>"); 
    
    printf("<td>".$row["content"],"</td>"); 
    printf("<td>".$row["uniqueness"],"</td>"); 
    printf("<td>".$row["visual"],"</td>"); 
    printf("<td>".$row["graphics"],"</td>"); 
    printf("<td>".$row["layout"],"</td>"); 
    printf("<td>".$row["info"],"</td>"); 
    printf("<td>".$row["nav"],"</td>"); 
    printf("<td>".$row["speed"],"</td>"); 
    printf("<td>".$row["useful"],"</td>"); 
    printf("<td>".$row"[satisfied"],"</td></tr><br>\n"); 
    } 
    echo"</table>"; 
    
    $result = mysql_query("select * from table3"); 
    
    echo"<table>\n"; 
    while ($row=mysql_fetch_array($result)) 
    { 
    printf("<tr><td>".$row["student"],"</td>"); 
    
    printf("<td>".$row["content"],"</td>"); 
    printf("<td>".$row["uniqueness"],"</td>"); 
    printf("<td>".$row["visual"],"</td>"); 
    printf("<td>".$row["graphics"],"</td>"); 
    printf("<td>".$row["layout"],"</td>"); 
    printf("<td>".$row["info"],"</td>"); 
    printf("<td>".$row["nav"],"</td>"); 
    printf("<td>".$row["speed"],"</td>"); 
    printf("<td>".$row["useful"],"</td>"); 
    printf("<td>".$row"[satisfied"],"</td></tr><br>\n"); 
    } 
    echo"</table>";
    Last edited by 7stud; May 24, 2001 at 00:30.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Atlanta
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou for your tips. I realy appriciate for that.
    I think I wasn't able to ask my question in right way.

    Actualy I only have one table named user. And I need data from that one table which will be display in many tables. What I want is the text report for data I have in the 'user' table.

    Aneal
    Aneal


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
  •