I've searched through the forum, but I couldn't find an answer. How do you display a result within HTML?

Such as:

$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	while ($row = mysql_fetch_array($result)){
		echo $row['first_name'];
		echo $row['last_name'];

Thanks in advance.

Recommended Answers

Could you please explain more what you want to display?

Jump to Post

there's no problem in your code that will display the results alright.Do you mean that you want to display the results in a specific area of an HTML page?

Jump to Post

just put the echo thing inside the table.

$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	echo "<table>";
        while ($row = mysql_fetch_array($result)){
		echo "<tr>"
                echo "<td>$row['first_name']</td>";
		echo "<td>$row['last_name']</td>";
		echo "<td>$row['email']</td>";
                echo "</tr>";		
//etc...
	}
        echo "</table>";
Jump to Post

you have mistakenly put ";" in this line: echo "<td>$row['last_name'];</td>"; erase it and it will be fine.

Jump to Post

All 14 Replies

Could you please explain more what you want to display?

I want to display the , , fields. Here's the script I have used to call up a result from my database, and the result is the echo $row['first_name'] , etc. I'm just trying to figure out how to wrap the result within HTML.

if(isset($_POST['submit'])) {
	$jobnumber=$_POST['jobnumber'];

	//connect

	$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	while ($row = mysql_fetch_array($result)){
		echo $row['first_name'];
		echo $row['last_name'];
		echo $row['email'];
		//etc...
	}
}
?>

Did I help clear it a little? Thanks for your help...

there's no problem in your code that will display the results alright.Do you mean that you want to display the results in a specific area of an HTML page?

I just want to display the results within a table or a list.

just put the echo thing inside the table.

$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	echo "<table>";
        while ($row = mysql_fetch_array($result)){
		echo "<tr>"
                echo "<td>$row['first_name']</td>";
		echo "<td>$row['last_name']</td>";
		echo "<td>$row['email']</td>";
                echo "</tr>";		
//etc...
	}
        echo "</table>";

I seem to be getting this error: Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in getjobnumber.php on line 30

Here's how I wrote it:

<?php
if(isset($_POST['submit'])) {
	$jobnumber=$_POST['jobnumber'];

	//connect

	$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	echo "<table>";
	while ($row = mysql_fetch_array($result))  {
		echo "<tr>"
		echo "<td>$row['first_name']</td>";
		echo "<td>$row['last_name'];</td>";
		echo "<td>$row['email'];</td>";
		echo "</tr>";
		//etc...
	}
		echo "</table>";
	}
?>

Line 30 = echo "<td>$row['first_name']</td>"; It's highlighted in thick red. Thanks again.

you have mistakenly put ";" in this line: echo "<td>$row['last_name'];</td>"; erase it and it will be fine.

and also in here: echo "<td>$row['email'];</td>"; I am referring to the ";" in the middle.

No..that isn't the problem.. The problem is missing ; in here..

echo "<tr>"

Beer mug ? Party time ? eh ? ;)

$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	echo "<table>";
	while ($row = mysql_fetch_array($result))  {
		echo "<tr>";
		echo "<td>$row['first_name']</td>";
		echo "<td>$row['last_name']</td>";
		echo "<td>$row['email']</td>";
		echo "</tr>";
		//etc...
	}
		echo "</table>";
	}
?>

This still gives me a parse error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in getjobnumber.php on line 30

I dont see line 30 in that code snippet !
And btw, instead of echo "<td>$row['last_name']</td>"; Try, echo "<td>".$row['last_name']."</td>";

$query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
	$result = mysql_query($query);
	echo "<table>";
	while ($row = mysql_fetch_array($result))  {
		echo "<tr>";
		echo "<td>$row['first_name']</td>";
		echo "<td>$row['last_name']</td>";
		echo "<td>$row['email']</td>";
		echo "</tr>";
		//etc...
	}
		echo "</table>";
	}
?>

This still gives me a parse error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in getjobnumber.php on line 30

You have two options:
--- Option 1 ---
Remove the single quotes ' from the $row
echo "<td>$row[first_name]</td>";
--- Option 2 ---
Change your echo to this (NOTE: the variable is surrounded by ". ." within the echo)
echo "<td>".$row."</td>";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.