Jump to content

Recommended Posts

Hi

 

I've been working from some tutorials that are currently inaccessible due to the creator being out of bandwidth, and have hit a snag.

 

I've had some assistance generating a section of code that displays an error message if the database cannot find anything to meet the user request.  I've changed quite a lot of the code, and somewhere amongst this, I have lost the "bit" that puts all of the data into a tabular format.  I've tried several things to get the right result, but no luck so far.

 

Can anyone assist me, please?

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html><head><title>Virtual Stud Book</title> 
<link rel="stylesheet" type="text/css" href="/style/style.css"/> 
</head>

	<?php include("../style/template.php");?>

<body>
<div id="main">

<?php $connection = mysql_connect("*****", "*****", "*****");
if (!$connection)
{die('Could not connect: ' . mysql_error());}

// Create database
//if (mysql_query("CREATE DATABASE horses",$connection))
//  {
// echo "Database created";
// }
//else
// {
// echo "Error creating database: " . mysql_error();
// }

// Create table in my_db database
mysql_select_db("virtualstu", $connection);

// select record fields from database table and check for results
$sql="SELECT * FROM horses 
	       WHERE breed='Arabian' AND gender='stallion' AND allowed='OK' ORDER BY points DESC";

if (!mysql_query($sql,$connection))
{die('Error: ' . mysql_error());}

$mysql_result=mysql_query($sql,$connection);
$num_rows=mysql_num_rows($mysql_result);
if ($num_rows == 0)
{echo "Sorry, we have no records for Arabian stallions.";} 

else 
{
echo "<TR>
<TH>Name</TH>
<TH>Horse ID</TH>
<TH>Player ID</TH>
<TH>Type</TH>
<TH>Points</TH>
<TH>Goal</TH>
<TH>Max Foals</TH>
<TH>Breeding Style</TH>
<TH>Fee</TH>
</TR>";

// table population
while ($row=mysql_fetch_array($mysql_result))
{
$name=$row["name"];
$horse_id=$row["horse_id"];
$player_id=$row["player_id"];
$horse_type=$row["horse_type"];
$points=$row["points"];
$goal=$row["goal"];
$max_foals=$row["max_foals"];
$breeding_type=$row["breeding_type"];
$fee=$row["fee"];

// results
echo " <TR>
<TD>$name</TD>
<TD>$horse_id</TD>
<TD>$player_id</TD>
<TD>$horse_type</TD>
<TD>$points</TD>
<TD>$goal</TD>
<TD>$max_foals</TD>
<TD>$breeding_type</TD>
<TD>$fee</TD>
</TR>";
}
}

</table>
mysql_close($connection);
?>

</body>
</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/83613-solved-tabulating-results/
Share on other sites

Try to replace

 

else 
{
echo "<TR>
<TH>Name</TH>
<TH>Horse ID</TH>
<TH>Player ID</TH>
<TH>Type</TH>
<TH>Points</TH>
<TH>Goal</TH>
<TH>Max Foals</TH>
<TH>Breeding Style</TH>
<TH>Fee</TH>
</TR>";

// table population
while ($row=mysql_fetch_array($mysql_result))
{
$name=$row["name"];
$horse_id=$row["horse_id"];
$player_id=$row["player_id"];
$horse_type=$row["horse_type"];
$points=$row["points"];
$goal=$row["goal"];
$max_foals=$row["max_foals"];
$breeding_type=$row["breeding_type"];
$fee=$row["fee"];

// results
echo " <TR>
<TD>$name</TD>
<TD>$horse_id</TD>
<TD>$player_id</TD>
<TD>$horse_type</TD>
<TD>$points</TD>
<TD>$goal</TD>
<TD>$max_foals</TD>
<TD>$breeding_type</TD>
<TD>$fee</TD>
</TR>";
}
}

</table>
mysql_close($connection);
?>

 

with

 

else 
{
echo "<TABLE><TR>
<TH>Name</TH>
<TH>Horse ID</TH>
<TH>Player ID</TH>
<TH>Type</TH>
<TH>Points</TH>
<TH>Goal</TH>
<TH>Max Foals</TH>
<TH>Breeding Style</TH>
<TH>Fee</TH>
</TR>";

// table population
while ($row=mysql_fetch_array($mysql_result))
{
$name=$row["name"];
$horse_id=$row["horse_id"];
$player_id=$row["player_id"];
$horse_type=$row["horse_type"];
$points=$row["points"];
$goal=$row["goal"];
$max_foals=$row["max_foals"];
$breeding_type=$row["breeding_type"];
$fee=$row["fee"];

// results
echo " <TR>
<TD>$name</TD>
<TD>$horse_id</TD>
<TD>$player_id</TD>
<TD>$horse_type</TD>
<TD>$points</TD>
<TD>$goal</TD>
<TD>$max_foals</TD>
<TD>$breeding_type</TD>
<TD>$fee</TD>
</TR>";
}
}

echo "</table>";
mysql_close($connection);
?>

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.