Jump to content

huntrguy102

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Everything posted by huntrguy102

  1. I have this code function showCart5() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM books WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $total += $price * $qty; $output[] = '<strong> $'.$total.'</strong>'; } } else { $output[] = ' '; } return join('',$output); } which is basically posting the final price. I am working on a book store and when someone puts in more than 1 different book. it posts the price of the first book and then the total price of both books. I think its a problem with the foreach part of the function. Is there a way I can replace the foreach with something else that will just post the final total? here is the link to the bookstore http://www.chulainnlibros.com/cart/index.php . If you try it your self you may have any idea of what I'm talking about.
  2. ok this is the code for image.php <?php $conn = mysql_connect('localhost,'username','password') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('database',$conn) or trigger_error("SQL", E_USER_ERROR); //table name is books $sql = "SELECT * FROM books ORDER BY id LIMIT 2"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); //the field with the binary dat is called image $image = $row['image']; header("Content-type: image/jpg"); // or whatever print $image; exit; ?> is this correct? when I look at this php in the browser, it gives me a bunch of random symbols and letters and numbers. Is that supposed to happen?
  3. And what about the <id>, what do I do with that?
  4. I have images stored in a mysql database. I have it as Type: Blob. It is binary data. my first question is: Did I go about putting the image in right? My second question is: How would I go about retrieving these images from the database? a very detailed explanation would be appreciated because I am basically lost at this point. Thanks.
  5. well the problem I am having is that I don't know how to have pictures in a database and then use php to post the images.
  6. I have a site with books in a database. I also have the names of the books corresponding with the I.D. number of the book in the database (i.e. 001.jpg = Book 1). So my question is, is their an way to post the pictures next to the information of the books on a page. I already have it so the information of the books (title, author, genre, etc.) are posted on a page, I just need the pictures (or thumbnails) next to them to show up. Any help would be appreciated.
  7. I have a database full of information of books (I.D.#, title, author, genre, publisher). What I need is for the 3 most recent books in the database to be posted on the website. Is there a way to use the I.D. numbers to post the most recent, so I could just add more books and it would update itself to the most recent. They are ordered 1,2,3,4 etc. the highest numbers being the most recent. Any help would be greatly appreciated. Thanks.
  8. thanks you very much. This worked perfectly
  9. I have a search engine for books on my website. I have it so they can search and book and then at it to a cart. When they click add to cart, it sends then to the cart page. I was wondering if there was a way to make it so I could send them back to the previous page they were at with a link, such as "Back to search Results"? Do you need a little bit more information to answer this question or is it good enough? Thanks.
  10. well i figured it out. It had nothing to do with what I was talking about.
  11. well here is the code from the index php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM books"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT id, title, author, price, Genre FROM books LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $output[] = '<ul>'; // while there are rows to be fetched... while ($row = mysql_fetch_assoc($result)) { // echo data $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].': '.$row['Genre'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } // end while $output[] = '</ul>'; echo join('',$output); /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Prev</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Next</a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>Last</a> "; } // end if /****** end build pagination links ******/ ?> and I just dont know how to get the add to cart button from here and put it into the search. here is the code for the search page: <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("amarroquin.db.5021301.hostedresource.com","amarroquin","Chulainnl1br0s"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("amarroquin") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "SELECT * FROM books WHERE title OR author LIKE \"%$trimmed%\" order by title"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; // google echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo $title; echo $author; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["title"]; $author = $row["author"]; echo "$count.) $title<br/>" ; echo "author"; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>&nbsp "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?>
  12. So I have a search engine that searches my database of books. http://chulainnlibros.com/cart/searching.html(they are spanish books so search something like "el" or "la"). So what I was wondering was, is there a way to add an add to cart button (like this one on my site http://chulainnlibros.com/cart/index.php). thanks
  13. ok so I put them in a directory. But I'm still not sure on how to fetch the data from the database and post it.
  14. I have books in a database and I have all the pictures that I want to use. Is there a way to have these pictures in a database to pull and put on a page using php?
  15. I have MySQL database full of data about books. I am able to display them all at once on a page. What I was wondering was if there is a way to be able to limit them to say 10 a page? How can I make a next 10 and previous 10 button?
  16. OK I tried the LIMIT 0, 30 and it works but I'm still a bit confused on what you're trying to say about changing to LIMIT 30, 60
  17. I have this PHP script that basically pulls from my MySql database. here is the code: <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php $sql = 'SELECT * FROM books ORDER BY author'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': $'.$row['price'].': '.$row['Genre'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> </div> </body> </html> My database is full of book data such as: title, author, price and genre. So my problem is not that the code doesn't work, it is that is jsut posts all 300 books all at once. Is there a way to have it show 10 at a time and then hit a next button to go to the next 10 and so forth, as well as a previous button?
  18. thank you haku thats all I needed to know
  19. ok that helps sort of. What I don't get (Im a noob) is, what tags do you mean. Like I know what tags are in html. But there is no HTML on the php page.
  20. I have a PHP file that pulls information from a database and posts them on the page. I was wondering how I would be able to stylized this page; because as of now it is just a white page with text nothing else. So is there a way to do this?
  21. Well nevermind thank you very much sader. the $s = $_GET['s'] made it work.
  22. the specific line that I think may be causing the problem is this line: $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >&gt</a>"; } but I'm not quite sure.
×
×
  • 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.