Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

help to make a raw text page


Guest

Recommended Posts

Posted

hi, i'm trying to create a page that in raw text can show an order.

 

so far i have managed to get everything in place EXCEPT ordered items

 

i can list them perfectly if i exclude attributes...

 

so far i do like this for the items part:

 

$result = mysql_query("SELECT * FROM orders_products WHERE orders_id='".$_GET["o"]."'");
while($row = mysql_fetch_array($result))
 {
 echo $row['products_quantity']. " * " . $row['products_name'];
echo " - ";
echo "<br>";
}

$result = mysql_query("SELECT * FROM orders_products_attributes WHERE orders_id='".$_GET["o"]."'");
while($row = mysql_fetch_array($result))
 {
 echo $row['products_options_values'];
 echo "<br>";

 }

 

this lists the products fine, but the attributes are listed under the items, not next to each item as it's needed

 

what i want is:

 

products_quantity * products_name - products_options_values

 

 

i have looked and looked (prop the wrong places) but have hit a dead end here.

 

i call this script by adding "?o=5230" in the address bar, which tells it what order number i want to show, in this case 5230

 

main trouble is that the data is in 2 different tables, i know you can do a query from 2 tables but i have not been able to figure out how in my case...

 

and some products have attributes while others don't

 

how is the most simple way i can get what i want?

Posted

better example:

 

http://carputer1.com/testwebshop/arduino2.php?o=59

 

clearly shows my problem. The attributes "Alm" are listed under the prodicts and not next to the 2 pizza's (first product is a cola that has no attributes)

 

the code for the page:

 

<?php
$con = mysql_connect("localhost","webshoptest","1234");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }
mysql_select_db("webshoptest", $con);
$result = mysql_query("SELECT * FROM orders WHERE orders_id='".$_GET["o"]."'");
while($row = mysql_fetch_array($result))
 {
 echo "Ordrenummer: ".$row['orders_id'];
 echo "<br>";
 echo "<br>";
 echo "Bestilt: ". $row['date_purchased'];
 echo "<br>";
 echo "<br>";
 echo $row['delivery_name'];
 echo "<br>";
 echo $row['delivery_street_address'];
 echo "<br>";
 echo $row['delivery_postcode'] . " " . $row['delivery_city'];
 echo "<br>";
 echo "-------------------------------------------------";
 echo "<br>";
  }
$result = mysql_query("SELECT * FROM orders_products WHERE orders_id='".$_GET["o"]."'");
while($row = mysql_fetch_array($result))
 {
 echo $row['products_quantity']. " * " . $row['products_name'];
echo " - ";
echo "<br>";
}

$result = mysql_query("SELECT * FROM orders_products_attributes WHERE orders_id='".$_GET["o"]."'");
while($row = mysql_fetch_array($result))
 {
 echo $row['products_options_values'];
 echo "<br>";
   }
echo "-------------------------------------------------";
echo "<br>";
$result = mysql_query("SELECT * FROM orders_status_history WHERE orders_id='".$_GET["o"]."' AND orders_status_id=1");
while($row = mysql_fetch_array($result))
 {

 echo wordwrap($row['comments'], 39, "<br>\n");

 }
echo "<br>";
echo "-------------------------------------------------";

$result = mysql_query("SELECT * FROM orders WHERE orders_id='".$_GET["o"]."'");
while($row = mysql_fetch_array($result))
 {
   echo "<br>";
 echo "IP: ".$row['ipaddy'];
 echo "<br>";
 echo "Udbyder: ".$row['ipisp'];
 echo "<br>";
 echo "-------------------------------------------------";
 echo "<br>";
 echo "Betalingsmåde: ".$row['payment_method'];
 echo "<br>";
}

mysql_close($con);
?>

Posted

I would suggest to use the osCommerce functions for any queries etc.

 

Regarding how ro pull and display order data with products + attributes, you can take a look at the admin pages that do that (eg admin/orders.php or admin/invoice.php) or to the account_history_info.php they all do the same thing.

 

You basically don't need to query again for order data, just use the available orders class, usage examples also available in same files

Posted

its just that these raw text pages are complete seperate from oscommerce... they just query the same database..

 

its need to be like that so that the pages can be called without logging in to admin

 

 

in the end the plan is that an arduino can call the page and then print the result to a small thermal printer

Posted

Your attributes loop needs to be within the (per)product loop.

 

You should still use the usual way of accessing a database in osCommerce, in order to

ensure that your calls cannot be injected with bad things by anyone who knows how.

 

Just because you link to the database does not mean the display has to be how

osCommerce usually looks. There is no relationship between data and display other than

how you want it to appear.

Posted

well when i have done these pages they will be hidden well and named funny enough to make it hard to find

 

and its only me that will use the files, an arduino will open the pages to read the data and then print it...

 

but i know its a risk, i'm just that tad willing to take the risk..

 

in fact i have tried to stick the attributes loop inside the parent one...

 

$result = mysql_query("SELECT products_quantity, products_name FROM orders_products WHERE orders_id='".$_GET["o"]."'");
while($row = mysql_fetch_array($result))
{
echo $row['products_quantity']. " * " . $row['products_name'];

$result2 = mysql_query("SELECT products_options_values FROM orders_products_attributes WHERE orders_product_id='".$row['orders_products_id']."'");
while ($r = mysql_fetch_array($result2))
{
echo " + ";
echo $r['products_options_values'];
}
echo "<br>";
}

 

but i cant just figure where the fault is, the error i get is:

 

1 * Coca-Cola Zero 1,5 Liter

Notice: Undefined index: orders_products_id in C:\ftp\bo\testwebshop\arduino2.php on line 85

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\ftp\bo\testwebshop\arduino2.php on line 86

 

1 * 03. Amalfi

Notice: Undefined index: orders_products_id in C:\ftp\bo\testwebshop\arduino2.php on line 85

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\ftp\bo\testwebshop\arduino2.php on line 86

 

1 * 14. Cheese

Notice: Undefined index: orders_products_id in C:\ftp\bo\testwebshop\arduino2.php on line 85

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\ftp\bo\testwebshop\arduino2.php on line 86

Posted

just for the cause of making sure...

orders_product_id is in both tables and to me seems to be what links each product to its attribute

Posted

$row does not contain the orders_products_id, does it?

 

no and its here i'm stuck on this one for the moment...

Posted

Look at lines 101 -> 120 of account_history_info.php to see how it is done. Change the code to how you want it.

 

Also lines 36 & 37, to include and call the order class. And of course line 13.

Posted

for the fun of it i tried to call account_history_info.php directly... i needed to login to the shop... and then its where i cant code... the 101-120 part seems logic enough for me, but then i sure miss a query before that

Posted

The 101 - 120 part is showing you how to do what you was trying to do regarding a correct loop for products/attributes

 

There is no query in that file, the data comes from the order class (lines 36 - 37)

 

This all is possible because we have application_top.php included, this happens in line 13

 

In that way you can also use any functions etc available in osCommerce and don't need to connect to DB separately

 

The login check happens in lines 15 - 18

 

This file has all you need for what you want to do

Posted

well i think i might give up on this, far to complex for me, call me stupid but i can live with that

Posted

considering that i'm not the big "coder" genius, how long would it take for a coder to make those 2 pages i need?

 

1. a php page that if i add ?o=xxxx shows the order... this one i have almost done but it misses attribs next to the product

2. a php page that can i can add ?o=xxxx&s=y to update a spec. order to a given status

 

2. should work excatly as if i entered admin and updated the order by hand. it should just return 0 or 1 to tell if updated ok

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...