Page 1 of 1

MySQL query problem or php problem or both?

Posted: Wed Feb 16, 2005 1:12 pm
by praxedis
feyd | USE FORMATTING TAGS


I've included all the applicable code for a date range search that I created. It worked fine until I wanted to pull some data from another table into the recordset (indicated by "-->"). Now it's not working at all. Any help appreciated.

Code: Select all

<?php		

$gm_sql_server = "localhost";
$gm_sql_username = "root";
$gm_sql_password = "";
$gm_sql_database = "something";

$gm_db = mysql_connect($gm_sql_server, $gm_sql_username, $gm_sql_password) or gm_die("Unable to connect to database. Please check your gm MySQL server, username and password configuration options.");
mysql_select_db($gm_sql_database, $gm_db) or gm_die("Unable to select the database. Please check your gm MySQL database configuration option.");

$sy = $_REQUEST&#1111;"startYear"];
$sm = $_REQUEST&#1111;"startMonth"];
$sd = $_REQUEST&#1111;"startDate"];

$ey = $_REQUEST&#1111;"endYear"];
$em = $_REQUEST&#1111;"endMonth"];
$ed = $_REQUEST&#1111;"endDate"];

$repid = $_REQUEST&#1111;"repid"];

$start_date = $sy."-".$sm."-".$sd;
$end_date = $ey."-".$em."-".$ed;

$result = mysql_query ("Select * from orders WHERE DATE_FORMAT(nowtime, '%Y-%m-%d') BETWEEN DATE_FORMAT('$start_date', '%Y-%m-%d') AND DATE_FORMAT('$end_date', '%Y-%m-%d') and repID='$repid'", $gm_db);

//$product = mysql_query("select product_name.products, product_id.products, fk_product.orders from products, orders where fk_product.orders = product_id.products");

if ($result == "") &#123;

echo "no results";

 exit;
&#125; 

elseif (!$result)&#123;

echo "no results";

exit;
&#125;
else
&#123;
echo <<<EOF
<TABLE width="100%" BORDER=1 bordercolor="#eeeeee"><tr><td colspan="6">Searching from $start_date to $end_date.</td></tr>
<TR><td><b>Name</b></td><td><b>Sales Agent ID</b></td><td><b>Product</b></td><td><b>Date of Sale</b></td><td><b>Address</b></td><td><b>Phone</b></td></TR>
EOF;
 while ($item = mysql_fetch_object($result))
    &#123;

	-->$product_orders = $item->fk_product;
	--> $product = mysql_query("select p.product_name, p.product_id, o.fk_product from orders o, products p where p.product_id=$product_orders", $gm_db);
	--> $product_item = mysql_fetch_object($product);
	
        echo "<TR><TD>$item->firstname $item->lastname</TD><TD>$item->repID</TD><TD>$product_item->product_name</TD><TD>$item->nowtime</TD><TD>$item->address1<br />$item->address2<br />$item->city, $item->state &nbsp;$item->zip</TD><TD>$item->dayphone</TD></TR>";
		
	&#125;
	&#125;
	
	echo <<<EOF
</table>
EOF;

mysql_close($gm_db);

?>

feyd | USE FORMATTING TAGS

Posted: Wed Feb 16, 2005 1:18 pm
by feyd

Posted: Wed Feb 16, 2005 1:42 pm
by praxedis
Did you mean formatting tags for the post or in the code itself?

Posted: Wed Feb 16, 2005 1:45 pm
by feyd
in the post.