Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How do I get routine to know the proper row to edit
Old 03-23-2005, 11:29 AM How do I get routine to know the proper row to edit
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Hello,

The following routine is part of a program that displays 52 rows with these 2 fields at the end of each row which would be used for the purpose of updating (changing) either or both of the respective field(s) in that row. I'm at a loss as to how I would get the routine to know what row I'm editing:

Code:
  while ($myrow = mysql_fetch_array($result)) {

     echo "<tr><td>";
     echo "<form method='POST' ACTION='$PHP_SELF'>";
     echo "<input type='text' name='NRate' size=5 maxlength=5>";
     echo "<input type='submit' value='Go'>";
     $thisID = $myrow["ID"];
     echo "</form>";
     if (empty($NRate)) {
       } else {
        mysql_select_db("foo_bar", $db);
        $qrsql = "UPDATE reservations SET Rate = $NRate WHERE ID = $thisID LIMIT 1";
        $qrret = mysql_query($qrsql, $db) or die(mysql_error());
        $NRate="";
        }
     echo "</td><td align='center' width=50>";
     echo "<form method='POST' ACTION='$PHP_SELF'>";
     echo "<select name='NStatus'>";
     echo "<option VALUE='' SELECTED>  </option>";
     echo "<option VALUE='A'>Available</option>";
     echo "<option VALUE='B'>Booked</option>";
     echo "<option VALUE='P'>Pending</option>";
     echo "</select>";
     echo "<input type='submit' value='Go'>";
     $thisID = $myrow["ID"];
     echo "</form>";
     if (empty($NStatus)) {
        } else {
        echo $thisID;
        mysql_select_db ("foo_bar", $db);
        $qrsql = "UPDATE reservations SET Status = $NStatus WHERE ID = $thisID LIMIT 1";
        $qrret = mysql_query($qrsql, $db) or die(mysql_error());
        $NStatus="";
        }
    echo "</td></tr>";
  }
Also, if there's a better approach than what I have, I'm certainly open to suggestions.

Thanks in advance for any and all help.

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-23-2005, 11:50 AM Here is the whole thing
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
PHP Code:
<?
$link 
mysql_connect("localhost""user""pass") or exit("Could not connect to MySQL server!");
mysql_select_db("reservations"$link) or exit("Could not select 'reservations' database!");
if (!empty(
$_POST)) {
$sql "SELECT MIN(ID) as min_id, MAX(ID) as max_id FROM reservations";
 
$result mysql_query($sql$link) or exit("Could not execute '{$sql}'");
 
$row mysql_fetch_object($result);
for (
$i $row->min_id$i <= $row->max_id$i++) {
if (isset(
$_POST['Rate_new'][$i])) {
if ((
$_POST['Rate_new'][$i] && != $_POST['Rate_old'][$i]) || ($_POST['Status_new'][$i] && != $_POST['Status_old'][$i])) {
    
$sql "UPDATE reservations SET Rate = '{$_POST['Rate_new'][$i]}', Status = '{$_POST['Status_new'][$i]}' WHERE ID = '{$i}'";
    
mysql_query($sql$link) or exit("Could not execute '{$sql}'");
}
}
}
 
}
$sql "SELECT ID, Rate, Status FROM reservations WHERE 1";
$result mysql_query($sql$link) or exit("Could not execute '{$sql}'");
$output "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">\n<table border=\"0\">\n";
while (
$row mysql_fetch_object($result)) {
$a_sel "";
$b_sel "";
$p_sel "";
$row->Status strtolower($row->Status);
switch (
$row->Status) {
case 
"a":
$a_sel " selected";
break;
case 
"b":
$b_sel " selected";
break;
case 
"p":
$p_sel " selected";
break;
}
$output .= <<<END_ROW
<tr>
<td>
    <input type="text" name="Rate_new[
{$row->ID}]" value="{$row->Rate}" size="5" maxlength="5">
    <input type="hidden" name="Rate_old[
{$row->ID}]" value="{$row->Rate}">
</td>
</tr>
<tr>
<td>
    <select name="Status_new[
{$row->ID}]" size="1">
     <option></option>
     <option value="a"
{$a_sel}>Available</option>
     <option value="b"
{$b_sel}>Booked</option>
     <option value="p"
{$p_sel}>Pending</option>
    </select>
    <input type="hidden" name="Status_old[
{$row->ID}]" value="{$row->Status}">
</td>
</tr>
END_ROW;
}
$output .= "</table>\n</form>\n";
echo 
$output;
?>
Hope that helps. Let me know if it was coded right. I threw that together off the top of my head
__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!

Last edited by simptech; 03-23-2005 at 12:03 PM..
simptech is offline
Reply With Quote
View Public Profile
 
Old 03-23-2005, 06:57 PM
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Hi simptech,

Looks impressive and I think I can see your approach but being a noob, I'm still trying to break it down so I can understand it.

I did try running the script and got the following error:

Parse error: parse error, unexpected T_IS_NOT_EQUAL in ..... on line 27

I don't have an editor that shows line numbers but if my count is right it's in the following line:

PHP Code:
if (($_POST['Rate_new'][$i] && != $_POST['Rate_old'][$i]) || ($_POST['Status_new'][$i] && != $_POST['Status_old'][$i])) { 
I appreciate your assistance.

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
Old 03-25-2005, 08:13 AM
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
sorry. like i said, off the top of my head

PHP Code:
if (($_POST['Rate_new'][$i] != $_POST['Rate_old'][$i]) || ($_POST['Status_new'][$i] != $_POST['Status_old'][$i])) {
    
$sql "UPDATE reservations SET Rate = '{$_POST['Rate_new'][$i]}', Status = '{$_POST['Status_new'][$i]}' WHERE ID = '{$i}'";
    
mysql_query($sql$link) or exit("Could not execute '{$sql}'");

__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!
simptech is offline
Reply With Quote
View Public Profile
 
Old 04-02-2005, 01:10 AM
Yizit's Avatar
Experienced Talker

Posts: 44
Location: CT
Trades: 0
Hello simptech,

Sorry I hadn't gotten back to you sooner. My disability decided to flare up which pretty much put me on my back for a week.

Thank you for the modified code. I just tried it and got the message:

Parse error: parse error, unexpected $ in ....... on line 60

Again, since I don't have an editor that shows line numbers, my manual count would put that near the end of the script, but there's no "$" on line 60. By my count END_ROW;} was line 60. The closest lines to that where I see a "$" are the following:
Code:
    <input type="hidden" name="Status_old[{$row->ID}]" value="{$row->Status}">
</td>
</tr>
END_ROW;}
$output .= "</table>\n</form>\n";
echo $output;
?>
I did try changing the equates for "Status" to uppercase since that's how I have them in the database, but it made no difference.

Any thoughts about what might be causing the error?

I appreciate the help.

--Yizit
Yizit is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do I get routine to know the proper row to edit
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16192 seconds with 12 queries