Petrushka Posted December 29, 2007 Share Posted December 29, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/83613-solved-tabulating-results/ Share on other sites More sharing options...
revraz Posted December 29, 2007 Share Posted December 29, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83613-solved-tabulating-results/#findComment-425376 Share on other sites More sharing options...
Petrushka Posted December 29, 2007 Author Share Posted December 29, 2007 Many thanks for the helpful response, the data is now tabulated - where would I add the table details, such as width? Quote Link to comment https://forums.phpfreaks.com/topic/83613-solved-tabulating-results/#findComment-425389 Share on other sites More sharing options...
revraz Posted December 29, 2007 Share Posted December 29, 2007 If it effects then entire table, you can do it here echo "<TABLE width='100%'> If it concerns Rows, then you need to do it in the TR tags. Quote Link to comment https://forums.phpfreaks.com/topic/83613-solved-tabulating-results/#findComment-425391 Share on other sites More sharing options...
Petrushka Posted December 29, 2007 Author Share Posted December 29, 2007 Wonderful, many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/83613-solved-tabulating-results/#findComment-425403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.