954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Echo Table Problem

I have a php script that echoes results from a search. Generally I have no problem getting the results in a table but for some reason I can't get these scripts to do that. I figure its a small error. I'm going to put in the code but if you want to just suggest a good editor (as I am new to php) that would be helpful. Thanks.

<?php
  if(isset($_POST['submit'])){
  if(isset($_GET['go'])){
  if(preg_match("/^[  a-zA-Z0-9]+/", $_POST['search'])){
  $search=$_POST['search'];
  
  $db=mysql_connect  ("connection info") or die ('I cannot connect to the database  because: ' . mysql_error());
 
  $mydb=mysql_select_db("database name");
  
  $sql="SELECT  OrderID, Customer, Address, City, State, ZipCode, Telephone, ServiceCategory, DateCall, WStatus FROM C WHERE OrderID LIKE '%" . $search .  "%' OR Customer LIKE '%" . $search ."%' OR Address LIKE '%" . $search ."%' OR City LIKE '%" . $search ."%' OR State LIKE '%" . $search ."%' OR ZipCode LIKE '%" . $search ."%' OR Telephone LIKE '%" . $search ."%' OR ServiceCategory LIKE '%" . $search ."%' OR DateCall LIKE '%" . $search ."%' OR WStatus LIKE '%" . $search ."%'";
  
 $result=mysql_query($sql);
{
if (mysql_num_rows($result)>1) {

echo "<table border='1'>  
<tr>
<th>Order ID</th>
<th>Customer</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Telephone</th>
<th>Service Category</th>
<th>Date of Call</th>
<th>Order Status</th>
</tr>";  
}
  while($row=mysql_fetch_array($result)){
       echo "<tr>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['OrderID'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Customer'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Address'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['City'] . "</a></td>"; 
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['State'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['ZipCode'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Telephone'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['ServiceCategory'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['DateCall'] . "</a></td>";
  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['WStatus'] . "</a></td>";  
  echo "</tr>";  
    
}
}
echo "</table>";
if(mysql_num_rows($result)==0){
  echo "<p><a href='aworkorder.html'> No record Found. Add Work Order</a>"; }
  }
  else{
  echo  "<p>Please enter a search query</p>";
  }
  }
  }
mysql_close($db);
?>


I think it's something simple but I figured I'd just ask for some help rather than continue bashing my head against a wall...Thanks

ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

what problem you have??, i can't understand what you want ??
which kind of editor??

jogesh_p
Junior Poster in Training
68 posts since Sep 2010
Reputation Points: 16
Solved Threads: 6
 

The table is not printing. The result is just displayed as one long hyperlink.

An editor that looks for minor problems like if you have a { but no }.

what problem you have??, i can't understand what you want ?? which kind of editor??
ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Try Now >>

<?php
  if(isset($_POST['submit'])){
  if(isset($_GET['go'])){
  if(preg_match("/^[  a-zA-Z0-9]+/", $_POST['search'])){
  $search=$_POST['search'];
  
  $db=mysql_connect  ("connection info") or die ('I cannot connect to the database  because: ' . mysql_error());
 
  $mydb=mysql_select_db("database name");
  
  $sql="SELECT  OrderID, Customer, Address, City, State, ZipCode, Telephone, ServiceCategory, DateCall, WStatus FROM C WHERE OrderID LIKE '%" . $search .  "%' OR Customer LIKE '%" . $search ."%' OR Address LIKE '%" . $search ."%' OR City LIKE '%" . $search ."%' OR State LIKE '%" . $search ."%' OR ZipCode LIKE '%" . $search ."%' OR Telephone LIKE '%" . $search ."%' OR ServiceCategory LIKE '%" . $search ."%' OR DateCall LIKE '%" . $search ."%' OR WStatus LIKE '%" . $search ."%'";
  
 $result=mysql_query($sql);
//{
	if (mysql_num_rows($result)>1) {

	echo "<table border='1'>  
	<tr>
	<th>Order ID</th>
	<th>Customer</th>
	<th>Address</th>
	<th>City</th>
	<th>State</th>
	<th>Zip Code</th>
	<th>Telephone</th>
	<th>Service Category</th>
	<th>Date of Call</th>
	<th>Order Status</th>
	</tr>";  
	//}
		  while($row=mysql_fetch_array($result)){
			   echo "<tr>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['OrderID'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Customer'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Address'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['City'] . "</a></td>"; 
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['State'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['ZipCode'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Telephone'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['ServiceCategory'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['DateCall'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['WStatus'] . "</a></td>";  
				  echo "</tr>";  
			
		}

		echo "</table>";
  }
//}

	if(mysql_num_rows($result)==0){
	  echo "<p><a href='aworkorder.html'> No record Found. Add Work Order</a>"; }
	  }
	  else{
	  echo  "<p>Please enter a search query</p>";
	  }
  }
  }
mysql_close($db);
?>
jogesh_p
Junior Poster in Training
68 posts since Sep 2010
Reputation Points: 16
Solved Threads: 6
 

if your problem get solved then let me now?? and Use Edit Plus editor,,
and do some necessary settings like match braces etc..

jogesh_p
Junior Poster in Training
68 posts since Sep 2010
Reputation Points: 16
Solved Threads: 6
 

that didn't work but I'll continue checking. I know it's something simple

if your problem get solved then let me now?? and Use Edit Plus editor,, and do some necessary settings like match braces etc..
ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

try this and i think you need a best editor, cause you mismatched the parentheses braces

<?php
  if(isset($_POST['submit'])){
  if(isset($_GET['go'])){
  if(preg_match("/^[  a-zA-Z0-9]+/", $_POST['search'])){
  $search=$_POST['search'];
  
  $db=mysql_connect  ("connection info") or die ('I cannot connect to the database  because: ' . mysql_error());
 
  $mydb=mysql_select_db("database name");
  
  $sql="SELECT  OrderID, Customer, Address, City, State, ZipCode, Telephone, ServiceCategory, DateCall, WStatus FROM C WHERE OrderID LIKE '%" . $search .  "%' OR Customer LIKE '%" . $search ."%' OR Address LIKE '%" . $search ."%' OR City LIKE '%" . $search ."%' OR State LIKE '%" . $search ."%' OR ZipCode LIKE '%" . $search ."%' OR Telephone LIKE '%" . $search ."%' OR ServiceCategory LIKE '%" . $search ."%' OR DateCall LIKE '%" . $search ."%' OR WStatus LIKE '%" . $search ."%'";
  
 $result=mysql_query($sql);
//{
	if (mysql_num_rows($result)>1) {

	echo "<table border='1'>  
	<tr>
	<th>Order ID</th>
	<th>Customer</th>
	<th>Address</th>
	<th>City</th>
	<th>State</th>
	<th>Zip Code</th>
	<th>Telephone</th>
	<th>Service Category</th>
	<th>Date of Call</th>
	<th>Order Status</th>
	</tr>";  
	//}
		  while($row=mysql_fetch_array($result)){
			   echo "<tr>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['OrderID'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Customer'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Address'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['City'] . "</a></td>"; 
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['State'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['ZipCode'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['Telephone'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['ServiceCategory'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['DateCall'] . "</a></td>";
				  echo "<td><a href='http://websitename.com/admin/workorder/link.php?OrderID=" . $row['OrderID'] . "'>" . $row['WStatus'] . "</a></td>";  
				  echo "</tr>";  
			
		}

		echo "</table>";
  }
else
  {
	echo "<p><a href='aworkorder.html'> No record Found. Add Work Order</a>";
  }
//}
/*
	if(mysql_num_rows($result)==0){
	  echo "<p><a href='aworkorder.html'> No record Found. Add Work Order</a>"; }
	  //}
	  else{
	  echo  "<p>Please enter a search query</p>";
	  }
	  */
  }
  }
mysql_close($db);
?>
jogesh_p
Junior Poster in Training
68 posts since Sep 2010
Reputation Points: 16
Solved Threads: 6
 

and let me know quickly if you not found solved>> :)

jogesh_p
Junior Poster in Training
68 posts since Sep 2010
Reputation Points: 16
Solved Threads: 6
 

mark solved if you find.

jogesh_p
Junior Poster in Training
68 posts since Sep 2010
Reputation Points: 16
Solved Threads: 6
 

Thanks for your help but the solution did not have to do with brackets. The problem was with the if statement at this:

if (mysql_num_rows($result)>1)


it should be

if (mysql_num_rows($result)>0)


Do I get points for solving my own thread? LOL. But seriously thanks for your help!mark solved if you find.

ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: