Jump to content

Recommended Posts

I am having a hell of a time getting my MySql table to display...

Here is the code...

 

<?php 

// load the configuration file. 

mysql_connect("localhost","root","xxxxxx"); 

//select which database you want to edit
mysql_select_db("database"); 
        
        $result = mysql_query("SELECT * FROM clients ORDER BY ID",$connect); 

        
        while($myrow = mysql_fetch_assoc($result)) 
             {//begin of loop 

               //now print the results: 
               echo "<b>Policy Number: "; 
               echo $myrow['PolicyNumber']; 
               echo "<b>First Name: "; 
               echo $myrow['First_Name']; 
               echo "<b>Last Name: "; 
               echo $myrow['Last_Name']; 

               echo "<br><a href=\"edit.php?PolicyNumber=$myrow[PolicyNumber]\">Edit</a> 
                 || <a href=\"delete.php?PolicyNumber=$myrow[PolicyNumber]\">Delete</a><br><hr>";

             }//end of loop 

?> 

 

anyone?

Link to comment
https://forums.phpfreaks.com/topic/137758-solved-database-not-displaying-noob/
Share on other sites

You need to put in place some error handling.

 

<?php 

// load the configuration file. 

mysql_connect("localhost","root","xxxxxx"); 

//select which database you want to edit
mysql_select_db("database"); 
        
if ($result = mysql_query("SELECT * FROM clients ORDER BY ID",$connect)) {
  if (mysql_num_rows($result)) { 
    while ($myrow = mysql_fetch_assoc($result)) {//begin of loop 
      //now print the results: 
      echo "<b>Policy Number: "; 
      echo $myrow['PolicyNumber']; 
      echo "<b>First Name: "; 
      echo $myrow['First_Name']; 
      echo "<b>Last Name: "; 
      echo $myrow['Last_Name']; 

      echo "<br><a href=\"edit.php?PolicyNumber={$myrow['PolicyNumber']}\">Edit</a> 
                 || <a href=\"delete.php?PolicyNumber={$myrow['PolicyNumber']}\">Delete</a><br><hr>";

    }//end of loop
  } else {
    echo "No results found";
  }
} else {
  echo mysql_error();
}

?>

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.