Jump to content

Outputting data in a table


fa_dy

Recommended Posts

Hello guys. I am facing a little problem on my website when I am trying to output the data from the database in the form of a table. If you go to http://sigmalogistix.com/track-trace/ and enter any on of the following B/L No's:

 

123456789

987651234

543216789

 

You can see that the table is being created but the data is not being shown to the user. If I switch back to the old code in which there was no table, then the data is being shown to the user upon entering the B/L No. Please help me guys. Attached below are the codes which I have inside the function.inc.php file and the index.php file.

 

function.inc.php

 

<?php
include 'db.inc.php';
function search_results($keywords) {
  $returned_results = array();
  $where = "";
  $keywords = preg_split('/[\s]+/', $keywords);
  $total_keywords = count($keywords);
foreach($keywords as $key=>$keyword){
        $where .= "`keywords` LIKE '%$keyword%'";
    if ($key != ($total_keywords - 1)) {
    $where .= " AND ";
     }
  }
  $results = "SELECT `Bill_No`, `Origin_City`, `Origin_Country`, `Destination_City`, `Destination_Country`, `Status`, `Current_Location` FROM `billoflading` WHERE $where";
  $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0;
  if ($results_num === 0) {
    return false;
}   else {
    while ($results_row = mysql_fetch_assoc($results)) {
      $returned_results[] = array (
                'Bill_No' => $results_row['Bill_No'],
                'Origin_City' => $results_row['Origin_City'],
                'Origin_Country' => $results_row['Origin_Country'],
                'Destination_City' => $results_row['Destination_City'],
                'Destination_Country' => $results_row['Destination_Country'],
                'Status' => $results_row['Status'],
                'Current_Location' => $results_row['Current_Location']
     );
   }
  
   return $returned_results;
  }
  }
?>

 

index.php

 

<?php include 'func.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>search</title>
</head>
<body>
<form action="" method="POST">
    <p>
        <input type="text" name="keywords" size="17" maxlength="9" value="Enter B/L No." onfocus="if(this.value == 'Enter B/L No.'){this.value = '';}" /> <input type="submit" class="formbutton" value="Track" />
    </p>
</form>
<?php
if  (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
  $errors[] = '';
} else if (strlen($keywords)<9) {
  $errors[] = '<br><strong>Your Bill of Lading Number must contain 9-digits.</strong>';
} else if (search_results($keywords) === false) {
  $errors[] = '<br><strong>Please enter a valid Bill of Lading Number.</strong>';
}
if (empty($errors)) {
   $results = search_results($keywords);
   $results_num = count($results);
   $suffix = ($results_num !=1) ? 's' : '';
   foreach($results as $result) {
     echo '<br><table>
    <thead>
        <tr>
            <th><strong>B/L No.</strong></th>
            <th><strong>Origin City</strong></th>
            <th><strong>Origin Country</strong></th>
            <th><strong>Destination City</strong></th>
            <th><strong>Destination Country</strong></th>
            <th><strong>Status</strong></th>
            <th><strong>Current Location</strong></th>
        </tr>
    </thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_assoc($results) {
    ?>
        <tr>
            <td><?php echo $row["Bill_No"]; ?></td>
            <td><?php echo $row["Origin_City"]; ?></td>
            <td><?php echo $row["Origin_Country"]; ?></td>
            <td><?php echo $row["Destination_City"]; ?></td>
            <td><?php echo $row["Destination_Country"]; ?></td>
            <td><?php echo $row["Status"]; ?></td>
            <td><?php echo $row["Current_Location"]; ?></td>
        </tr>
    <?php
    }
    ?>
    </tbody>
</table>';
}
} else {
   foreach($errors as $error) {
    echo $error, '</br>';
  }
}
}
?>
</body>
</html>

Link to comment
Share on other sites

When you echo out the table, try switching the single quotes with double quotes (and vice-versa). It will not parse PHP variables that are inside singles quotes, but it will if they are within double quotes. If you look at the source for the page it produces, you will see your PHP code in your HTML.

 

 

Link to comment
Share on other sites

You also don't want to echo out the php tags such as:

<?php echo $row['Bill_No'] ?>

 

Since that is already inside an echo, just concatenate it into the string.

 

Thanks a lot for your reply. I removed the php tags and the result has started appearing but again there's a problem. If you go to the website and enter any one B/L No., you'll see that it isn't outputting the result but is instead outputting the code which is inside the <td> tags.

 

This is how the code looks now:

 

<?php include 'func.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>search</title>
</head>
<body>
<form action="" method="POST">
    <p>
        <input type="text" name="keywords" size="17" maxlength="9" value="Enter B/L No." onfocus="if(this.value == 'Enter B/L No.'){this.value = '';}" /> <input type="submit" class="formbutton" value="Track" />
    </p>
</form>
<?php
if  (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
  $errors[] = '';
} else if (strlen($keywords)<9) {
  $errors[] = '<br><strong>Your Bill of Lading Number must contain 9-digits.</strong>';
} else if (search_results($keywords) === false) {
  $errors[] = '<br><strong>Please enter a valid Bill of Lading Number.</strong>';
}
if (empty($errors)) {
   $results = search_results($keywords);
   $results_num = count($results);
   $suffix = ($results_num !=1) ? 's' : '';
   foreach($results as $result) {
     echo '<br><table>
    <thead>
        <tr>
            <th><strong>B/L No.</strong></th>
            <th><strong>Origin City</strong></th>
            <th><strong>Origin Country</strong></th>
            <th><strong>Destination City</strong></th>
            <th><strong>Destination Country</strong></th>
            <th><strong>Status</strong></th>
            <th><strong>Current Location</strong></th>
        </tr>
    </thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_assoc($results) {
    ?>
        <tr>
            <td>echo $row["Bill_No"]</td>
            <td>echo $row["Origin_City"]</td>
            <td>echo $row["Origin_Country"]</td>
            <td>echo $row["Destination_City"]</td>
            <td>echo $row["Destination_Country"]</td>
            <td>echo $row["Status"]</td>
            <td>echo $row["Current_Location"]</td>
        </tr>
    <?php
    }
    ?>
    </tbody>
</table>';
}
} else {
   foreach($errors as $error) {
    echo $error, '</br>';
  }
}
}
?>
</body>
</html>

 

Please help  :-\

Link to comment
Share on other sites

I can't test your code because I don't have your database, etc. set up. But try this and tell me what errors it puts out:

 

<?php include 'func.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>search</title>
</head>
<body>
<form action="" method="POST">
    <p>
        <input type="text" name="keywords" size="17" maxlength="9" value="Enter B/L No." onfocus="if(this.value == 'Enter B/L No.'){this.value = '';}" /> <input type="submit" class="formbutton" value="Track" />
    </p>
</form>
<?php
if  (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
  $errors[] = '';
} else if (strlen($keywords)<9) {
  $errors[] = '<br><strong>Your Bill of Lading Number must contain 9-digits.</strong>';
} else if (search_results($keywords) === false) {
  $errors[] = '<br><strong>Please enter a valid Bill of Lading Number.</strong>';
}
if (empty($errors)) {
   $results = search_results($keywords);
   $results_num = count($results);
   $suffix = ($results_num !=1) ? 's' : '';
   foreach($results as $result) {
     echo "<br><table>
    <thead>
        <tr>
            <th><strong>B/L No.</strong></th>
            <th><strong>Origin City</strong></th>
            <th><strong>Origin Country</strong></th>
            <th><strong>Destination City</strong></th>
            <th><strong>Destination Country</strong></th>
            <th><strong>Status</strong></th>
            <th><strong>Current Location</strong></th>
        </tr>
    </thead>
    <tbody>";
  
    while ($row = mysql_fetch_assoc($results) {

    echo "
            <tr>
            <td> {$row['Bill_No']}</td>
            <td> {$row['Origin_City']}</td>
            <td> {$row['Origin_Country']}</td>
            <td> {$row['Destination_City']}</td>
            <td> {$row['Destination_Country']}</td>
            <td> {$row['Status']}</td>
            <td> {$row['Current_Location']}</td>
        </tr>
        ";
    
    }
    echo"
    </tbody>
</table>";
}
} else {
   foreach($errors as $error) {
    echo $error, '</br>';
  }
}
}
?>
</body>
</html>

Link to comment
Share on other sites

I can't test your code because I don't have your database, etc. set up. But try this and tell me what errors it puts out:

 

<?php include 'func.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>search</title>
</head>
<body>
<form action="" method="POST">
    <p>
        <input type="text" name="keywords" size="17" maxlength="9" value="Enter B/L No." onfocus="if(this.value == 'Enter B/L No.'){this.value = '';}" /> <input type="submit" class="formbutton" value="Track" />
    </p>
</form>
<?php
if  (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
  $errors[] = '';
} else if (strlen($keywords)<9) {
  $errors[] = '<br><strong>Your Bill of Lading Number must contain 9-digits.</strong>';
} else if (search_results($keywords) === false) {
  $errors[] = '<br><strong>Please enter a valid Bill of Lading Number.</strong>';
}
if (empty($errors)) {
   $results = search_results($keywords);
   $results_num = count($results);
   $suffix = ($results_num !=1) ? 's' : '';
   foreach($results as $result) {
     echo "<br><table>
    <thead>
        <tr>
            <th><strong>B/L No.</strong></th>
            <th><strong>Origin City</strong></th>
            <th><strong>Origin Country</strong></th>
            <th><strong>Destination City</strong></th>
            <th><strong>Destination Country</strong></th>
            <th><strong>Status</strong></th>
            <th><strong>Current Location</strong></th>
        </tr>
    </thead>
    <tbody>";
  
    while ($row = mysql_fetch_assoc($results) {

    echo "
            <tr>
            <td> {$row['Bill_No']}</td>
            <td> {$row['Origin_City']}</td>
            <td> {$row['Origin_Country']}</td>
            <td> {$row['Destination_City']}</td>
            <td> {$row['Destination_Country']}</td>
            <td> {$row['Status']}</td>
            <td> {$row['Current_Location']}</td>
        </tr>
        ";
    
    }
    echo"
    </tbody>
</table>";
}
} else {
   foreach($errors as $error) {
    echo $error, '</br>';
  }
}
}
?>
</body>
</html>

 

The page doesn't load now. It only opens up till the grey header and no page content is loaded. Should I send you the database file which you can directly import to the mysql database and also the func.inc.php, index.php and db.php file?

Link to comment
Share on other sites

It looks like you it's still outputting your old code. If you view the source, you can still see the echo statements on each $row, which I removed in my code.

 

Actually I had switched back to the previous code. Please check now and you'll see that the page isn't opening up.

Link to comment
Share on other sites

See those two lines of code in my signature? Put them at the top of the page, inside the php tags. Let me know if you get an error output to the screen and what it says.

 

There are 2 Errors. The first one says:

 

Notice: Undefined variable: celta_rss in /home7/sigmalog/public_html/wp-content/themes/revelation-theme/lib/theme-shortcodes.php on line 217

 

'theme-shortcodes.php' is a file inside my theme. This is the code inside that file:

 

<?php
/*============================================================ Layout Columns Shortcodes ============================================================*/
function celta_columns_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"size" => 'full-width',
	"last" => 'false',
	"title" => '',
	"subtitle" => ''
), $atts));

$clear = '';

if ( $last == 'true' ) {
	$last = ' last';
	$clear = '<div class="clear"></div>';
} else {
	$last = '';
}

$box_title = '';

if ( $title != '' ) {
	$box_title = '<div class="box-title">
					<h3>' .$title. '</h3>
					<span class="box-subtitle">' .$subtitle. '</span>
				</div>';
}

return '<div class="' . $size . $last . '">' . $box_title . do_shortcode( $content ) . '</div>' . $clear;

}

add_shortcode( 'column', 'celta_columns_shortcode' );

/*============================================================ Title Column Shortcodes ============================================================*/
function celta_title_col_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"title" => ''
), $atts));

$output = '<div class="title-col">
			   <h2>' . $title . '</h2>
			   ' . do_shortcode( $content ) . '
		   </div>';

return $output;

}

add_shortcode( 'title_column', 'celta_title_col_shortcode' );

/*============================================================ Numbered Box Shortcodes ============================================================*/
function celta_numbered_box_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"title" => '',
	"subtitle" => '',
	"number" => ''
), $atts));
		   
$output = '<div class="box-title">
				<span class="box-number">' . $number . '</span>
				<h3>' . $title . '</h3>
				<span class="box-subtitle">' . $subtitle . '</span>
			</div><!-- end box-title -->	
			' . do_shortcode( $content );

return $output;

}

add_shortcode( 'numbered_box', 'celta_numbered_box_shortcode' );

/*============================================================ Project Shortcodes ============================================================*/
function celta_project_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"type" => '',
	"link" => '',
	"image" => '',
	"title" => ''
), $atts));

if ( $type == 'video') $class = 'play'; else $class = 'zoom';

$output = '<a class="' .$class. '" href="' .$link. '" rel="prettyPhoto" title="' .$title. '"><img class="box-img" src="' .$image. '" alt="" /></a>
			<div class="box-title">
				<h4>' .$title. '</h4>
			</div><!-- end box-title -->	
			<p>' .$content. '</p>';

return $output;

}

add_shortcode( 'project', 'celta_project_shortcode' );

/*============================================================ Dropcap Shortcodes ============================================================*/
function celta_drop_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"type" => '',
), $atts));

if ( $type != 'colored' )

	$output = '<span class="dropcap-1">' .$content. '</span>';

else

	$output = '<span class="dropcap-2">' .$content. '</span>';

return $output;

}

add_shortcode( 'dropcap', 'celta_drop_shortcode' );

/*============================================================ Highlight Shortcodes ============================================================*/
function celta_high_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"type" => '',
), $atts));

if ( $type == 'alternative-1' )

	$output = '<span class="highlight-2">' .$content. '</span>';

elseif ( $type == 'alternative-2' )

	$output = '<span class="highlight-3">' .$content. '</span>';

else

	$output = '<span class="highlight-1">' .$content. '</span>';

return $output;

}

add_shortcode( 'highlight', 'celta_high_shortcode' );

/*============================================================ Divider Shortcodes ============================================================*/
function celta_divider_shortcode( $atts, $content = null ) {

return '<div class="separator-line"></div>';

}

add_shortcode( 'divider', 'celta_divider_shortcode' );

/*============================================================ Recent Posts Shortcodes ============================================================*/
function celta_recent_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"qty" => 1
), $atts));

$output = '<ul class="latest-news">';

$loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => $qty ) );

while ( $loop->have_posts() ) : $loop->the_post(); 

	$output .= '<li>';
		$output .= '<a href="' . get_permalink() . '" title=""><strong>' . get_the_title() . '</strong></a>';
		$output .= '<p>' . get_the_excerpt() . '</p>';
		$output .= '<span>' . get_the_time( 'j F, Y' ) . '</span>';
	$output .= '</li>';

endwhile;

$output .= '</ul>';

return $output;

}

add_shortcode( 'recent_posts', 'celta_recent_shortcode' );

/*============================================================ Social Profiles Shortcodes ============================================================*/
function celta_social_shortcode( $atts, $content = null ) {
require( CELTA_LIB . "theme-options-vars.php" );
$output = '<ul class="social-links">';

if ( $celta_blogger != '' )
	$output .= '<li class="blogger" title="Blogger"><a href="' . $celta_blogger . '"></a></li>';
if ( $celta_delicious != '' )
	$output .= '<li class="delicious" title="Delicious"><a href="' . $celta_delicious . '"></a></li>';
if ( $celta_deviantart != '' )
	$output .= '<li class="deviant" title="DeviantArt"><a href="' . $celta_deviantart . '"></a></li>';
if ( $celta_digg != '' )
	$output .= '<li class="digg" title="Digg"><a href="' . $celta_digg . '"></a></li>';
if ( $celta_facebook != '' )
	$output .= '<li class="facebook" title="Facebook"><a href="' . $celta_facebook . '" target="_blank"></a></li>';
if ( $celta_flickr != '' )
	$output .= '<li class="flickr" title="Flickr"><a href="' . $celta_flickr . '"></a></li>';
if ( $celta_forrst != '' )
	$output .= '<li class="forrst" title="Forrst"><a href="' . $celta_forrst . '"></a></li>';
if ( $celta_lastfm != '' )
	$output .= '<li class="lastfm" title="LastFM"><a href="' . $celta_lastfm . '"></a></li>';
if ( $celta_linkedin != '' )
	$output .= '<li class="linkedin" title="Linkedin"><a href="' . $celta_linkedin . '"></a></li>';
if ( $celta_myspace != '' )
	$output .= '<li class="myspace" title="MySpace"><a href="' . $celta_myspace . '"></a></li>';
if ( $celta_reddit != '' )
	$output .= '<li class="reddit" title="Reddit"><a href="' . $celta_reddit . '"></a></li>';
if ( $celta_tumblr != '' )
	$output .= '<li class="tumblr" title="Tumblr"><a href="' . $celta_tumblr . '"></a></li>';
if ( $celta_twitter != '' )
	$output .= '<li class="twitter" title="Twitter"><a href="' . $celta_twitter . '" target="_blank"></a></li>';
if ( $celta_vimeo != '' )
	$output .= '<li class="vimeo" title="Vimeo"><a href="' . $celta_vimeo . '"></a></li>';
if ( $celta_rss != '' )
	$output .= '<li class="rss" title="RSS"><a href="' . $celta_vimeo . '"></a></li>';

$output .= '</ul>';

return $output;

}

add_shortcode( 'social_profiles', 'celta_social_shortcode' );

/*============================================================ Tabs Shortcodes ============================================================*/
function celta_tabs_shortcode( $atts, $content = null ) {

return '<div class="tabs">' . do_shortcode( $content ) . '</div></div>';

}

add_shortcode( 'tabs', 'celta_tabs_shortcode' );

function celta_tabsNav_shortcode( $atts, $content = null ) {

return '<ul class="tab-nav">' . do_shortcode( $content ) . '</ul><div class="tab-panels">';

}

add_shortcode( 'tabsNav', 'celta_tabsNav_shortcode' );

function celta_tabLink_shortcode( $atts, $content = null ) {

return '<li><a href="#">' . $content . '</a></li>';

}

add_shortcode( 'tabLink', 'celta_tabLink_shortcode' );

function celta_tab_shortcode( $atts, $content = null ) {

return '<div>' . do_shortcode( $content ) . '</div>';

}

add_shortcode( 'tab', 'celta_tab_shortcode' );

/*============================================================ Pricing Table Shortcodes ============================================================*/
function celta_pricing_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"color" => '',
	"title" => '',
	"price" => ''
), $atts));

$output = '<div class="pricing-column">
				<div class="pricing-header">
					<div class="pricing-title '.$color.'">
						<h3>'.$title.'</h3>
					</div><!-- end pricing-title -->
					<div class="price">
						<p>'.$price.'</p>
					</div><!-- end price -->
				</div><!-- end pricing-header -->
				'.do_shortcode($content).'							
			</div>';

return $output;

}

add_shortcode( 'pricing_table', 'celta_pricing_shortcode' );

/*============================================================ Toggle Shortcodes ============================================================*/
function celta_toggle_shortcode( $atts, $content = null ) {

return '<div class="toggle-container">' . do_shortcode( $content ) . '</div>';

}

add_shortcode( 'toggle', 'celta_toggle_shortcode' );

function celta_toggle_title_shortcode( $atts, $content = null ) {


return '<div class="toggle-header"><h4>' . $content . '</h4><a class="toggle-link toggle-open" href="#"></a><div class="clear"></div></div>';

}

add_shortcode( 'toggle_title', 'celta_toggle_title_shortcode' );

function celta_toggle_box_shortcode( $atts, $content = null ) {

return '<div class="toggle-content">' . do_shortcode( $content ) . '</div>';

}

add_shortcode( 'toggle_content', 'celta_toggle_box_shortcode' );

/*============================================================ Content Boxes Shortcodes ============================================================*/
function celta_boxes_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"color" => ''
), $atts));

return '<div class="'.$color.'-info info-box">
			'.do_shortcode($content).'
		</div>';

}

add_shortcode( 'content_box', 'celta_boxes_shortcode' );

/*============================================================ Button Shortcodes ============================================================*/
function celta_button_shortcode( $atts, $content = null ) {

extract( shortcode_atts( array(
	"link" => ''
), $atts));

return '<a class="button" href="'.$link.'">' . do_shortcode( $content ) . '</a>';

}

add_shortcode( 'button', 'celta_button_shortcode' );

/*============================================================ Google Maps Shortcode ============================================================*/
function fn_googleMaps($atts, $content = null) {

extract(shortcode_atts(array(
	"width" => '640',
	"height" => '480',
	"src" => ''
), $atts));

return '<div id="google-map"><iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'"></iframe></div>';

}

add_shortcode("googlemap", "fn_googleMaps");

// Add Shortcodes to Widgets
add_filter('widget_text', 'do_shortcode');
?>

 

And the second one says:

 

Strict Standards: is_a(): Deprecated. Please use the instanceof operator in /home7/sigmalog/public_html/wp-includes/class-wp-error.php on line 207
Link to comment
Share on other sites

Was that with my code or yours? If it was with yours, put my code back and add those two lines to the top inside the php tags and tell me what the error says.

 

It was with my code. With your code, the page doesn't load and hence no error shows up. I wonder where we are getting wrong  :-\

Link to comment
Share on other sites

Ok. Back to basics. This may look ugly, but do this:

 

$results = search_results($keywords);
var_dump($results);

Also, we should have output $results instead of $row. Let's see what the var_dump says.

 

It says:

 

array(1) { [0]=> array(7) { ["Bill_No"]=> string(17) "B/L No: 123456789" ["Origin_City"]=> string(19) "Origin City: Mumbai" ["Origin_Country"]=> string(21) "Origin Country: India" ["Destination_City"]=> string(26) "Destination City: New York" ["Destination_Country"]=> string(45) "Destination Country: United States of America" ["Status"]=> string(17) "Status: Delivered" ["Current_Location"]=> string(52) "Current Location: New York, United States of America" } }

 

and then there's the table with the same type of results as before. I am now making the changes on my localhost.

 

This is how the code looks like:

 

<?php include 'func.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>search</title>
</head>
<body>
<form action="" method="POST">
    <p>
        <input type="text" name="keywords" size="17" maxlength="9" value="Enter B/L No." onfocus="if(this.value == 'Enter B/L No.'){this.value = '';}" /> <input type="submit" class="formbutton" value="Track" />
    </p>
</form>
<?php
if  (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
  $errors[] = '';
} else if (strlen($keywords)<9) {
  $errors[] = '<br><strong>Your Bill of Lading Number must contain 9-digits.</strong>';
} else if (search_results($keywords) === false) {
  $errors[] = '<br><strong>Please enter a valid Bill of Lading Number.</strong>';
}
if (empty($errors)) {
   $results = search_results($keywords);
   var_dump($results);
   $results_num = count($results);
   $suffix = ($results_num !=1) ? 's' : '';
   foreach($results as $result) {
     echo '<br><table>
    <thead>
        <tr>
            <th><strong>B/L No.</strong></th>
            <th><strong>Origin City</strong></th>
            <th><strong>Origin Country</strong></th>
            <th><strong>Destination City</strong></th>
            <th><strong>Destination Country</strong></th>
            <th><strong>Status</strong></th>
            <th><strong>Current Location</strong></th>
        </tr>
    </thead>
    <tbody>
    <?php
    while ($row = mysql_fetch_assoc($results) {
    ?>
        <tr>
            <td>echo $result["Bill_No"]</td>
            <td>echo $result["Origin_City"]</td>
            <td>echo $result["Origin_Country"]</td>
            <td>echo $result["Destination_City"]</td>
            <td>echo $result["Destination_Country"]</td>
            <td>echo $result["Status"]</td>
            <td>echo $result["Current_Location"]</td>
        </tr>
    <?php
    }
    ?>
    </tbody>
</table>';
}
} else {
   foreach($errors as $error) {
    echo $error, '</br>';
  }
}
}
?>
</body>
</html>

Link to comment
Share on other sites

Try this:

 

<?php include 'func.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>search</title>
</head>
<body>
<form action="" method="POST">
    <p>
        <input type="text" name="keywords" size="17" maxlength="9" value="Enter B/L No." onfocus="if(this.value == 'Enter B/L No.'){this.value = '';}" /> <input type="submit" class="formbutton" value="Track" />
    </p>
</form>
<?php
if  (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
  $errors[] = '';
} else if (strlen($keywords)<9) {
  $errors[] = '<br><strong>Your Bill of Lading Number must contain 9-digits.</strong>';
} else if (search_results($keywords) === false) {
  $errors[] = '<br><strong>Please enter a valid Bill of Lading Number.</strong>';
}
if (empty($errors)) {
   $results = search_results($keywords);
   $results_num = count($results);
   $suffix = ($results_num !=1) ? 's' : '';
   foreach($results as $result) {
     echo "<br><table>
    <thead>
        <tr>
            <th><strong>B/L No.</strong></th>
            <th><strong>Origin City</strong></th>
            <th><strong>Origin Country</strong></th>
            <th><strong>Destination City</strong></th>
            <th><strong>Destination Country</strong></th>
            <th><strong>Status</strong></th>
            <th><strong>Current Location</strong></th>
        </tr>
    </thead>
    <tbody>

        <tr>
<td>{$result['Bill_No']}</td>
<td>{$result['Origin_City']}</td>
<td>{$result['Origin_Country']}</td>
<td>{$result['Destination_City']}</td>
<td>{$result['Destination_Country']}</td>
<td>{$result['Status']}</td>
<td>{$result['Current_Location']}</td>
        </tr>
    </tbody>
</table>";
}
} else {
   foreach($errors as $error) {
    echo $error, '</br>';
  }
}
}
?>
</body>
</html>

[/code]

Link to comment
Share on other sites

Try this:

 

<?php include 'func.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>search</title>
</head>
<body>
<form action="" method="POST">
    <p>
        <input type="text" name="keywords" size="17" maxlength="9" value="Enter B/L No." onfocus="if(this.value == 'Enter B/L No.'){this.value = '';}" /> <input type="submit" class="formbutton" value="Track" />
    </p>
</form>
<?php
if  (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
  $errors[] = '';
} else if (strlen($keywords)<9) {
  $errors[] = '<br><strong>Your Bill of Lading Number must contain 9-digits.</strong>';
} else if (search_results($keywords) === false) {
  $errors[] = '<br><strong>Please enter a valid Bill of Lading Number.</strong>';
}
if (empty($errors)) {
   $results = search_results($keywords);
   $results_num = count($results);
   $suffix = ($results_num !=1) ? 's' : '';
   foreach($results as $result) {
     echo "<br><table>
    <thead>
        <tr>
            <th><strong>B/L No.</strong></th>
            <th><strong>Origin City</strong></th>
            <th><strong>Origin Country</strong></th>
            <th><strong>Destination City</strong></th>
            <th><strong>Destination Country</strong></th>
            <th><strong>Status</strong></th>
            <th><strong>Current Location</strong></th>
        </tr>
    </thead>
    <tbody>

        <tr>
<td>{$result['Bill_No']}</td>
<td>{$result['Origin_City']}</td>
<td>{$result['Origin_Country']}</td>
<td>{$result['Destination_City']}</td>
<td>{$result['Destination_Country']}</td>
<td>{$result['Status']}</td>
<td>{$result['Current_Location']}</td>
        </tr>
    </tbody>
</table>";
}
} else {
   foreach($errors as $error) {
    echo $error, '</br>';
  }
}
}
?>
</body>
</html>

[/code]

 

Finally its working  :D :D Thanks a lot for your help, bro!  :) Couldn't have found a better forum than phpfreaks to get my problem solved. Thanks a lot.

Link to comment
Share on other sites

I have another question. In the database, I have four 'Status' values, namely Initiated, Picked Up, In Transit and Delivered. Now I have four images corresponding to each Status Value which I want to be displayed when a person submits the form:

 

Initiated:

 

progress_initiated_ltr.gif

 

Picked Up:

 

progress_pickedup_ltr.gif

 

In Transit:

 

progress_intransit_ltr.gif

 

Delivered:

 

progress_delivered_ltr.gif

 

What I want is that when somebody's courier status is 'Initiated', the image assigned to the value 'initiated' should be displayed above the table. Just like this, when somebody's courier status is 'Delivered', the image assigned to the value 'delivered' should be displayed above the table and so on for each value. The code would be something like this (this is not a proper code, just an imitation of what I want)

 

If status=Delivered
show img: http://www.fedex.com/Tracking/track/images/detail/progress_delivered_ltr.gif
or else
If status=In Transit
show img: http://www.fedex.com/Tracking/track/images/detail/progress_intransit_ltr.gif
or else
If status=Picked Up
show img: http://www.fedex.com/Tracking/track/images/detail/progress_pickedup_ltr.gif
or else
If status=Initiated
show img: http://www.fedex.com/Tracking/track/images/detail/progress_initiated_ltr.gif

 

Please let me know if doing so is possible. Thanks.

Link to comment
Share on other sites

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.