Jump to content

Recommended Posts

I am reading the table passwords to see if the password exists. If true then read the table airplanes and output a table with the data. If the password is not in the table, then output msg AMA Number Not Found. All of this works.

 

My problem is if it does not find the password, it echos the msg, but it also echos the talble headers. I would like to goto end, skip the echo of the table if it does not find the password. Just can't figure out how to do it.

 

<html>
<head>
</head>
<body>
<?php
// Connect to database=====================================================

include("connect_db.php"); 
$table1='passwords';
$table2='airplanes';

// Retrieve form data ======================================================

$amano = $_POST['amano']; 

// Send password query ===========================================================

$result = mysql_query("SELECT * FROM $table1
WHERE ama='$amano'") or die(mysql_error());  

if (!$result) {
    die("Query to show fields from table failed");
}

// Check if AMA number found in password file =============================

$num=mysql_numrows($result);
if ($num==0) {
echo "AMA Number Not Found";
} else {
echo "Record Found";
}

// Send airplanes query ===========================================

$result = mysql_query("SELECT * FROM $table2
WHERE ama='$amano'") or die(mysql_error());  

if (!$result) {
    die("Query to show fields from table failed");
}

echo "<table border='10' cellpadding='3' cellspacing='2'>";
echo "<p>Airplanes for Joe Blow</p><br>";

echo "<tr> <th>ID</th> <th>AMA #</th> <th>Model Name</th> <th>Model MFG</th><th>Wingspan</th><th>Engine</th><th>Decibels</th></tr>";

// keeps getting the next row until there are no more to get ================

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

// Print out the contents of each row into a table ==========================

echo "<tr><td>";
echo $row['id'];
echo "</td><td>"; 
echo $row['ama'];
echo "</td><td>"; 
echo $row['model_name'];
echo "</td><td>"; 
echo $row['model_mfg'];
echo "</td><td>"; 
echo $row['wingspan'];
echo "</td><td>"; 
echo $row['engine'];
echo "</td><td>"; 
echo $row['decibels'];
echo "</td></tr>"; 
} 

echo "</table>";
?>
<br>
Put something here.
<body>
</html>

 

Thanks,

 

Curtis

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/226274-sure-wish-php-had-a-goto-statement/
Share on other sites

Actually, php.net just added it in php5.3 so that php help forums like this one will get more traffic  :hail_freaks:

 

that's disturbing. oh well, in the long run it will mean more work for geeks like me that make a decent living fixing the mistakes of others.

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.