GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Jul-2004, 23:06
cmarti cmarti is offline
New Member
 
Join Date: Jul 2004
Posts: 5
cmarti is on a distinguished road

Displaying all rows with same ID


Hey everyone, I am having a problem displaying all rows with the same ID. I have two entries in my database with the same ID, but only one is being displayed. I think I need a while loop but I'm not sure how to intigrate one with what I have.
PHP Code:

<?
$conn = mysql_connect("localhost","databaseUsername","databasePassword");
$db = mysql_select_db("databaseName");

// takes info from form
$username = $_POST["StuUserID"];
$password = $_POST["StudPassword"];

$result = MYSQL_QUERY("select * from User_Info, GradeBook where User_Info.stuID=GradeBook.stuID AND User_Info.StuID='$username'and User_Info.Password='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

$username = $worked[StuID];
$password = $worked[Password];
$fname = $worked[FirstName];
$lname = $worked[LastName];
$cname = $worked[ClassName];
$glevel = $worked[GradeLevel];
$assign = $worked[Assignment];
$grade = $worked[Grade];
$comments = $worked[Comments];
$dposted = $worked[DatePosted];

if($worked) {
   include "header.php";
   echo "<br><center>Welcome $fname!</center><br><div align=center>
  <center>
  <table border=1 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 id=AutoNumber1>
    <tr>
      <td>Class Name</td>
      <td>Assignment</td>
      <td>Grade</td>
      <td>Date Posted</td>
      <td>Comments</td>
    </tr>
    <tr>
      <td>$cname</td>
      <td>$assign</td>
      <td>$grade</td>
      <td>$dposted</td>
      <td>$comments</td>
    </tr>
  </table>
  </center>
</div><br>"; 
   include "footer.php";  

} else {
  include "header.php";
  echo "<br><br><b><center>Sorry, Name and password not found or not matched</center></b><br><br>";
  include "footer.php";
}
?>

Any help is greatly appreciated!
  #2  
Old 26-Jul-2004, 06:06
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello cmarti,

Assume the following:

PHP Code:

<?php
// ... php code snipped

$result = MYSQL_QUERY("select * from User_Info, GradeBook where User_Info.stuID=GradeBook.stuID AND User_Info.StuID='$username'and User_Info.Password='$password'")
   or die ("Name and password not found or not matched");

// Assuming there are no problems with this query...
// you could echo out the beginning of the table markup.
   include "header.php";
   echo "<br><center>Welcome $fname!</center><br><div align=center>
  <center>
  <table border=1 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 id=AutoNumber1>
    <tr>
      <td>Class Name</td>
      <td>Assignment</td>
      <td>Grade</td>
      <td>Date Posted</td>
      <td>Comments</td>
    </tr>";

// NOW, you can loop the SQL results...
$table_rows = '';
while( $worked = mysql_fetch_assoc($result) )
{
    $table_rows .= "<tr>
      <td>$worked[ClassName]</td>
      <td>$worked[Assignment]</td>
      <td>$worked[Grade]</td>
      <td>$worked[DatePosted]</td>
      <td>$worked[Comments]</td>
    </tr> ";
}
if( $table_rows )
    echo $table_rows;
else
    echo '<tr><td colspan="5">Nothing Found!</td></tr>';

// close the table
echo "</table>
  </center>
</div><br>";
// ... other php code
?>

  #3  
Old 26-Jul-2004, 09:42
cmarti cmarti is offline
New Member
 
Join Date: Jul 2004
Posts: 5
cmarti is on a distinguished road

Thank you JDS


Thanks JDS,
That is definitely much cleaner.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying array of points Nelly C++ Forum 0 26-May-2004 06:29
opening files and displaying text pin215 C++ Forum 7 21-Feb-2004 22:27
Having problems displaying a line of variable length using winio. warny_maelstrom C Programming Language 8 15-Feb-2004 12:56
Displaying the Post Number BobbyDouglas Open Discussion Forum 4 10-Oct-2003 11:43
Displaying Code Using Notepad BobbyDouglas Web Design Forum 1 16-Aug-2003 07:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:55.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.