Jump to content


Photo

Help with arrays


  • Please log in to reply
45 replies to this topic

#41 stualk

stualk
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 27 October 2006 - 10:15 AM

I already have but failed miserably!

I tried taking the if statements out regarding the quantity (code below) but that didn't work. I also tried changing the quantity in this code from 1 to 0 and even tried putting nothing at all but none of this works.

Can't think what else to try. I think i've almost done the right thing, but not quite!

// if a link has been clicked
if (isset($_GET['id'])){
   if (!isset($_SESSION['items'][$_GET['id']])){
      // if it the first time it's selected, quantity is 1
      $_SESSION['items'][$_GET['id']] = 1;
   }
   else {
      // if it's been selected before, increase it by 1
      $_SESSION['items'][$_GET['id']]++;
   }
}


#42 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 27 October 2006 - 10:43 AM

OK, it's always good to start with a plan, so how about this.  On all your product pages you allow people to add the product to the order form by selecting a link.  We have this in place already.  They can't decrease the quantity from these pages, they have to go to the order form for that, is that a fair assumption?

I think despite this being an order form, it should be treated like a shopping cart, with the same principles.

Then from the order form page, they can remove specific items, remove all items, or change the quantity for individual items?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#43 stualk

stualk
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 27 October 2006 - 10:50 AM

Yes that's a fair assumption. The quantity is dealt with on the order page.

It would be good if we could have an option to remove individual items from the order form but it's not crucial. The quantity issue is the main thing but if there's a way we can have a 'remove' option in a column beside each product as well that could be useful.

I have already put in a 'clear form' option and this works fine.

#44 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 27 October 2006 - 02:27 PM

Can you possibly provide me the complete code that you're using for the order page now.

I can work with that.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#45 stualk

stualk
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 27 October 2006 - 02:31 PM

Well you did ask...! :-D

<?php
if ($action =="" || $action=="default") {

print("
<form name=\"form1\" method=\"post\">
<input type=\"hidden\" name=\"action\" value=\"addscript\" size=\"20\">
");

if ($action =="" || $action=="default") {

$NumRows=mysql_query("SELECT * FROM customers") or die("Sorry Couldn't Complete Query_1");
$NumRows=mysql_num_rows($NumRows); 
if ($NumRows == "0") {
echo("<br><br><br><b>SORRY, PLEASE GO BACK AND TRY AGAIN.</b>");
}
else {
$Result = mysql_query("SELECT * FROM customers where id='$clientid'") or die("Sorry Couldn't Complete Query_2");
  $id = mysql_result($Result,0,0);
  $company_name = mysql_result($Result,0,3);
  $contact_name = mysql_result($Result,0,4);
  $address = mysql_result($Result,0,5);
  $town = mysql_result($Result,0,6);
  $county = mysql_result($Result,0,7);
  $post_code = mysql_result($Result,0,8);
  $email = mysql_result($Result,0,9);
  $telephone = mysql_result($Result,0,10);
  $mobile = mysql_result($Result,0,11);
}

if ($NumRows == "0") 	{
  echo ("<b>Sorry, please go back and try again.</b><br><br>");
}
else  {
$NumRows = mysql_query("SELECT * FROM customers where id='$clientid'") or die("Sorry Couldn't Complete Query_3");
$NumRows = mysql_num_rows($NumRows);
$Result = mysql_query("SELECT * FROM customers where id='$clientid'") or die("Sorry Couldn't Complete Query_4");
 for ($i=1; $i<=$NumRows; $i++) {
  if ($row = mysql_fetch_array($Result)) {
	$id = $row["id"];
	$company_name = $row["company_name"];
	$contact_name = $row["contact_name"];
	$address = $row["address"];
	$town = $row["town"];
	$county = $row["county"];
	$post_code = $row["post_code"];
	$email = $row["email"];
	$telephone = $row["telephone"];
	$mobile = $row["mobile"];

 }}}

	print("
		<table width='580' border='0' cellspacing='0' cellpadding='0'>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>Name: </font></b></td>
                  <td colspan='3'><input type='text' name='contact_name' value='$contact_name' size='50'></td>
                </tr>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>Company Name: </font></b></td>
                  <td colspan='3'><input type='text' name='company_name' value='$company_name' size='50'></td>
                </tr>
                <tr valign='top'> 
                  <td width='25%'><b><font face='Verdana' size='2'>Address: </font></b></td>
                  <td colspan='3'><textarea name=\"address\" cols=\"40\" rows=\"4\" wrap=\"VIRTUAL\">$address</textarea></td>
                </tr>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>Town: </font></b></td>
                  <td colspan='3'><input type='text' name='town' value='$town' size='25'></td>
                </tr>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>County: </font></b></td>
                  <td colspan='3'><input type='text' name='county' value='$county' size='25'></td>
                </tr>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>Post Code: </font></b></td>
                  <td colspan='3'><input type='text' name='post_code' value='$post_code' size='10'></td>
                </tr>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>Email: </font></b></td>
                  <td colspan='3'><input type='text' name='email' value='$email' size='35'></td>
                </tr>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>Daytime Telephone: </font></b></td>
                  <td colspan='3'><input type='text' name='telephone' value='$telephone' size='20'></td>
                </tr>
                <tr> 
                  <td width='25%'><b><font face='Verdana' size='2'>Mobile: </font></b></td>
                  <td colspan='3'><input type='text' name='mobile' value='$mobile' size='20'></td>
                </tr>
				<tr valign='top'> 
                  <td width='25%'><b><font face='Verdana' size='2'>Comments: </font></b></td>
                  <td colspan='3'><textarea name=\"comments\" cols=\"40\" rows=\"4\" wrap=\"VIRTUAL\"></textarea></td>
                </tr>
              </table>

<font face='Verdana' size='2'><br>Please enter your order details below and click the <b>Submit Order</b> button at the bottom to automatically send your order through to us.<br></font>

<font face='Verdana' size='2'><br>Alternatively, please click the <b>Print Order Form</b> button at the bottom to print and fax the order form to us.<br><br></font>

<table width='580' border='1' cellpadding='2' cellspacing='0' bordercolor='#000000'>
  <tr valign='top'>
    <td width='70%'><div align='center'><font size='2'><strong>Product Description</strong></font></div>
    </td>
    <td width='15%'><div align='center'><font size='2'><strong>Product Code</strong></font></div></td>
    <td width='15%'><div align='center'><font size='2'><strong>Quantity</strong></font></div></td>
  </tr>
");
?>


<?php session_start();

// clear the cart if the action is clear
if ($_GET['action'] == "clear"){
   unset($_SESSION['items']);
}

// if a link has been clicked
if (isset($_GET['id'])){
   if (!isset($_SESSION['items'][$_GET['id']])){
      // if it the first time it's selected, quantity is 1
      $_SESSION['items'][$_GET['id']] = 1;
   }
   else {
      // if it's been selected before, increase it by 1
      $_SESSION['items'][$_GET['id']]++;
   }
}

// put the array of id's into a string for use in the sql query
$sqlitems = implode(",", array_keys($_SESSION['items']));

// connect to the database
include_once('database.php');

// run the query to get the product name from the database
$sql = "SELECT id, brand_name, product_name, item_number FROM products WHERE id IN ($sqlitems)";
$result = mysql_query($sql) or die ("<b>Unable to run :</b> $sql<br>\n<br>\n<b>Because:</b> " . mysql_error());

// echo a row for each of our product lines
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   echo "<tr><td><font face='Verdana' size='2'>{$row['brand_name']} {$row['product_name']}</font></td><td><font face='Verdana' size='2'>{$row['item_number']}</font></td><td><input size=\"5\" type=\"text\" name=\"{$row['id']}\" value=\"{$_SESSION['items'][$row['id']]}\"></td></tr>\n";
}
?>

<?php
print ("
  <tr>
    <td>&nbsp;</td>
    <td><div align='center'>
      <input type='submit' name='Submit' value='Submit Order'>
    </div></td>
    <td><font face='Verdana' size='2'><b><div class='navlinks'><a href='order_form.php?action=clear'>CLEAR FORM</a></b></div></font></td>
  </tr>
</table>
</form>
");
}}

if ($action =="addscript" ) {

require ('mail.php');

if 	($multiple == "yes"){print("<meta http-equiv=\"refresh\" content=\"1;URL=?action=submitted\"><font face='Verdana' size='2'><br><br><br><br><br><br><br><br><br><br><br><b>Submitting order...</b><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");	}
else	{print("<meta http-equiv=\"refresh\" content=\"1;URL=?action=submitted\"><font face='Verdana' size='2'><br><br><br><br><br><br><br><br><br><br><br><b>Submitting order...</b><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");	}

// ------------------------------------------------------------------------------- action
if ($action =="submitted" ) {

print("<font face='Verdana' size='2'><br><br><br><br><br><br><br><br><br><b>Thank you.</b><br><br>Your order has been submitted and will be processed and dispatched within 5 working days.<br><br><br><br><br><br><br><br></font>");	

// ------------------------------------------------------------------------------- action
}}

?>	


#46 stualk

stualk
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 30 October 2006 - 09:42 AM

Hi Huggie,

I've been thinking about it over the weekend and I don't think we really need a 'remove item' button on the form. If people want to remove anything they can clear the form and start again, lazy so and sos!

The main thing I need to do is sort the small problem with the quantity keep resetting itself and not submitting properly to the email script. Do you know what could be causing this?

Once i've sorted that i'm a happy bunny!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users