Jump to content

[SOLVED] Problem running multiple queries?


sstoveld

Recommended Posts

hey guys, this is an assignment for school that i'm having trouble with. we're supposed to pretty much build this:

 

http://flywheel.caset.buffalo.edu/315/world.php

 

the database is already set up, and just need to get the php coded.

 

i think im having a problem running multiple queries, one after another. if i comment out all of the other queries, it runs ok for that section, but if not, it just displays a blank page.

 

here's a link to the pastebin of my code...

 

http://pastebin.com/m6138c856

 

see it works when i have all the other queries commented out, but when i uncomment the next one in the list, it just displays a blank page...

 

here's the link to my page:

http://gamera.caset.buffalo.edu/~sstoveld/a2.php

 

and here's my code if you dont want to go to the pastebin:

any help would be appreciated on how i can fix this somehow... thanks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>World Database</title>
<link href="styles/styles.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>

<div id="container">
<div id="header">
<h1>World Database</h1>
</div><!--header-->

<p>This PHP script populates a table with the countries of the world, along with other info about them.</p>

<?php
// Connect to the Database //
$dbhost = '*****';
$dbuser = '*****';

$conn = mysql_connect($dbhost, $dbuser) or die                      ('Error connecting to mysql');

// Select the Database //
$dbname = 'world';
mysql_select_db($dbname);

// Query the Database to select Countries in Asia //
$queryasia = @mysql_query('SELECT * FROM Country WHERE Continent = "Asia" ORDER BY Name')
//$queryeurope = @mysql_query('SELECT * FROM Country WHERE Continent = "Europe" ORDER BY Name')
//$queryna = @mysql_query('SELECT * FROM Country WHERE Continent = "North America" ORDER BY Name')
//$queryafrica = @mysql_query('SELECT * FROM Country WHERE Continent = "Africa" ORDER BY Name')
//$queryoceania = @mysql_query('SELECT * FROM Country WHERE Continent = "Oceania" ORDER BY Name')
//$queryantarctica = @mysql_query('SELECT * FROM Country WHERE Continent = "Antarctica" ORDER BY Name')
//$querysa = @mysql_query('SELECT * FROM Country WHERE Continent = "South America" ORDER BY Name') 



// Make an HTML table to hold the data for Asia //
?>

<h2>Asia</h2>

<table>
<tr>
    	<td><strong>Name</strong></td>
        <td><strong>Population</strong></td>
        <td><strong>GNP</strong></td>
        <td><strong>Government</strong></td>
    </tr>

<?php
while ($row = mysql_fetch_array($queryasia)) {
	echo('<tr><td>' . $row['Name'] . '</td><td>' . $row['Population'] . '</td><td>' . $row['GNP'] . '</td><td>' . $row['GovernmentForm'] . '</td></tr>');
}

// Make an HTML table to hold the data for Europe //
?>
</table>

<h2>Europe</h2>

<table>
<tr>
    	<td><strong>Name</strong></td>
        <td><strong>Population</strong></td>
        <td><strong>GNP</strong></td>
        <td><strong>Government</strong></td>
    </tr>

<?php
while ($row = mysql_fetch_array($queryeurope)) {
	echo('<tr><td>' . $row['Name'] . '</td><td>' . $row['Population'] . '</td><td>' . $row['GNP'] . '</td><td>' . $row['GovernmentForm'] . '</td></tr>');
}

?>
</table>




</div><!--container-->


</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/175248-solved-problem-running-multiple-queries/
Share on other sites

if your getting a blank page I assume error reporting has been turned off I recommned turning error reporting on this can be done by putting the following at the top of your file

 

<?php
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);
?>

 

one error I can see is you've forgotten to put a ; on the end of your queries like:

 

$queryasia = @mysql_query('SELECT * FROM Country WHERE Continent = "Asia" ORDER BY Name');
$queryeurope = @mysql_query('SELECT * FROM Country WHERE Continent = "Europe" ORDER BY Name');
$queryna = @mysql_query('SELECT * FROM Country WHERE Continent = "North America" ORDER BY Name');
$queryafrica = @mysql_query('SELECT * FROM Country WHERE Continent = "Africa" ORDER BY Name');
$queryoceania = @mysql_query('SELECT * FROM Country WHERE Continent = "Oceania" ORDER BY Name');
$queryantarctica = @mysql_query('SELECT * FROM Country WHERE Continent = "Antarctica" ORDER BY Name');
$querysa = @mysql_query('SELECT * FROM Country WHERE Continent = "South America" ORDER BY Name') 

 

also you may want to remove your error supressor the @ symbol as this will stop any errors from showing as well.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.