Jump to content

Recommended Posts

weird...how about this:

<?php
include 'common.php';
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
print "<pre>Counter: $c\nResults:\n";
print_r($results);
exit;
if(!is_array($results[$c]) || !count($results[$c]))
  die("Customer not found");
$customer = mysql_fetch_assoc($results[$c]);
?>
<html>
   <head>
      <Title>Edit Customer</title>
   </head>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

ok...that is good...now what about this:

 

<?php
include 'common.php';
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
print "Rows: ".mysql_num_rows($results[$c]);
exit;
if(!is_array($results[$c]) || !count($results[$c]))
  die("Customer not found");
$customer = mysql_fetch_assoc($results[$c]);
?>
<html>
   <head>
      <Title>Edit Customer</title>
   </head>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

well...the join will produce a row for each order, instead of each customer. truthfully, every row should have the customer info, so that shouldn't be a problem. anyways, try this then:

<?php
include 'common.php';
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
print "<pre>Rows: ".mysql_num_rows($results[$c])."\nFirst Row:\n";
print_r(mysql_fetch_assoc($results[$c]));
exit;
if(!is_array($results[$c]) || !count($results[$c]))
  die("Customer not found");
$customer = mysql_fetch_assoc($results[$c]);
?>
<html>
   <head>
      <Title>Edit Customer</title>
   </head>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

Rows: 4

First Row:

Array

(

    [customer_id] => 21249

    [first_name] => *

    [last_name] => *

    [care_of] =>

    [address] => *

    [ups_address] =>

    [city] => Ames

    [states] => IA

    [zip] => 50010

    [country_id] => 0

    [email_address] => *

    [phone_number] => *

    [fax_number] => *

    [reseller] => 0

    [consultant] => 0

    [support_id] => 2

    [support_exp] => 0000-00-00 00:00:00

    [group_id] => 0

    [tax_id] =>

    [business] => 0

    [trac_count] => 0

    [funds_count] => 0

    [stock_count] => 0

    [site_count] => 0

    [combo_count] => 0

    [first_contact] => Shannon Roder

    [sort_id] =>

    [status_id] => 6

    [date_entered] => 0000-00-00 00:00:00

    [last_contact] => 0000-00-00 00:00:00

    [last_pur_date] => 0000-00-00 00:00:00

    [dealer_rating] =>

    [type_of_computer] =>

    [lit_status] => 0

    [lit_date] => 0000-00-00 00:00:00

    [cd_version] => 5

    [order_id] => 358

    [employee_id] => 5

    [shipping_method] => Normal

    [ship_date] => 0000-00-00 00:00:00

    [tax] => 0.00

    [tax_amt] => 0.00

    [ship_charge] => 0.00

    [price_list] => Retail

    [packing_printed] => 1

    [label_printed] => 1

    [total_payment] => 0.00

    [payment_method_id] => 4

    [PO_number] =>

    [CC_number] => *

    [CC_exp_date] => *

    [card_holder_name] =>

    [CC_sent_to_bank] => 1

    [COD_recieved] => 0

    [can_print] => 1

    [norm_has_seen] => 1

    [comments] =>

    [order_complete] => 0

    [internet_order_id] =>

)

 

Note:  Stars had data I however removed it for the post.

this this should work:

 

<?php
include 'common.php';
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
if(!mysql_num_rows($results[$c]))
  die("Customer not found");
$customer = mysql_fetch_assoc(mysql_fetch_assoc($results[$c]));
?>
<html>
   <head>
      <Title>Edit Customer</title>
   </head>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

oops...had two mysql_fetch_assoc in there:

 

<?php
include 'common.php';
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
if(!mysql_num_rows($results[$c]))
  die("Customer not found");
$customer = mysql_fetch_assoc($results[$c]);
?>
<html>
   <head>
      <Title>Edit Customer</title>
   </head>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

it should have worked a while ago, but i was having a brain fart.

 

the changes that were made:

-On the form, used full PHP tags, and added some spaces to make that echo work

-In the EditCustomer.php, dbQuery() returns a integer. That integer refers to a key in the $results global variable

-The value for that key in $results is a mysql resource, which you have to pull the row off using one of the mysql_fetch_* functions

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.