PHP/MySQL Help

From: Date: Tue, 10 Apr 2001 14:09:35 +0000
Subject: PHP/MySQL Help
Groups: php.windows 
Request: Send a blank email to php-windows+get-6604@lists.php.net to get a copy of this message
I am no stranger to programming, having done that professionally for 30+ years; however, PHP is a new animal to me. As usual, the text I have leave a little to be desired. The reason for this email is to ask for a little assistance in getting over a coding "speed bump". I am rewriting a shopping cart application for a local retailer. It was originally an informational site; but, with the request to add 2,500 items to his virtual store shelf I went into total rewrite mode. I had originally thought of using Access as the data base and mentioned this to my Java instructor last fall. He suggested I use PHP and MySQL since I'm on a Unix machine. I am not developing the maintenance routine. The tables have been created and the data base populated. All I want to do is access the tables to effect updates, deletes, and additions. There is the snag. I keep getting "object not defined" from PHP. Once I correct this, I feel I will be in a better position to continue with the order processing part, which is now a client-side Javascript routine. The code follows. If you could show me what I am going wrong, I would certainly appreciate the help. Matter of fact, I'd appreciate any pointers I could get. The essence of this module is: On initial entry, display the first 15 or so records from the data base; Whenever the "forward" button is pressed, display the next 15 records; Whenever the "backward" button is pressed, go backwards 15 records; Be able to go to the first record in the file; Be able to go to the last record in the file; Modify a record; Add a record; Delete a record; The code below is the portion that I want to be able to page forward and backward in the file. The table has seven entries, displayed on at a time rather than all seven on the page. This is because the product and customer tables have thousands of records and I want to be able to page through them record by record. <? /* Module: show_vendor.php Function: 1) When called from the root module [], this program displays the first
      vendor in the vendors MySQL database.
2) Present the user with options of:
      a)    Forward paging, with wrap around;
      b)    Reverse paging, with wrap around;
      c)    Modify the displayed vendor record;
      d)    Add a new vendor record;
      e)    Delete the displayed vendor record;
*/ //class show_vendor //{ $db_name = "healthspot"; $table_name = "vendors"; $connection = mysql_connect ("localhost","","") or die ("Couldn't connect to localhost"); $db = mysql_select_db ($db_name, $connection) or die ("Couldn't select $db_name"); $sql_statement =
       "
        SELECT Vactive, Vname, Vlogo_loc, Vlogo_height, Vlogo_width, Valink, Vdiscount
	     FROM $table_name
"; $result = mysql_query ($sql_statement, $connection) or die ("Couldn't execute msql_query: [$sql_statement]"); $rowmax = $number_of_rows = mysql_numrows($result); $rowmax--; $rowmin = 0; $TableRecord = -1; $Sequence = 2; function Advance_retreat($operation){
    GLOBAL $TableRecord;
    GLOBAL $Sequence;
    global $rowmax, $rowmin, $i;
    GLOBAL $db_name;
    GLOBAL $table_name;
    GLOBAL $connection;
    global $Sequence;
    $Sequence = 1;
/* print "<BR><BR>--> In function Advance_retreat before Retrieve call<BR>\n"; print "rowmax : $rowmax rowmin: $rowmin Sequence: $Sequence<br>\n"; print "operation: $operation<BR>\n"; */
    switch ($operation)
    {
        case 'L':
            $TableRecord = $rowmax;
            break;
        case '1':
            $TableRecord = $rowmin;
            break;
        case '-':
            if (($TableRecord - 1) < 0){
                $TableRecord = $rowmax;
            } else {
                --$TableRecord;
            }
            break;
        case '+':
            break;
        case 'A':
            break;
        case 'D':
            break;
        case 'M':
            break;
    }                                  // end of switch statement
    $db = mysql_select_db ($db_name, $connection) or die ("Couldn't select $db_name");
    $sql_statement =
         "
           SELECT Vactive, Vname, Vlogo_loc, Vlogo_height, Vlogo_width, Valink, Vdiscount
	       FROM $table_name
           LIMIT $TableRecord, 1
	     ";
    $result = mysql_query ($sql_statement, $connection) or die ("Couldn't execute msql_query:  [$sql_statement]");
    while ($row = mysql_fetch_array($result)){
      $vactive  = $row['Vactive'];
      if ($vactive == 0){
        $vactive = "No";
      } else if ($vactive == 1){
        $vactive = "Yes";
      }
      $vname = $row['Vname'];
      $vlogo = $row['Vlogo'];
      $vlogo_height = $row['Vlogo_height'];
      $vlogo_width = $row['Vlogo_width'];
      $valink = $row['Valink'];
      $vdiscount = $row['Vdiscount'];
/*
print "RETRIEVED --> vname       : $vname<BR>\n";
print "RETRIEVED --> vlogo_height: $vlogo_height<BR>\n"; print "RETRIEVED --> vdiscount : $vdiscount<BR>\n"; */
    }                                  // end of while loop
    $Sequence = 3;
    $temp = $GLOBALS['vname'];
/* print "<BR>--> In function Advance_retreat after Retrieve call<BR>\n";
  print "Sequence    : $Sequence<BR>\n";
  print "vactive     : $vactive<BR>\n";
  print "vname       : $vname<BR>\n";
  print "vlogo       : $vlogo<BR>\n";
print "vlogo_height: $vlogo_height<BR>\n"; print "vlogo_width : $vlogo_width<BR>\n";
  print "valink      : $valink<BR>\n";
print "vdiscount : $vdiscount<BR>\n"; print "globals[vname]: $temp<BR>\n"; */
    $display_block  = "<H3 STYLE=\"position: absolute; left: 525; top: 200\">$vactive</H3>";
    $display_block .= "<H3 STYLE=\"position: absolute; left: 525; top: 220\">$vname</H3>";
    $display_block .= "<H3 STYLE=\"position: absolute; left: 525; top: 240\">$vlogo</H3>";
    $display_block .= "<H3 STYLE=\"position: absolute; left: 525; top: 260\">$vlogo_height</H3>";
    $display_block .= "<H3 STYLE=\"position: absolute; left: 525; top: 280\">$vlogo_width</H3>";
    $display_block .= "<H3 STYLE=\"position: absolute; left: 525; top: 300\">$valink</H3>";
    $display_block .= "<H3 STYLE=\"position: absolute; left: 525; top: 320\">$vdiscount</H3>";
    echo $display_block;
  }                                    // end of Advance_Retreat function
//}                                       end of class definition
?> <?php Advance_retreat('1'); ?> As the usual case with anything pertaining to IT, this should have been done months ago. Bob Sears Owner WebWyshez rsears@onet.net www.on-net.net/~rsears/webwyshez/webwyshez.html

« previous php.windows (#6604) next »