Jump to content

[SOLVED] Something is Broken and I can't figure it out


PrettyHotProgrammer

Recommended Posts

Here is my code...

Configuration.php has all the variables for Database Hostname username password... I know the connection works..

 

<?php

include("configuration.php");

if (!($db = mysql_pconnect($hostname, $username , $password))){

die("Can't connect to database server.");

}else{

// select a database

 

if (!(mysql_select_db("$database",$db))){

die("Can't connect to database.");

}

}

 

$result = mysql_query("SELECT * FROM Assignment");

 

$num_rows = mysql_num_rows($result);

 

$i = 0;

 

echo"<table width="100%" border="0">";

echo"<tr>

<td></td>

<td>Assignment ID</td>

<td>Title</td>

<td>School ID</td>

<td>Description</td>

</tr>";

 

while($i < $num_rows+1)

{

$query = "Select * from Assignment where AssnID = $i";

                                $result = mysql_query($query);

$row = mysql_fetch_array($result);

echo"

<tr>

<td>$row[1]</td>

<td>$row[2]</td>

<td>$row[3]</td>

<td>$row[4]</td>

</tr>

";

}

echo"</table>";

?>

 

Thanks in advanced!!

Link to comment
Share on other sites

are your column names numbers? If so(which is a horrible idea and might not even work correctly), you need to make your while statement into:

 

while($row = mysql_fetch_array($result))
{
  stuff with $row[1] and so on
}

but if your column names are things like id, name, email, etc then you'd have to do $row[id], $row[name], etc

Link to comment
Share on other sites

Ok I have bolded the errors or things you need to fix

 

<?php
   include("configuration.php");
      if (!($db = mysql_pconnect($hostname, $username , $password))){
         die("Can't connect to database server.");
      }else{
         // select a database
         
         if (!(mysql_select_db("$database",$db))){
            die("Can't connect to database.");
         }
      }
      
      $result = mysql_query("SELECT * FROM Assignment");

      $num_rows = mysql_num_rows($result);
      
      $i = 0;
      
      echo"<table width="100%" border="0">";
      echo"<tr>
               <td>[b]$nbsp;[/b]</td>
               <td>Assignment ID</td>
               <td>Title</td>
               <td>School ID</td>
               <td>Description</td>
            </tr>";
            
      while([b]$row = mysql_fetch_array($result)[/b])
      {
            $query = "Select * from Assignment where AssnID = [b]'$i'[/b]"; // you need single quotes around the variable
                                $result = mysql_query($query);
           ;
         echo"
            <tr>
               [b]<td>$row['column_name']</td>
               <td>$row['column_name']</td>
               <td>$row['column_name']</td>
               <td>$row['column_name']</td>
               <td>$row['column_name']</td>[/b]
            </tr>   
         ";
         [b]$i++[/b]
      }
      echo"</table>";
   ?>

 

EDIT: well, apparently it won't bold if the text is in code tags. Oh well, look for the [ b] tags

Link to comment
Share on other sites

This is now my code... Still White Screen...

I am used to programming in C# where when there is a problem you can step through it and find where it is not doing what it is supposed to... This is the Reason I should stay with my Windows Forms Programming haha

 

<?php

  include("config.php");

      if (!($db = mysql_pconnect($hostname, $username , $password))){

        die("Can't connect to database server.");

      }else{

        // select a database

       

        if (!(mysql_select_db("$database",$db))){

            die("Can't connect to database.");

        }

      }

     

      $result = mysql_query("SELECT * FROM Assignment");

 

      $num_rows = mysql_num_rows($result);

     

      $i = 0;

     

      echo"<table width="100%" border="0">";

      echo"<tr>

              <td>$nbsp;</td>

              <td>Assignment ID</td>

              <td>Title</td>

              <td>School ID</td>

              <td>Description</td>

            </tr>";

           

      while($row = mysql_fetch_array($result))

      {

            $query = "Select * from Assignment where AssnID = '$i'";

                                $result = mysql_query($query);

        echo"

            <tr>

              <td>$nbsp;</td>

              <td>$row['Assignment']</td>

              <td>$row['Title']</td>

              <td>$row['SchoolID']</td>

              <td>$row['Description']</td>

            </tr> 

        ";

        $i++

      }

      echo"</table>";

  ?>

Link to comment
Share on other sites

You need to run this:

 

$result = mysql_query("SELECT * FROM Assignment");

while($row = mysql_fetch_array($result)) {

echo"

            <tr>

              <td>$nbsp;</td>

              <td>$row['Assignment']</td>

              <td>$row['Title']</td>

              <td>$row['SchoolID']</td>

              <td>$row['Description']</td>

            </tr> 

        ";

}

Link to comment
Share on other sites

Thank you all for all of you help... I finally figured it out it was a pain but i found it on ScriptPlayground

 

here is the code for future people looking for this!!

 

 <?php
include("config.php");

if (!($db = mysql_pconnect($hostname, $username , $password))){
         die("Can't connect to database server.");
      }else{
         // select a database
         
         if (!(mysql_select_db("$database",$db))){
            die("Can't connect to database.");
         }
      }

function display_db_query($query_string, $header_bool, $table_params)
{
// perform the database query
	$result_id = mysql_query($query_string)
		or die("display_db_query:" . mysql_error());

// find out the number of columns in result
	$column_count = mysql_num_fields($result_id)
		or die("display_db_query:" . mysql_error());

// Here the table attributes from the $table_params variable are added
	print("<TABLE $table_params >\n");

// optionally print a bold header at top of table
	if ($header_bool)
	{
		print("<TR>");
		for ($column_num = 0; $column_num < $column_count; $column_num++)
		{
			$field_name = mysql_field_name($result_id, $column_num);
			print("<TH>$field_name</TH>");
		}
		print("</TR>\n");
	}

// print the body of the table
	while ($row = mysql_fetch_row($result_id))
	{
		print("<TR ALIGN=LEFT VALIGN=TOP>"); 
		for ($column_num = 0; $column_num < $column_count; $column_num++)
		{
			print("<TD>$row[$column_num]</TD>\n");
		}
		print("</TR>\n");
	}
	print("</TABLE>\n"); 
}

function display_db_table($tablename, $header_bool, $table_params)
{
$query_string = "SELECT * FROM $tablename";
display_db_query($query_string,$header_bool, $table_params);
}
?>
        <TABLE border="2">
                <TR>
                    <TD>
					<?php
                        //In this example the table name to be displayed is  static, but it could be taken from a form
                        $table = $assignmentTable;
                        
                        display_db_table($table, $global_dbh, TRUE, "border='0'");
                        ?>
                    </TD>
                </TR>
        </TABLE>      
    </body>
</html>

Link to comment
Share on other sites

There was 2 errors in the code I gave.

 

one was you need to remove the single quotes in the $row array when it's been put in double quotes.

 

Second was remove the query that was called within the while statement. That should do it. I'm sorry you had to find the script somewhere and that it works... bc that means you probably have no idea why your previous code wasnt working. :( not a good way to solve problems

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.