?
Solved

how to show all the recult inside the table

Posted on 2009-02-16
4
Medium Priority
?
164 Views
Last Modified: 2013-12-13
i want to show all the result in a table "machine" in MySQL to the table inside the html , how to do it?

each cell inside the table store one parameter ( time , date and name ) of each staff ~
how ?

thanks

$con = mysql_connect(localhost, root, 1234567);
	if (!$con)
  	{
  		die('Could not connect: ' . mysql_error());
  	}
	mysql_select_db(final)or die("cannot select DB");
$result = mysql_query("select * from  machine order by ID desc limit 4");
$r=mysql_fetch_assoc($result);
	//while($r=mysql_fetch_assoc($result))
  //var_dump($r);
 
 
 
 
html part:
  <table width="500" border="0">
            <tr>
              <td colspan="2"><h1 class="style19">abc</h1></td>
            </tr>
            <tr>
              <
            </tr>
            
           
            <tr>
              <td height="48" colspan=""><table width="438" height="239" border="1">
                <tr>
                  <th scope="row">staff</th>
                  <td><h1>Date</h1></td>
                  <td><h1>Time</h1></td>
                  <td><h1>Name</h1></td>
                </tr>
                <tr>
                  <th scope="row">1.</th>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <th scope="row">2.</th>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <th scope="row">3.</th>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <th scope="row">4.</th>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
              </table>

Open in new window

0
Comment
Question by:ftpphptest1
  • 3
4 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 23653205
You said you want all rows, but you have limit 4 in the query and show a html table with 4 data rows...?

You must make a loop:

 


while($r=mysql_fetch_assoc($result))
  echo '<tr>'.
       '<th scope="row">'.$row['staff'].'</th>'.
       '<td>'.$row['date'].'</td>'.
       '<td>'.$row['time'].'</td>'.
       '<td>'.$row['name'].'</td>'.
       '</tr>';

Open in new window

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 23653216
The provided code produces the data rows, you must output the start of the table including column headings before the loop, and end the table with </table> after the loop.
0
 

Author Comment

by:ftpphptest1
ID: 23653250
nono~~~the last 4 record inside the table
and i can not show the data using ur code ~
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 1000 total points
ID: 23653621
Sorry, I mixed up the variable name $r/$row. It should be like this:
while($row = mysql_fetch_assoc($result))
  echo '<tr>'.
       '<th scope="row">'.$row['staff'].'</th>'.
       '<td>'.$row['date'].'</td>'.
       '<td>'.$row['time'].'</td>'.
       '<td>'.$row['name'].'</td>'.
       '</tr>';

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question