Dear Andres, i've been using your shop for a long time now, but the end of the year is near, and i have to change only the prices of all the articles, so i wanted to make a php page to show a big list with only all the article names and its price next to it so that i could change them all at once, instead of clicking all the articles one by one, but i don't know where to start with this code...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Build a page which creates a HTML-table from a SQL-query like
select item.ID, item.nr, iteminfo.name, price.value from item, iteminfo, price where item.ID=iteminfo.itemID and iteminfo.langID=1 and price.itemID=item.ID and pice.curID=$curID
Only one variable is needed: $curID, the id of currency. You can give it with URL &curID=1 or via dropdown. As you like it ;-)
The HTML-table is in a HTML-form with one submit button.
+ First lines you can use with phPay in another way:
<?php
include("header.inc.php");
$query_Recordset1 = db_query("..:") or db_die();
+ Remove from <html> until <body>
+ you should set the form-action to the filename where update-query is in. (maybe the same file).
Okay, update in file uaip.php (update-all-item-prices ;-)
<?php
include("header.inc.php");
for($i=0, $i<$count; $i++)
{
$upd = db_query("update price set value= $price[$i] where price.itemID=$itemID[$i] ") or db_die();
echo "."; // as controll for each entry
}
?>
Should be all.
If you wish to use the same file where form is in:
Add an hidden input field:
<input type=hidden name=mode value=update>
And put for...{} into an if($mode=="update") { for .... } before $query_Recordset1.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-10-23
when i make the file uaip.php :-) i get this error when i submit :
Parse error: parse error, unexpected ')', expecting ';' in C:\FoxServ\www\test\admin\uaip.php on line 3
This is my uaip.php file:
<?php
include("header.inc.php");
for ($i=0, $i<$count; $i++)
{
$upd = db_query("update price set value= $price[$i] where price.itemID=$itemID[$i] ") or db_die();
echo "."; // as controll for each entry
}
?>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-10-23
If fixed the little problem from above, but it still isn't updating i don't know what to do with the action stuff this is the code so far:
<?php
if($mode=="update") for($i=0; $i<$count; $i++)
{
$upd = db_query("update price set value= $price[$i] where price.itemID=$itemID[$i] ") or db_die();
echo "."; // as controll for each entry
}
?>
<?php
mysql_select_db($database_lanting, $lanting);
$query_Recordset1 = "SELECT item.ID, item.number, iteminfo.name, price.value FROM item, iteminfo, price WHERE item.ID=iteminfo.itemID and iteminfo.langID=1 and price.itemID=item.ID and price.curID=1 ";
$Recordset1 = mysql_query($query_Recordset1, $lanting) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
Hm, we update only one table ...
One question: The build of table with all items works so far?
I'll try to get ready or if someone else wish to do... don't fear.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-10-24
Jip that works, i get a list of the id's with the prices in a text field, but when i press submit it just reloads the page with the original values....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Andres, i've been using your shop for a long time now, but the end of the year is near, and i have to change only the prices of all the articles, so i wanted to make a php page to show a big list with only all the article names and its price next to it so that i could change them all at once, instead of clicking all the articles one by one, but i don't know where to start with this code...
Hm, interessting problem ;-)
A direction:
Build a page which creates a HTML-table from a SQL-query like
select item.ID, item.nr, iteminfo.name, price.value from item, iteminfo, price where item.ID=iteminfo.itemID and iteminfo.langID=1 and price.itemID=item.ID and pice.curID=$curID
Only one variable is needed: $curID, the id of currency. You can give it with URL &curID=1 or via dropdown. As you like it ;-)
The HTML-table is in a HTML-form with one submit button.
One line looks like:
<tr>
<td>
$row[1]
</td>
<td>
$row[2]
</td>
<td>
<input type=hidden name=itemID value="$row[0]">
<input type=text name=price[] value="$row[3]">
</td>
</tr>
The [ ] brackets are important!
After submit you update all prices:
for($i=0, $i<$count; $i++)
{
update price set value= $price[$i] where price.itemID=$itemID[$i]
}
Of course you have to put SQL-queries into functions and little bit more HTML, but that's the direction, I would take ;-)
Helpfull?
I've got it almost to work but i don't get the update/submit thing to work (i'am a total newbie with PHP/Mysql)
This is my code:
<?php require_once('Connections/lanting.php'); ?>
<?php
mysql_select_db($database_lanting, $lanting);
$query_Recordset1 = "select item.ID, item.number, iteminfo.name, price.value from item, iteminfo, price where item.ID=iteminfo.itemID and iteminfo.langID=1 and price.itemID=item.ID and price.curID=1 ";
$Recordset1 = mysql_query($query_Recordset1, $lanting) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="">
<p> </p>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>ID</td>
<td>number</td>
<td>name</td>
<td>value</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['ID']; ?></td>
<td><?php echo $row_Recordset1['number']; ?></td>
<td><?php echo $row_Recordset1['name']; ?></td>
<td><input type=text name=price[] value="<?php echo $row_Recordset1['value']; ?>"></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
+ First lines you can use with phPay in another way:
<?php
include("header.inc.php");
$query_Recordset1 = db_query("..:") or db_die();
+ Remove from <html> until <body>
+ you should set the form-action to the filename where update-query is in. (maybe the same file).
Okay, update in file uaip.php (update-all-item-prices ;-)
<?php
include("header.inc.php");
for($i=0, $i<$count; $i++)
{
$upd = db_query("update price set value= $price[$i] where price.itemID=$itemID[$i] ") or db_die();
echo "."; // as controll for each entry
}
?>
Should be all.
If you wish to use the same file where form is in:
Add an hidden input field:
<input type=hidden name=mode value=update>
And put for...{} into an if($mode=="update") { for .... } before $query_Recordset1.
when i make the file uaip.php :-) i get this error when i submit :
Parse error: parse error, unexpected ')', expecting ';' in C:\FoxServ\www\test\admin\uaip.php on line 3
This is my uaip.php file:
<?php
include("header.inc.php");
for ($i=0, $i<$count; $i++)
{
$upd = db_query("update price set value= $price[$i] where price.itemID=$itemID[$i] ") or db_die();
echo "."; // as controll for each entry
}
?>
If fixed the little problem from above, but it still isn't updating i don't know what to do with the action stuff this is the code so far:
<?php require_once('../Connections/lanting.php'); ?>
<?php
if($mode=="update") for($i=0; $i<$count; $i++)
{
$upd = db_query("update price set value= $price[$i] where price.itemID=$itemID[$i] ") or db_die();
echo "."; // as controll for each entry
}
?>
<?php
mysql_select_db($database_lanting, $lanting);
$query_Recordset1 = "SELECT item.ID, item.number, iteminfo.name, price.value FROM item, iteminfo, price WHERE item.ID=iteminfo.itemID and iteminfo.langID=1 and price.itemID=item.ID and price.curID=1 ";
$Recordset1 = mysql_query($query_Recordset1, $lanting) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<form name="form1" method="post" action="">
<p> </p>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>ID</td>
<td>number</td>
<td>name</td>
<td>value</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['ID']; ?></td>
<td><?php echo $row_Recordset1['number']; ?></td>
<td><?php echo $row_Recordset1['name']; ?></td>
<td><input type=hidden name=mode value=update><input type=text name=price[] value="<?php echo $row_Recordset1['value']; ?>"></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?php
mysql_free_result($Recordset1);
?>
Please try action="$PHP_SELF".
If the code below is yours, it cann't work, because the for is never used.
Notice: count is not defined ;-)
for ($i=0; $i<count($itemID); $i++) ... sorry I wrote wrong. I would write count(), the function which gives you number of elements of a given array.
I'am sorry i've tried it but i can't seem to solve it.
Maybe I'am wrong with the SQL-queries. I'll keep it in my mind and try myself ... but this can take a while.
When is the laste date to get ready? Maybe you don't want change all price on 31.12.2002 ;-?
i need to change it before 1st of november,
but about the sql query, someone told me that a select query in different tables can't be updated this way, or something like that....
Hm, we update only one table ...
One question: The build of table with all items works so far?
I'll try to get ready or if someone else wish to do... don't fear.
Jip that works, i get a list of the id's with the prices in a text field, but when i press submit it just reloads the page with the original values....
Maybe the price after reload are an old view from cache or similar?
If I find a little time, I'll try myself.