Displaying PHP result within HTML?

Thread Solved

Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Displaying PHP result within HTML?

 
0
  #1
Apr 3rd, 2008
I've searched through the forum, but I couldn't find an answer. How do you display a result within HTML?

Such as:

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

Thanks in advance.
Last edited by peter_budo; Apr 5th, 2008 at 1:28 pm. Reason: [icode] is for one line of code, [code] is for multiple lines
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Displaying PHP result within HTML?

 
0
  #2
Apr 3rd, 2008
Could you please explain more what you want to display?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: Displaying PHP result within HTML?

 
0
  #3
Apr 3rd, 2008
I want to display the ['first_name'], ['last_name'], ['email'] 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.

  1. if(isset($_POST['submit'])) {
  2. $jobnumber=$_POST['jobnumber'];
  3.  
  4. //connect
  5.  
  6. $query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
  7. $result = mysql_query($query);
  8. while ($row = mysql_fetch_array($result)){
  9. echo $row['first_name'];
  10. echo $row['last_name'];
  11. echo $row['email'];
  12. //etc...
  13. }
  14. }
  15. ?>

Did I help clear it a little? Thanks for your help...
Last edited by peter_budo; Apr 5th, 2008 at 1:28 pm. Reason: [icode] is for one line of code, [code] is for multiple lines
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Displaying PHP result within HTML?

 
0
  #4
Apr 3rd, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: Displaying PHP result within HTML?

 
0
  #5
Apr 3rd, 2008
I just want to display the results within a table or a list.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Displaying PHP result within HTML?

 
0
  #6
Apr 3rd, 2008
just put the echo thing inside the table.

  1. $query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
  2. $result = mysql_query($query);
  3. echo "<table>";
  4. while ($row = mysql_fetch_array($result)){
  5. echo "<tr>"
  6. echo "<td>$row['first_name']</td>";
  7. echo "<td>$row['last_name']</td>";
  8. echo "<td>$row['email']</td>";
  9. echo "</tr>";
  10. //etc...
  11. }
  12. echo "</table>";
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: Displaying PHP result within HTML?

 
0
  #7
Apr 4th, 2008
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:

  1. <?php
  2. if(isset($_POST['submit'])) {
  3. $jobnumber=$_POST['jobnumber'];
  4.  
  5. //connect
  6.  
  7. $query = "SELECT * FROM customers WHERE job_number='$jobnumber'";
  8. $result = mysql_query($query);
  9. echo "<table>";
  10. while ($row = mysql_fetch_array($result)) {
  11. echo "<tr>"
  12. echo "<td>$row['first_name']</td>";
  13. echo "<td>$row['last_name'];</td>";
  14. echo "<td>$row['email'];</td>";
  15. echo "</tr>";
  16. //etc...
  17. }
  18. echo "</table>";
  19. }
  20. ?>

Line 30 = echo "<td>$row['first_name']</td>";
It's highlighted in thick red. Thanks again.
Last edited by peter_budo; Apr 5th, 2008 at 1:28 pm. Reason: [icode] is for one line of code, [code] is for multiple lines
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Displaying PHP result within HTML?

 
0
  #8
Apr 4th, 2008
you have mistakenly put ";" in this line:

echo "<td>$row['last_name'];</td>";
erase it and it will be fine.
Last edited by peter_budo; Apr 5th, 2008 at 1:29 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Displaying PHP result within HTML?

 
0
  #9
Apr 4th, 2008
and also in here:

echo "<td>$row['email'];</td>";
I am referring to the ";" in the middle.
Last edited by peter_budo; Apr 5th, 2008 at 1:29 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Displaying PHP result within HTML?

 
0
  #10
Apr 4th, 2008
No..that isn't the problem.. The problem is missing ; in here..
echo "<tr>"
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC