Jump to content

elice

New Members
  • Posts

    2
  • Joined

  • Last visited

elice's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all, I have 3 files, namely, [custom.js / allitem.php / fetch_pages.php]. where i have been compiling, studying and at the same time create a website of my own. I am a total newbie, so i gather examples from the entire web and try to put it together. But right now, I am stuck for 3 long days going 4 days tomorrow in a single problem whereas my head is banging on how to do it. Also been searching in internet of the same problem this has. but unfortunately, i find similar but still cant get it to work. The codes below are currently working as I want it to be. Except from starting at this location, at [fetch_pages.php] --> <span class="page_name"><a class="show-popup" href="#?id='.$row['id'].'">'.$row['name'].'</a></span> Where I dont know how to retrieve the value of id='.$row['id'].' and passed it to below location and use it to query the products where id=$id. <div class="overlay-bg" id="overlay-bg"> <div class="overlay-content"> $result = mysql_query("SELECT * FROM products WHERE id=$id", $mysqli); </div> </div> Can anyone help me code it out from this. Please.... ---------------------------------------------------------------------------------------- custom.js $(document).ready(function(){ // show popup when you click on the link $('.show-popup').click(function(event){ event.preventDefault(); var docHeight = $(document).height(); var scrollTop = $(window).scrollTop(); $('.overlay-bg').show().css({'height' : docHeight}); $('.overlay-content').css({'top': scrollTop+20+'px'}); }); $('.close-btn').click(function(){ $('.overlay-bg').hide(); // hide the overlay }); $('.overlay-bg').click(function(){ $('.overlay-bg').hide(); }) $('.overlay-content').click(function(){ return false; }); document.getElementById('data-id').innerHTML = 'data-id'; return id = 'data-id' }); allitem.php <?php session_register(); session_start(); include("connect.php"); $catphp=$_GET["catphp"]; $_SESSION['catphp']=$catphp; //PAGINATION---------------------------------- $results = mysqli_query($mysqli,"SELECT COUNT(*) FROM products WHERE itemcon='$catphp'"); $get_total_rows = mysqli_fetch_array($results); //total records //break total records into pages $pages = ceil(($get_total_rows[0]/$item_per_page) + 1); //create pagination if($pages > 1) { $pagination = ''; $pagination .= '<ul class="paginate">'; for($i = 1; $i<$pages; $i++) { $pagination .= '<li><a href="#" class="paginate_click" id="'.$i.'-page">'.$i.'</a></li>'; } $pagination .= '</ul>'; } //PAGINATION---------------------------------- ?> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script type="text/javascript" src="overlay/custom.js"></script> <link href='overlay/overlaypopup.css' rel='stylesheet' type='text/css'> <script type="text/javascript"> $(document).ready(function() { $("#results").load("fetch_pages.php", {'page':0}, function() {$("#1-page").addClass('active');}); //initial page number to load $(".paginate_click").click(function (e) { $("#results").prepend('<div class="loading-indication"><img src="ajax-loader.gif" /> Loading...</div>'); var clicked_id = $(this).attr("id").split("-"); //ID of clicked element, split() to get page number. var page_num = parseInt(clicked_id[0]); //clicked_id[0] holds the page number we need $('.paginate_click').removeClass('active'); //remove any active class //post page number and load returned data into result element //notice (page_num-1), subtract 1 to get actual starting point $("#results").load("fetch_pages.php", {'page':(page_num-1)}, function(){ }); $(this).addClass('active'); //add active class to currently clicked element (style purpose) return false; //prevent going to herf link }); }); </script> </head> <body> <div id="results"></div> <?php echo $pagination; ?> </body> fetch_pages.php <?php session_start(); $catphp = $_SESSION['catphp']; include("connect.php"); //include config file ?><head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script type="text/javascript" src="overlay/custom.js"></script> <link href='overlay/overlaypopup.css' rel='stylesheet' type='text/css'> </head> <?php //sanitize post value $page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); //validate page number is really numaric if(!is_numeric($page_number)) { die('Invalid page number!'); } //get current starting point of records $position = ($page_number * $item_per_page); //Limit our results within a specified range. $results = mysqli_query($mysqli,"SELECT * FROM products WHERE itemcon='$catphp' ORDER BY id ASC LIMIT $position, $item_per_page"); //output results from database to a paginated window echo '<ul class="page_result">'; while($row = mysqli_fetch_array($results)) { echo '<li id="item_'.$row["id"].'">'.$row["id"].'. <span class="product-thumb"><img src="uploads/thumbs/'.$row['pic'].'"></span> <span class="page_name"><a class="show-popup" href="#?id='.$row['id'].'">'.$row['name'].'</a> </span> <br /><br /> <span class="page_description">'.$row["description"].' </span><br /><br /> <span class="page_itemcondesc">Condition : <span class="page_itemcon">'.$row["itemcon"].'</span> </span> <span class="page_warrantydesc">Warranty : <span class="page_warranty">'.$row["warranty"].'</span> </span> <br /><br /> <span class="page_price">Price:'.$row["price"].'</span> </li>'; } echo '</ul>'; ?> <div class="overlay-bg" id="overlay-bg"> <div class="overlay-content"> <font style="font-weight:bold">Product Details </font> <br /> <?php include "xx.isd"; $mysqli = mysql_connect($mysql_hostname,$mysql_user,$mysql_password); if (!$mysqli) { die("Database connection failed: " . mysql_error()); } //Select a database to use $db_select = mysql_select_db($mysql_database,$mysqli); //Perform database query to read the table entry $result = mysql_query("SELECT * FROM products WHERE id=$id", $mysqli); if (!$result) { die("Database query failed: " . mysql_error()); } //Use returned data while($row = mysql_fetch_array($result)) { $id=$row['id']; $product_code=$row['product_code']; $name=$row['name']; $description=$row['description']; $specs=$row['specs']; $accessory=$row['accessory']; $notes=$row['notes']; $itemcon=$row['itemcon']; $warranty=$row['warranty']; $price=$row['price']; $stocks=$row['stocks']; $category=$row['category']; $pic=$row['pic']; echo '<li id="item_'.$row["product_code"].'">'.$row["product_code"].' <span class="page_name">'.$row["name"].'</a> </span> <br /><br /> <span class="page_description">'.$row["description"].' </span><br /><br /> <span class="page_specs"><font style="font-weight:bold">Specification:</font> '.$row["specs"].' </span><br /><br /> <span class="page_accessory"><font style="font-weight:bold">Accessories:</font> '.$row["accessory"].' </span><br /><br /> <span class="page_notes"><font style="font-weight:bold">Notes:</font> '.$row["notes"].' </span><br /><br /> <span class="page_itemcon"><font style="font-weight:bold">Condition:</font> '.$row["itemcon"].' </span> <span class="page_itemcon"><font style="font-weight:bold">Warranty:</font> '.$row["warranty"].' </span><br /><br /> <span class="page_price"><font style="font-weight:bold">Price:</font> '.$row["price"].'</span> <span class="page_price"><font style="font-weight:bold">Stocks:</font> '.$row["stocks"].'</span> <br /><br /> </li>'; echo '<li id="item_">'.' <span class="product-thumb"><img src="uploads/thumbs/'.$row['pic'].'"></span> </li>'; } //Get images from upload_data $sql2="select file_name from upload_data where prod_name='$name'"; $result2=mysql_query($sql2,$mysqli) or die(mysql_error()); while($row2=mysql_fetch_array($result2)) { $name2=$row2['file_name']; ?> <span class="product-thumb"> <?php echo "<img src='../../uploads/thumbs/".$name2."'>"; ?> </span> <?php } //Close connection mysql_close($mysqli); ?> <br /> <button class="close-btn">Close</button> </div> </div> <?php echo '</ul>'; ?>
×
×
  • 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.