Jump to content

Alexhoward

Members
  • Posts

    310
  • Joined

  • Last visited

    Never

Everything posted by Alexhoward

  1. Sorry to push this again, but can anyone please help me...?
  2. can anyone please help... i'm soo stuck.....
  3. OK, let me narrow things down a bit... the calendars fine, and it displays ok (not great design but it works) i have an MySQL table that stores the date required i then want to be able to pull the dates, and display a "booked" results in that day on the calendar. the issue lies here : <?php //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die('Could not connect to mysql because ' . mysql_error()); //select the database mysql_select_db($db) or die('Could not select database because ' . mysql_error()); $query = ' SELECT * FROM book'; $result = mysql_query($query); while ($array= mysql_fetch_array($result)) { $booked = $array['date_req']; } ?> as i am only pulling the loop once to stop the table being duplicated, or a cell i only get the last result in the table, i only get on booking displayed... can anyone help me to do this properly? thank again!
  4. Hi Guys! I'm trying to create a simple calendar booking form, just for a bit of an education at the moment... I'm trying to display one result for if we're booked, and one for when we're available.. I've got the calendar working but am having trouble with the "we're booked" part.. the problem being that it will only pull back one result, and if i move the while loop further it will duplicate cells, or the entire table... any suggestions would be much appreciated! thanks in advance <?php include ('config.php'); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die('Could not connect to mysql because ' . mysql_error()); //select the database mysql_select_db($db) or die('Could not select database because ' . mysql_error()); $query = ' SELECT * FROM book'; $result = mysql_query($query); while ($array= mysql_fetch_array($result)) { $booked = $array['date_req']; } //This gets today's date if(!isset($_GET['date'])) { $_GET['date'] = time() ; } $date = $_GET['date'] ; //This puts the day, month, and year in seperate variables $day = date('d', $date) ; $month = date('m', $date) ; $year = date('Y', $date) ; //Here we generate the first day of the month $first_day = mktime(0,0,0,$month, 1, $year) ; //This gets us the month name $title = date('F', $first_day) ; //Here we find out what day of the week the first day of the month falls on $day_of_week = date('D', $first_day) ; //Once we know what day of the week it falls on, we know how many blank days occure before it. //If the first day of the week is a Sunday then it would be zero switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } //We then determine how many days are in the current month $days_in_month = cal_days_in_month(0, $month, $year) ; $days_left = ($days_in_month - $day) ; $days_gone = $day ; $next = $date + (($days_left + 1) * 24 * 60 * 60) ; $prev = $date - (($days_gone + 1) * 24 * 60 * 60) ; //Here we start building the table heads echo "<table border=1 width=700>"; echo "<tr><th colspan='7'><a href=availability.php?date=$prev style='text-decoration:none; color:#000000;'><<</a> $title $year <a href=availability.php?date=$next style='text-decoration:none; color:#000000';>>></a></th></tr>"; echo "<tr><td width=100>Sun</td><td width=100>Mon</td><td width=100>Tue</td><td width=100>Wed</td><td width=100>Thur</td><td width=100>Fri</td><td width=100>Sat</td></tr>"; //This counts the days in the week, up to 7 $day_count = 1; echo "<tr>"; //first we take care of those blank days while ( $blank > 0 ) { echo "<td bgcolor='#CCCCCC'> </td>"; $blank = $blank-1; $day_count++; } //sets the first day of the month to 1 $day_num = 1; //count up the days, untill we've done all of them in the month while ( $day_num <= $days_in_month ) { $booked_date = explode('-', $booked) ; if($booked_date[0] == $year && $booked_date[1] == $month && $booked_date[2] == $day_num ) { $book = 'Apologies we are booked <br> <a href=who.php>more info</a>' ; $colour = 'bgcolor=#A4A4FF' ; } else { $book = 'Available<p><input type=submit name=book value=book us>' ; $colour = 'bgcolor=#A6FFA6' ; } echo " <form> <td height='100' width='100' align='left' valign='top' $colour> <strong>$day_num</strong> <input type='hidden' name='when' value='$year-$month-$day_num'> <input type='hidden' name='date' value='$date'> <p> <div align='center'> $book </div> </td> </form>"; $day_num++; $day_count++; //Make sure we start a new row every week if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //Finaly we finish out the table with some blank details if needed while ( $day_count >1 && $day_count <=7 ) { echo "<td bgcolor='#CCCCCC'> </td>"; $day_count++; } echo "</tr></table>"; mysql_close($link) ; ?>
  5. That's great! however it will show all pages, for the purpose of the site i'm creating that will be fine, as there is not that many results. but how would you display it as it is at thee bottom of the php help page (for example)... cheers
  6. Good Morning, I have been looking for examples of how to display paging like that at the bottom of the php help page. Where it shows a number of results then "....." then the last page and when you move on it shows "1...11,12,13,14...285" could anyone point me to a good tutorial? i am pulling the results from MySQL Thanks in advance
  7. Hi Guys, Thanks for replying! apologies that i've only just managed to get back to the forum. I got it working by creating a 1px wide image, and stretching it by 100%. The problem seemed to be that html will stretch an image beond it's original size, but will not shrink it any lower. thanks again for your help!
  8. supposes it's html.... but this forum has been such a great help in the past i thought i'd ask here again.. say you had : <table width="100%"> <tr> <td></td> <td width="800"></td> <td></td> </tr> </table> i would like to only show the centre column on a resolution of 800 X 600, and the other two to start coming in on a higher resolution... but this doesn't seem to work...
  9. Hi Guys Bit embarrassed to ask this but... I’m creating a web page in 800 X 600, and I’d like to add an extra column each side that will fill the remained of the screen when view on a higher resolution. At the moment I have a table with 3 columns set at 100%, the centre column is set at 800px However I would like the outside 2 to shrink down to nothing when viewed on 800 X 600, and expand to whatever when viewed on a higher resolution, but this doesn’t seem to be happening Could someone please tell me where I’m going wrong… Thanks!!
  10. HI Guys, thanks for the replies. it was a silly question... i was trying to find the number of items in a users shopping basket. but obviously i can just add together all the quantities...!! I thought this would be a build in function thou...
  11. Hi Guys, probably a stupid question, but does anyone know how to count the number of active sessions...? also is it possible to just count a specific group of sessions...? i can't find the answer anywhere.. Thanks in advance!
  12. OK guys, so i've got it working like this : <?php session_start(); include("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); //select the database mysql_select_db($db) or die ("Could not select database because ".mysql_error()); if(!isset($_SESSION['customer'])) { $_SESSION['customer'] = "guest" ; } $num = "SELECT * FROM Customers WHERE username = '".$_SESSION['customer']."' " ; $cust = mysql_query($num); while ($array= mysql_fetch_array($cust)) { $custid = $array['id'] ; mysql_query("INSERT INTO ordernum VALUES('Null', '".$custid."', 'Null', CURRENT_TIMESTAMP)") ; } $ordnum = "SELECT * FROM ordernum WHERE date = CURRENT_TIMESTAMP " ; $number = mysql_query($ordnum); while ($array1= mysql_fetch_array($number)) { $ordernumber = $array1['id'] ; } foreach($_SESSION['a'] as $product_id => $quantity) { $query = "SELECT * FROM products WHERE id = '".$product_id."' " ; $result = mysql_query($query); while ($array= mysql_fetch_array($result)) { $prod = $array['name'] ; $price = number_format($array['price'],2) ; $line_total = number_format($quantity * $price,2) ; if(!isset($total)) { $total = 0 ; } $total = number_format($line_total + $total,2) ; mysql_query("INSERT INTO orders VALUES ('Null', '".$ordernumber."', '".$custid."', CURRENT_TIMESTAMP, '".$prod."', '".$quantity."', '".$total."', '1')") ; } } ?> a marked improvement.... however, what happens if the timestamps don't match... is it possible to put a tollerance on the time? or to possibly timeout if it takes longer than a second.....
  13. but the session should be set, so why would that be impacting it...? i got alot of help from here for this on too, so i'm not too sure what some bits are actually doing... cheers
  14. thanks for your help... i'm getting in a right muddle... here's what i've done..... looking at it i know it's messed up... <?php session_start(); include("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); //select the database mysql_select_db($db) or die ("Could not select database because ".mysql_error()); foreach($_SESSION['a'] as $product_id => $quantity) { $query = "SELECT * FROM products WHERE id = '".$product_id."' " ; $result = mysql_query($query); while ($array= mysql_fetch_array($result)) { $prod = $array['name'] ; $price = number_format($array['price'],2) ; $line_total = number_format($quantity * $price,2) ; if(!isset($total)) { $total = 0 ; } $total = number_format($line_total + $total,2) ; if(!isset($_SESSION['customer'])) { $_SESSION['customer'] = "guest" ; } $num = "SELECT * FROM Customers WHERE username = '".$_SESSION['customer']."' " ; $cust = mysql_query($num); while ($array1= mysql_fetch_array($cust)) { $custid = $array1['id'] ; mysql_query("INSERT INTO ordernum VALUES('Null', '".$custid."', '".$total."', CURRENT_TIMESTAMP)") ; $order = "SELECT * FROM ordernum WHERE id = '".$custid."' AND amount = '".$total."' " ; $ordernum = mysql_query($order); while ($array2= mysql_fetch_array($ordernum)) { $orderid = $array2['id'] ; mysql_query("INSERT INTO orders VALUES ('Null', '".$orderid."', '".$custid."', CURRENT_TIMESTAMP, '".$prod."', '".$quantity."', '".$total."', '1')") ; } } } } ?>
  15. Hi Guys, when i view the basket and it clears everything : using : echo session_id(); i get : ue9a0ops7javdrlr44fp5tkfl5 echo '<pre>' . print_r($_SESSION, true) . '</pre>'; i get : Array ( [a] => Array ( ) ) and i'm not sure what's ment by : error_reporting(E_ALL); ini_set('display_errors','On'); ? And echoing the session vars to check if they are correct? i'm still learning....
  16. hi, i tried this, the problem with doing this is that when i select it again to get the order id it only pulls one value and doesn't loop through all the sessions... any sugestions? thanks again
  17. Sorry, It's right at the start before a load of HTML <?php session_start(); ?>
  18. OK Thanks again i'll give it a go, because i'm using a timestamp thou, it may be a second off... sure there maust be somewway to tie them together, thanks for the push, great idea!
  19. Hello again F1Fan! that's a good idea, but how do i find the order id when inserting into both tables as it's created by an auto number...? what unique value would i have to ensure i select the correct one...?
  20. hi waynewex, thanks for the reply! it unsets the session, or set's it to zero, and displays "your basket is empty..."
  21. Hello again, i've had this issue running around for a while. my basket works fine, adding, removing, empting, everythings fine. except when you just view it navigating with: basket.php it removes everything! to add, empty, remove items i use basket.php?add=1, or basket.php?remove ans so on could some one please tell me why this is happening...? thanks in advance!! <?php include ("config.php"); //connect to the mysql server $link = mysql_connect($host, $db, $pass) or die("Could not connect to mysql because " . mysql_error()); //select the database mysql_select_db($db) or die("Could not select database because " . mysql_error()); // I replaced your two if statements with these: $product_id = isset ($_GET['id']) ? $_GET['id'] : " "; $action = isset ($_GET['action']) ? $_GET['action'] : " "; function productExists($product_id) { $sql = sprintf("SELECT id FROM products "); // You're missing stuff in your query here, specifically a WHERE clause return mysql_num_rows(mysql_query($sql)) > 0; } if (!productExists($product_id)) { die("Error. Product Doesn't Exist"); } if (!isset ($_SESSION['a'])) { $_SESSION['a'] = array (); } if (($action == "add" || $action == "remove") && !isset ($_SESSION['a'][$product_id])) { $_SESSION['a'][$product_id] = 0; } if ($action == "add") { $_SESSION['a'][$product_id]++; } elseif ($action == "remove") { $_SESSION['a'][$product_id]--; } elseif ($action = "empty") { $_SESSION['a'] = array (); } if (isset($_SESSION['a'][$product_id])&&@$_SESSION['a'][$product_id] == 0) { unset ($_SESSION['a'][$product_id]); } foreach ($_SESSION['a'] as $product_id => $quantity) { $sql = sprintf("SELECT name, description, price, pandp FROM products WHERE id = %d;", $product_id); $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { list ($name, $description, $price, $pandp) = mysql_fetch_row($result); $line_cost = $price * $quantity; if (!isset ($total)) { $total = 0; } $total = $line_cost + $total; if (!isset ($post)) { $post = 0; } $post = $pandp; print " <tr> <td width='66%'><span class='style2'>$name</span></td> <td width='15%' align='center' valign='middle'><span class='style2'><a href='basket.php?action=remove&id=$product_id'><img src='images/minus.jpg' alt='Remove' width='15' height='15' border='0' valign='middle' /></a> <input type='text' value='$quantity' style='width:30' /> <a href='basket.php?action=add&id=$product_id'><img src='images/plus.jpg' alt='Add' width='15' height='15' border='0' valign='middle' /></a></span></td> <td width='17%' align='right'><span class='style2'>£ $line_cost</span></td> </tr>"; } } if (!isset($_SESSION['a'][$product_id])&&@$_SESSION['a'][$product_id] == 0) { $total = 0.00; print " <tr> <td width='66%'><span class='style2'>Your Basket is Empty...</span></td> <td width='15%' align='center' valign='middle'><span class='style2'>0</span></td> <td width='17%' align='right'><span class='style2'>0.00</span></td> </tr>"; } ?>
  22. Hi Everybody! i've got a shopping basket, and each item added is saved into a session : $_SESSION['a'][$product_id] where 'a' saves the quantity and $product_id is the product id i'd like to be able to save the basket into mysql on one row, so i can have one unique order id, along with the customer id the only way i've found to do it is to use foreach, however this will obviously pull the sessions and insert them seperatly. i'd like to insert them as : | order_id | cust_id | date | products (as id, so 1,2,3) | quantity (e.g. 4,5,3) | price (e.g. 2.99,1.99,4.99) | so i can them pull the all out exploded again when customers want to see their order history.. could anyone please help me? thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.