Jump to content

[SOLVED] Query Results do not display in a table :/


xcali

Recommended Posts

Hey guys

 

could someone please guide me where im making a mistake?

without table everything works find and results are displayed but they are all over the place

after creating a table, all i get is a blank page

 

I tried numerous things to fix the problem but i just cant seem to get it :/

Please advise

 

Thank you

 

<?php
include('results2.html');
if ($_POST['searching2'] == "yes")
{ echo '<h1 class="style2">Results</h1><p>';
$gender = $_POST['gender'];
$age = $_POST['age'];
$btype = $_POST['btype'];
$ethnicity = $_POST['ethnicity'];
require_once ('../cgi-bin/dbconnect.php');

$data = mysql_query("SELECT * FROM users WHERE regis_as='M' and age='$age' and btype='$btype' and ethnicity='$ethnicity'");

$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{ echo "Sorry, but we can not find an entry to match your query<br><br>"; }

while ($result = mysql_fetch_array($data))
{		echo "<table align="center" cellspacing="0" cellpadding="5">
				<tr>
				<td align="left"><b>First Name</b></td>
				<td align="left"><b>Last Name</b></td>
				<td align="left"><b>Email</b></td>
				<td align="left"><b>Age</b></td> 
				<td align="left"><b>Ethnicity</b></td></tr> ";

		echo "<tr><td align="left">" $result['first_name']"</td>
				<td align="left">" $result['last_name']"</td></tr>
				<td align="left">" $result['username']"</td></tr>
				<td align="left">" $result['age']"</td></tr>
				<td align="left">" $result['ethnicity']"</td></tr> ";
}
echo "</table>";

  mysql_free_result($result);
} 
?>

<?php
include('results2.html');
if ($_POST['searching2'] == "yes")
{ echo '<h1 class="style2">Results</h1><p>';
$gender = $_POST['gender'];
$age = $_POST['age'];
$btype = $_POST['btype'];
$ethnicity = $_POST['ethnicity'];
require_once ('../cgi-bin/dbconnect.php');

$data = mysql_query("SELECT * FROM users WHERE regis_as='M' and age='$age' and btype='$btype' and ethnicity='$ethnicity'");

$anymatches=mysql_num_rows($data);
if ($anymatches == 0){ 
echo "Sorry, but we can not find an entry to match your query<br><br>"; 
}
else{
echo "<table align=\"center\" cellspacing=\"0\" cellpadding=\"5\">";
while ($result = mysql_fetch_array($data))
	{		echo "<tr>
					<td align=\"left\"><b>First Name</b></td>
					<td align=\"left\"><b>Last Name</b></td>
					<td align=\"left\"><b>Email</b></td>
					<td align=\"left\"><b>Age</b></td> 
					<td align=\"left\"><b>Ethnicity</b></td></tr> ";

			echo "<tr><td align=\"left\">" $result['first_name']"</td>
					<td align=\"left\">" $result['last_name']"</td></tr>
					<td align=\"left\">" $result['username']"</td></tr>
					<td align=\"left\">" $result['age']"</td></tr>
					<td align=\"left\">" $result['ethnicity']"</td></tr> ";
	}
	echo "</table>";

  mysql_free_result($result);
  }
} 
?>

you cant use  "" inside the  " " it should be single quote ' or escape them with \

second yourtable declaration is inside the loop

thank you for your response

 

thats so weird

i tried the code that you supplied but i still keep getting a blank page

i also tried replacing  "" inside the  " " with single quotes as suggested but with the same outcome

 

any other ideas what might be wrong? :s

A line like this:

 

echo "<tr><td align='left'>" $result['first_name'] "</td>

 

Should have the string concatenated to the variable, so the variables are echoed:

 

echo "<tr><td align='left'>" . $result['first_name'] . "</td>

 

The full code:

 

<?php
include('results2.html');
if ($_POST['searching2'] == "yes")
{ echo '<h1 class="style2">Results</h1><p>';
$gender = $_POST['gender'];
$age = $_POST['age'];
$btype = $_POST['btype'];
$ethnicity = $_POST['ethnicity'];
require_once ('../cgi-bin/dbconnect.php');

$data = mysql_query("SELECT * FROM users WHERE regis_as='M' and age='$age' and btype='$btype' and ethnicity='$ethnicity'");

$anymatches=mysql_num_rows($data);
if ($anymatches == 0){ 
echo "Sorry, but we can not find an entry to match your query<br><br>"; 
}
else{
echo "<table align='center' cellspacing='0' cellpadding='5'>";
while ($result = mysql_fetch_array($data))
	{		echo "<tr>
					<td align='left'><b>First Name</b></td>
					<td align='left'><b>Last Name</b></td>
					<td align='left'><b>Email</b></td>
					<td align='left'><b>Age</b></td> 
					<td align='left'><b>Ethnicity</b></td></tr> ";

			echo "<tr><td align='left'>" . $result['first_name'] . "</td>
					<td align='left'>" . $result['last_name'] . "</td></tr>
					<td align='left'>" . $result['username'] . "</td></tr>
					<td align='left'>" . $result['age'] . "</td></tr>
					<td align='left'>" . $result['ethnicity'] . "</td></tr> ";
	}
	echo "</table>";

  mysql_free_result($result);
  }
} 
?>

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.