Jump to content

Recommended Posts

I am trying to echo tables and i am doing this in a very basic way eg "echo '<table';" so i have slight error in my code that outputs the table but my variable is put out as text rather than the information its meant to collect! Im sure this is probably just a matter of having the right quotes in the right place. Here is a small segment of my code for anyone interested to look at..

 

<?php	  
  while($row = mysql_fetch_array($result))

      { echo '<table border="1">';    
        echo '<tr>';
        echo '<td>';
	echo '"$row"["flight_num"]';
	echo '</td>';
	echo '</tr>';
	echo '</table>';
    
    
?>

 

many thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/136492-solved-slight-error-echoing-tables/
Share on other sites

I have to also play around with the quotes for this to happen. But think of it this way. " " - double quotes should always start a Echo.then anywhere in the echo with double quotes you can use single quotes.

 

   
  while($row = mysql_fetch_array($result)){

     echo '<table border="1">';    
     echo '<tr>';
     echo '<td>';
     echo "'$row['flight_num']'"; //changed this row. Look at it.
     echo '</td>';
     echo '</tr>';
     echo '</table>';
       
       //Also you forgot the ending } sign.
}

I have to also play around with the quotes for this to happen. But think of it this way. " " - double quotes should always start a Echo.then anywhere in the echo with double quotes you can use single quotes.

  
  while($row = mysql_fetch_array($result))

      { echo '<table border="1">';    
        echo '<tr>';
        echo '<td>';
      echo "'$row['flight_num']'"; //changed this row. Look at it.
      echo '</td>';
      echo '</tr>';
      echo '</table>';
       
       //Also you forgot the ending } sign.
}
?>

 

Sorry that code edit failed, i got not output to the users (aka just a blank page rather than ""$row"["flight_num"]"" in a table. below i will post a larger chunk of code incase its important, also the while loop continues further down the page.. ill show you.

 

  
<?php


  if(mysql_num_rows($result) > 0){       
      
          ?>
    <!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=iso-8859-1" 
/>
    <link
  rel="stylesheet"
  href="dropdown2.css" 
  type="text/css"
    />
    <script 
  type="text/javascript"
    src="dropdown.js">
</script>
    <script 
      type="text/javascript"	
    src="calendar.js">
</script>
<script
      type="text/javascript"	
    src="enablefield.js">
</script>
<script 
  type="text/javascript">
    function greyText(one_way, return_date)
    {
          if (document.form1[one_way].checked)
	    {
		  document.form1[return_date].disabled=true;
              document.form1[return_flight].disabled=true;
            } 
	  else 
	    {
              document.form1[return_date].disabled=false;
              document.form1[return_flight].disabled=false;
            }
        }
	<title>Webair Contact Us</title> 
<link rel="StyleSheet" href="./mainstyle.css"type="text/css" media="screen">  
     </script>
   </head> 
   <body>
     <div id="wrapper">
       <table> 
         <tr>
       <td>
             <img 
		   src="Webair--logo.gif" 
           height= "65"
		   width="240"
       	       align="top"
         />
       </td>
       <td 
	     background="Banner--background.gif"
		 height="60"
		 align="right"
		 width="817"
	   >
           <a
		     class="hyperlink"
		     href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php">
		    
		     <b>
		     Staff login
		     </b>
		   </a>
                 |	 
           <a 
		     class="hyperlink"
			 href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"
		   >
		  <b>
		    Home
		  </b>
		  </a>
             |  
          <a 
		    class="hyperlink"
			href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"
		  >
		    <b>
		    Booked Flights
			   &nbsp
		    </b>
		  </a>

       </td>
     </tr>
  </table>
     <dl 
   class="dropdown"
 >
       <dt 
     id="one-ddheader" 
     onmouseover="ddMenu('one',1)"
         onmouseout="ddMenu('one',-1)"
   >
     Home
   </dt>
       <dd 
     id="one-ddcontent"
     onmouseover="cancelHide('one')"
         onmouseout="ddMenu('one',-1)"
   >
         <ul>
           <li>
         <a 
           href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" 
	       class="underline"
         >
           Home
         </a>
       </li>
         </ul>
   </dd>
     </dl>
     <dl 
   class="dropdown"
 >
      <dt 
    id="two-ddheader"
  		onmouseover="ddMenu('two',1)"
        onmouseout="ddMenu('two',-1)"
  >
    Contact us
  </dt>
        <dd 
	  id="two-ddcontent"
	  onmouseover="cancelHide('two')"
          onmouseout="ddMenu('two',-1)"
	>
	 <ul>
           <li>
	     <a 
		   href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact" 
		   class="underline"
		 >
		   Contact us
		 </a>
	   </li>
     </ul>
       </dd>
     </dl>  
     <dl 
   class="dropdown"
 >
       <dt
  	     id="three-ddheader"
	 onmouseover="ddMenu('three',1)"
	 onmouseout="ddMenu('three',-1)"
   >
     Flights
   </dt>
         <dd
		   id="three-ddcontent"
	   onmouseover="cancelHide('three')"
           onmouseout="ddMenu('three',-1)"
	 >
           <ul>
                         
         <li>
		   <a
		     href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_refunds.html"
			 class="underline"
		   >
		     Refund Policy
		   </a>
		 </li>
           </ul>
         </dd>
     </dl>
     <dl
 class="dropdown"
 >
       <dt 
     id="four-ddheader"
	 onmouseover="ddMenu('four',1)"
         onmouseout="ddMenu('four',-1)"
   >
     Travel Information
   </dt>
         <dd 
	   id="four-ddcontent"
	   onmouseover="cancelHide('four')"
           onmouseout="ddMenu('four',-1)"
	 >
          <ul>
            <li>
		  <a
     		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_flight_fares.html"
			class="underline"
		  >
		    Flight Timetable 
		  </a>
		</li>
            <li>
		  <a 
		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_baggage.html" 
			class="underline"
		  >
		    Baggage Information
		  </a>
		</li>
            <li>
		  <a 
		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_airport_info.html" 
			class="underline"
	      >
		    Airport information
		  </a>
		</li>
            <li>
		  <a 
		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_travel_info.html"
			class="underline"
		  >
		    Travel documentation requirements
		  </a>
        </li>
          </ul>
        </dd>
      </dl>  
      <dl
    class="dropdown"
  >
      <dt
    id="five-ddheader"
	onmouseover="ddMenu('five',1)"
        onmouseout="ddMenu('five',-1)"
  >
    About Webair
  </dt>
        <dd 
	  id="five-ddcontent" 
	  onmouseover="cancelHide('five')"
          onmouseout="ddMenu('five',-1)"
	>
          <ul>
            <li>
		  <a 
		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html" 
			class="underline"
		  >
		    About Webair
		  </a>
	    </li>
            <li>
		  <a
    	    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"
			class="underline"
		  >
		    Contact us
		  </a>
	    </li>
          </ul>
        </dd>
      </dl>
      <div 
    style="clear:both"
      /> 
    </div>
      <div 
    id="content"
  >
      <div
  	    class="inner"
  >
<?php	  
  while($row = mysql_fetch_array($result))

      { echo '<table border="1">';    
        echo '<tr>';
        echo '<td>';
	echo '"$row"["flight_num"]';
	echo '</td>';
	echo '</tr>';
	echo '</table>';
    
    
?>




</div>
</div>
<div id="footer">
<div id="inner">
<div id="footer2">
<p><hr class="line"></hr>
<a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"><b>Staff login</b></a>
     |	 
 <a  class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"><b>Home</b></a>
 |  
 <a  class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"><b>Contact us</b></a>
 |
 <a  class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html"><b>About Webair</b></a>

<hr class="line2"></hr>
</p>
</div>
</div>
</div>
  </body>
  </html>
<?php

      
      }
             
       }else{
    
     echo 'Sorry, couldn\'t find any flights';
    
    }       
             
   

   mysql_free_result($result);   
     
?>

 

 

many thanks

Ill look through it, and post random comment signs. Honestly, there wasnt much to fix. the only thing i fixed was the while loop.

<?php


  if(mysql_num_rows($result) > 0){       
      
          ?>
    <!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=iso-8859-1" 
/>
    <link
  rel="stylesheet"
  href="dropdown2.css" 
  type="text/css"
    />
    <script 
  type="text/javascript"
    src="dropdown.js">
</script>
    <script 
      type="text/javascript"	
    src="calendar.js">
</script>
<script
      type="text/javascript"	
    src="enablefield.js">
</script>
<script 
  type="text/javascript">
    function greyText(one_way, return_date)
    {
          if (document.form1[one_way].checked)
	    {
		  document.form1[return_date].disabled=true;
              document.form1[return_flight].disabled=true;
            } 
	  else 
	    {
              document.form1[return_date].disabled=false;
              document.form1[return_flight].disabled=false;
            }
        }
	<title>Webair Contact Us</title> 
<link rel="StyleSheet" href="./mainstyle.css"type="text/css" media="screen">  
     </script>
   </head> 
   <body>
     <div id="wrapper">
       <table> 
         <tr>
       <td>
             <img 
		   src="Webair--logo.gif" 
           height= "65"
		   width="240"
       	       align="top"
         />
       </td>
       <td 
	     background="Banner--background.gif"
		 height="60"
		 align="right"
		 width="817"
	   >
           <a
		     class="hyperlink"
		     href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php">
		    
		     <b>
		     Staff login
		     </b>
		   </a>
                 |	 
           <a 
		     class="hyperlink"
			 href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"
		   >
		  <b>
		    Home
		  </b>
		  </a>
             |  
          <a 
		    class="hyperlink"
			href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"
		  >
		    <b>
		    Booked Flights
			   &nbsp
		    </b>
		  </a>

       </td>
     </tr>
  </table>
     <dl 
   class="dropdown"
 >
       <dt 
     id="one-ddheader" 
     onmouseover="ddMenu('one',1)"
         onmouseout="ddMenu('one',-1)"
   >
     Home
   </dt>
       <dd 
     id="one-ddcontent"
     onmouseover="cancelHide('one')"
         onmouseout="ddMenu('one',-1)"
   >
         <ul>
           <li>
         <a 
           href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" 
	       class="underline"
         >
           Home
         </a>
       </li>
         </ul>
   </dd>
     </dl>
     <dl 
   class="dropdown"
 >
      <dt 
    id="two-ddheader"
  		onmouseover="ddMenu('two',1)"
        onmouseout="ddMenu('two',-1)"
  >
    Contact us
  </dt>
        <dd 
	  id="two-ddcontent"
	  onmouseover="cancelHide('two')"
          onmouseout="ddMenu('two',-1)"
	>
	 <ul>
           <li>
	     <a 
		   href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact" 
		   class="underline"
		 >
		   Contact us
		 </a>
	   </li>
     </ul>
       </dd>
     </dl>  
     <dl 
   class="dropdown"
 >
       <dt
  	     id="three-ddheader"
	 onmouseover="ddMenu('three',1)"
	 onmouseout="ddMenu('three',-1)"
   >
     Flights
   </dt>
         <dd
		   id="three-ddcontent"
	   onmouseover="cancelHide('three')"
           onmouseout="ddMenu('three',-1)"
	 >
           <ul>
                         
         <li>
		   <a
		     href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_refunds.html"
			 class="underline"
		   >
		     Refund Policy
		   </a>
		 </li>
           </ul>
         </dd>
     </dl>
     <dl
 class="dropdown"
 >
       <dt 
     id="four-ddheader"
	 onmouseover="ddMenu('four',1)"
         onmouseout="ddMenu('four',-1)"
   >
     Travel Information
   </dt>
         <dd 
	   id="four-ddcontent"
	   onmouseover="cancelHide('four')"
           onmouseout="ddMenu('four',-1)"
	 >
          <ul>
            <li>
		  <a
     		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_flight_fares.html"
			class="underline"
		  >
		    Flight Timetable 
		  </a>
		</li>
            <li>
		  <a 
		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_baggage.html" 
			class="underline"
		  >
		    Baggage Information
		  </a>
		</li>
            <li>
		  <a 
		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_airport_info.html" 
			class="underline"
	      >
		    Airport information
		  </a>
		</li>
            <li>
		  <a 
		    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_travel_info.html"
			class="underline"
		  >
		    Travel documentation requirements
		  </a>
        </li>
          </ul>
        </dd>
      </dl>  
      <dl
    class="dropdown"
  >
      <dt
    id="five-ddheader"
	onmouseover="ddMenu('five',1)"
        onmouseout="ddMenu('five',-1)"
  >
    About Webair
  </dt>
        <dd 
	  id="five-ddcontent" 
	  onmouseover="cancelHide('five')"
          onmouseout="ddMenu('five',-1)"
	>
          <ul>
            <li>
		  <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html" class="underline" > About Webair </a>
	    </li>
            <li>
		  <a
    	    href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"
			class="underline"
		  >
		    Contact us
		  </a>
	    </li>
          </ul>
        </dd>
      </dl>
      <div 
    style="clear:both"
      /> 
    </div>
      <div 
    id="content"
  >
      <div
  	    class="inner"
  >
<table border="1">
<?php	  
  while($row = mysql_fetch_array($result)){ 
                echo "<tr>";
                echo "<td>";
	echo ".$row['flight_num'].";
	echo "</td>";
	echo "</tr>";
}
    
?>
</table>



</div>
</div>
<div id="footer">
<div id="inner">
<div id="footer2">
<p><hr class="line"></hr>
<a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"><b>Staff login</b></a>
     |	 
 <a  class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"><b>Home</b></a>
 |  
 <a  class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"><b>Contact us</b></a>
 |
 <a  class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html"><b>About Webair</b></a>

<hr class="line2"></hr>
</p>
</div>
</div>
</div>
<?php
             
       }
   else{
    
     echo 'Sorry, couldn\'t find any flights';
    
    }       
             
   

   mysql_free_result($result);   
     
?>
</body>
</html>

I am trying to add in another row with a heading column 'Flight Number'. I tried adding this to the php and tired a number of ways but its not displaying the table. Please find below my attempt of adding this to the code. Any help would be much appreciated. 

 

<?php  

  while($row = mysql_fetch_array($result)){

  echo "

 

  <table border='1'> 

 

  <tr>

  <td>"Flight Number"</td></tr>

  <tr>

    <td>

  ".$row['flight_num']."

 

  </td> </tr> </table>";

   

   

?>

no offence or anything but its a lot easier to raed if you use code tags when posting snippets of code.

From the above you appear to have no closing curly brace for your while lopp ;-)

 

I know sorry, i will try that next time., if you check the above larger bulk of code you can see that the while loop extends down and closes later.

 

thank you :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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