xcali Posted April 23, 2008 Share Posted April 23, 2008 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); } ?> Link to comment https://forums.phpfreaks.com/topic/102441-solved-query-results-do-not-display-in-a-table/ Share on other sites More sharing options...
teng84 Posted April 23, 2008 Share Posted April 23, 2008 <?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 Link to comment https://forums.phpfreaks.com/topic/102441-solved-query-results-do-not-display-in-a-table/#findComment-524586 Share on other sites More sharing options...
xcali Posted April 23, 2008 Author Share Posted April 23, 2008 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 Link to comment https://forums.phpfreaks.com/topic/102441-solved-query-results-do-not-display-in-a-table/#findComment-524600 Share on other sites More sharing options...
Fadion Posted April 23, 2008 Share Posted April 23, 2008 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); } } ?> Link to comment https://forums.phpfreaks.com/topic/102441-solved-query-results-do-not-display-in-a-table/#findComment-524626 Share on other sites More sharing options...
xcali Posted April 23, 2008 Author Share Posted April 23, 2008 dang such an easy thing yet cause so many problems thank you very much guys all works ! Link to comment https://forums.phpfreaks.com/topic/102441-solved-query-results-do-not-display-in-a-table/#findComment-524636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.