Jump to content

digitalmartyr

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

digitalmartyr's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. ok so i tried the affected rows function and now, the information updates, but i still get an error message.... Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/rock925/admin/editproduct.php on line 156 here is my code, where i kick the update query to mysql, and process the results. anything else i can try? <?php }else{ //if pressed submit. $productId = $_POST['productid']; $updateTitle = cleanentry((isset($_POST['productname'])))?$_POST['productname']:""; $updatePrice = cleanentry((isset($_POST['productprice'])))?$_POST['productprice']:""; $updateDscrb = cleanentry((isset($_POST['productdesc'])))?$_POST['productdesc']:""; $updateDscrb = stripslashes($updateDscrb); $updateDscrb = trim($updateDscrb); $updateDscrb = str_replace("'","",$updateDscrb); $updateImg = cleanentry((isset($_POST['productimage'])))?$_POST['productimage']:""; $updateAvilb = cleanentry((isset($_POST['avil'])))?$_POST['avil']:""; $updateCategory = cleanentry((isset($_POST['productCat'])))?$_POST['productCat']:""; $updateCategory = str_replace("'"," ", $updateCategory); $file_dir = "../assets/productimages"; //designate file upload folder foreach($_FILES as $file_name => $file_array) { echo "name: ".$file_array['name']."<br>\n"; //file location $file_loc = $file_dir . "/" . $file_array['name']; if(is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], $file_loc) or die ("couldnt copy file"); echo "file was moved!<br>"; } } // create query $updateSql = "UPDATE products SET productname = '$updateTitle', productprice = '$updatePrice', productdscrb = '$updateDscrb', productimg = '$file_loc', available = '$updateAvilb', category = '$updateCategory' WHERE productid = '$productId';"; //echo $updateSql; $updateResult = mysql_query($updateSql)or die ("Error in query: $updateSql. " . mysql_error()); if(mysql_affected_rows($updateResult) > 0){ $updatedInfo = mysql_fetch_array($updateResult); { $html = '<div id="productThumb">'; $html .= '<input type="hidden" name="productid" value="<?php echo $productId; ?>">'; $html .= '<h3>product id: '.$updatedInfo['productid'].'</h3>'; $html .= '<h2>product name: '.$updatedInfo['productname'].'</h2>'; $html .= '<img height="140" width="100" src="'.$updatedInfo['productimg'].'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$info['productdscrb'].'</span>'; $html .= "<a href='{$_SERVER['PHP_SELF']}?page=editprod&productid=".$updatedInfo['productid'].">edit</a>"; $html .= '</div>'; echo $html; } } } ?>
  2. ok, i tried the mysql_data_seek() and i still got the same error. when i update the entry thats displayed i get this warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource so here is my code, im having issues with the second sql query which is to update the current viewed product. <?php session_start(); require('dbconnect.php'); require('functions.php'); if(!$_POST['submitUpdate']){ //if it hasnt been posted, show selected entry. $productId = (isset($_REQUEST['productid']))?$_REQUEST['productid']:""; //if productid is a number, its legit, so get it from the database if(preg_match("/^[0-9]+$/", $productId)) { $viewSql = "SELECT productname, productprice, productdscrb, productimg, available, category FROM products WHERE productid='$productId'"; $viewResult = mysql_query($viewSql)or die ("Error in query: $viewSql. " . mysql_error()); if(mysql_num_rows($viewResult) > 0){ $myproduct = mysql_fetch_array($viewResult); $productTitle = $myproduct['productname']; $productPrice = $myproduct['productprice']; $productCategory = $myproduct['category']; $productAvilb = $myproduct['available']; $productImg = $myproduct['productimg']; $productDscrb = stripslashes($myproduct['productdscrb']); $productDscrb = trim($productDscrb); $updateDscrb = str_replace("'","",$updateDscrb); $html = '<div id="productThumb">'; $html .= '<h3>product id: '.$productId.'</h3>'; $html .= '<h2>product name: '.$productTitle.'</h2>'; $html .= '<img height="140" width="100" src="'.$productImg.'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$productDscrb.'</span>'; $html .= '</div>'; echo $html; } } else { $message = "no products match that id"; } ?> <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'].'?page=editprod&productid='.$productId; ?>"> <span> <p class="form1"> <input type="hidden" name="productid" value="<?php echo $productId; ?>"> <label for="productname">Product Name:</label> <input type="text" name="productname" value="<?php if(isset($productTitle)){ echo $productTitle;} ?>"/> </p> </p> <p class="form1"> <label for="productname">Product Price:</label> <input type="text" name="productprice" value='<?php if(isset($productPrice)){ echo $productPrice;} ?>'/> </p> <h3>Product Available</h3> <p class="form1"> <input id="avil_yes" checked="checked" class="radio" name="avil" type="radio" value="yes" /> <lable for="avil_yes">Yes</lable> </p> <p class="form1"> <input id="avil_no" class="radio" name="avil" type="radio" value="no" /> <lable for="avil_no">No</lable> </p> <p> <h3>Product Category</h3> <select name="productCat" id="productCat"> <?php $getCats = "SELECT * FROM categories"; $catResult = mysql_query($getCats)or die(mysql_error()); while($cats = mysql_fetch_array($catResult)) { //$selected = ($cats['catid'] == $catid)? 'selected':''; echo "<option value=".$cats['catname'].">".$cats['catname']."</option>"; } ?> </select> </p> <p class="form1"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> <lable id="productimage">Product image:</label> <input type="file" name="productimage" value='<?php if(isset($productImg)){ echo $productImg;} ?>' > <p class="form1"> <label for="productname">Product Description:</label> <textarea type="textarea" name="productdesc" rows='10' cols='50'/> '<?php if(isset($productDscrb)){ echo $productDscrb;} ?>' </textarea> </p> <br /> <div id="subdiv"> <p class="submitarea"> <input type="submit" name="submitUpdate"/> </p> </div> </form> </fieldset> <?php }else{ //if pressed submit. $productId = $_POST['productid']; $updateTitle = cleanentry((isset($_POST['productname'])))?$_POST['productname']:""; $updatePrice = cleanentry((isset($_POST['productprice'])))?$_POST['productprice']:""; $updateDscrb = cleanentry((isset($_POST['productdesc'])))?$_POST['productdesc']:""; $updateDscrb = stripslashes($updateDscrb); $updateDscrb = trim($updateDscrb); $updateDscrb = str_replace("'","",$updateDscrb); $updateImg = cleanentry((isset($_POST['productimage'])))?$_POST['productimage']:""; $updateAvilb = cleanentry((isset($_POST['avil'])))?$_POST['avil']:""; $updateCategory = cleanentry((isset($_POST['productCat'])))?$_POST['productCat']:""; $updateCategory = str_replace("'"," ", $updateCategory); $file_dir = "../assets/productimages"; //designate file upload folder foreach($_FILES as $file_name => $file_array) { echo "name: ".$file_array['name']."<br>\n"; //file location $file_loc = $file_dir . "/" . $file_array['name']; if(is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], $file_loc) or die ("couldnt copy file"); echo "file was moved!<br>"; } } // create query $updateSql = "UPDATE products SET productname = '$updateTitle', productprice = '$updatePrice', productdscrb = '$updateDscrb', productimg = '$file_loc', available = '$updateAvilb', category = '$updateCategory' WHERE productid = '$productId';"; echo $updateSql; $updateQuery = mysql_query($updateSql); if(mysql_num_rows($updateQuery) > 0){ mysql_data_seek($updateQuery); $info = mysql_fetch_array($updateQuery); { $html = '<div id="productThumb">'; $html .= '<input type="hidden" name="productid" value="<?php echo $productId; ?>">'; $html .= '<h3>product id: '.$info['productid'].'</h3>'; $html .= '<h2>product name: '.$info['productname'].'</h2>'; $html .= '<img height="140" width="100" src="'.$info['productimg'].'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$info['productdscrb'].'</span>'; $html .= "<a href='{$_SERVER['PHP_SELF']}?page=editprod&productid=".$info['productid'].">edit</a>"; $html .= '</div>'; echo $html; } } } ?> thank you. chad
  3. I have an edit page for products on a website. when you click on edit to edit an item, it brings you to the edit page, and it echos out all the information on the db about the item. that part of the querys work. i have it that on submit, to process the form for the updates and the echo out the result, when it processes the updates it errors with this message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/rock925/admin/editproduct.php on line 136 here is my code <?php session_start(); require('dbconnect.php'); require('functions.php'); if(!$_POST['submitUpdate']){ //if it hasnt been posted, show selected entry. $productId = (isset($_REQUEST['productid']))?$_REQUEST['productid']:""; //if productid is a number, its legit, so get it from the database if(preg_match("/^[0-9]+$/", $productId)) { $viewSql = "SELECT productname, productprice, productdscrb, productimg, available, category FROM products WHERE productid='$productId'"; $viewResult = mysql_query($viewSql)or die ("Error in query: $viewSql. " . mysql_error()); if(mysql_num_rows($viewResult) > 0){ $myproduct = mysql_fetch_array($viewResult); $productTitle = $myproduct['productname']; $productPrice = $myproduct['productprice']; $productCategory = $myproduct['category']; $productAvilb = $myproduct['available']; $productImg = $myproduct['productimg']; $productDscrb = stripslashes($myproduct['productdscrb']); $productDscrb = trim($productDscrb); $updateDscrb = str_replace("'","",$updateDscrb); $html = '<div id="productThumb">'; $html .= '<h3>product id: '.$productId.'</h3>'; $html .= '<h2>product name: '.$productTitle.'</h2>'; $html .= '<img height="140" width="100" src="'.$productImg.'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$productDscrb.'</span>'; $html .= '</div>'; echo $html; } } else { $message = "no products match that id"; } ?> <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'].'?page=editprod&productid='.$productId.';' ?>"> <span> <p class="form1"> <input type="hidden" name="productid" value="<?php echo $productId; ?>"> <label for="productname">Product Name:</label> <input type="text" name="productname" value="<?php if(isset($productTitle)){ echo $productTitle;} ?>"/> </p> </p> <p class="form1"> <label for="productname">Product Price:</label> <input type="text" name="productprice" value='<?php if(isset($productPrice)){ echo $productPrice;} ?>'/> </p> <h3>Product Available</h3> <p class="form1"> <input id="avil_yes" checked="checked" class="radio" name="avil" type="radio" value="yes" /> <lable for="avil_yes">Yes</lable> </p> <p class="form1"> <input id="avil_no" class="radio" name="avil" type="radio" value="no" /> <lable for="avil_no">No</lable> </p> <p> <h3>Product Category</h3> <select name="productCat" id="productCat"> <?php $getCats = "SELECT * FROM categories"; $catResult = mysql_query($getCats)or die(mysql_error()); while($cats = mysql_fetch_array($catResult)) { //$selected = ($cats['catid'] == $catid)? 'selected':''; echo "<option value=".$cats['catname'].">".$cats['catname']."</option>"; } ?> </select> </p> <p class="form1"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> <lable id="productimage">Product image:</label> <input type="file" name="productimage" value='<?php if(isset($productImg)){ echo $productImg;} ?>' > <p class="form1"> <label for="productname">Product Description:</label> <textarea type="textarea" name="productdesc" rows='10' cols='50'/> '<?php if(isset($productDscrb)){ echo $productDscrb;} ?>' </textarea> </p> <br /> <div id="subdiv"> <p class="submitarea"> <input type="submit" name="submitUpdate"/> </p> </div> </form> </fieldset> <?php }else{ //if pressed submit. require('dbconnect.php'); $productId = $_POST['productid']; $updateTitle = cleanentry((isset($_POST['productname'])))?$_POST['productname']:""; $updatePrice = cleanentry((isset($_POST['productprice'])))?$_POST['productprice']:""; $updateDscrb = cleanentry((isset($_POST['productdesc'])))?$_POST['productdesc']:""; $updateDscrb = stripslashes($updateDscrb); $updateDscrb = trim($updateDscrb); $updateDscrb = str_replace("'","",$updateDscrb); $updateImg = cleanentry((isset($_POST['productimage'])))?$_POST['productimage']:""; $updateAvilb = cleanentry((isset($_POST['avil'])))?$_POST['avil']:""; $updateCategory = cleanentry((isset($_POST['productCat'])))?$_POST['productCat']:""; $updateCategory = str_replace("'"," ", $updateCategory); $updateSql = "UPDATE products SET productname = '$updateTitle', productprice = '$updatePrice', productdscrb = '$updateDscrb', available = '$updateAvilb', category = '$updateCategory' WHERE productid = '$productId'"; echo $updateSql; $updateQuery = mysql_query($updateSql); $info = mysql_fetch_array($updateQuery); { $html = '<div id="productThumb">'; $html .= '<h3>product id: '.$info['productid'].'</h3>'; $html .= '<h2>product name: '.$info['productname'].'</h2>'; //$html .= '<img height="140" width="100" src="'.$info['productimg'].'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$info['productdscrb'].'</span>'; $html .= "<a href='{$_SERVER['PHP_SELF']}?page=editprod&productid=".$info['productid'].">edit</a>"; $html .= '</div>'; echo $html; } } ?> i hope someone can help me with this, because i dont see where im going wrong thankyou very much
  4. so i have a catalog for user to view, to make it more friendly its broken down using pagination. it works, it breaks the entries into sets of 9 on every page. but information is only displayed on the first page. if you click next or previous, you get no entires. here is my code below, if someone can take a look at id be very greatful. thanx <?php require('dbconnect.php'); // if($_GET['page']) { $pagesection = $_GET['page']; } if(isset($_GET['cat'])) { $prodCat = $_GET['cat']; echo "<br />"; echo "Category: ".$prodCat; } // $pagenum = $_GET['pagenum']; if (empty($pagenum) || !is_numeric($pagenum)) { $pagenum = 1; } else { $pagenum = $_GET['pagenum']; } //make sure page number isnt below 1 or more than maxpages //get sql results and count //see what cat is called if($prodCat == 'all') { $data = "SELECT * FROM products"; $query = mysql_query($data)or die(mysql_error()); } else { $data = "SELECT * FROM products WHERE category = '$prodCat'"; $query = mysql_query($data)or die(mysql_error()); } $rows = mysql_num_rows($query); //number of results per page $page_rows = 9; //tells the page number of our last page $last = ceil($rows/$page_rows); //sets the range to display in our query $max = ' LIMIT '.($pagenum-1) * $page_rows.','.$page_rows; $limit = (($pagenum - 1) * $page_rows); echo "limit ".$limit; echo "pagenum ".$pagenum; echo "pagerow ".$page_rows; $maxquery = $data.$max; $qdata = mysql_query($maxquery)or die(mysql_error()); //run query to display results *style for display* //add $max to it for limiting result echo "<table>"; // initiate counter $i = 0; while($info = mysql_fetch_array($qdata)) { $html = '<div id="productThumb">'; $html .= '<h3>product id: '.$info['product_id'].'</h3>'; $html .= '<h2>product name: '.$info['product_name'].'</h2>'; $html .= '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$info['product_dscrb'].'</span>'; $html .= "<a href='{$_SERVER['PHP_SELF']}?product_id=".$info['product_id']."&page=editprod'>edit</a>"; $html .= '</div>'; if(($i + 1) % 3 == 1){ echo "<tr><td>$html</td>"; } elseif(($i + 1) % 3 == 2){ echo "<td>$html</td>"; } elseif(($i + 1) % 3 == 0){ echo "<td>$html</td></tr>"; } // increment counter $i++; // unset html var unset($html); } echo "</table>"; //shows user what page they are on and the total number of pages echo "<p>--page $pagenum of $last--<p>"; //check if on page 1, if so we dont need a link to the prev page or first page so do nothing //if we arent on page 1 we generate links to the first page and to the prev pages if($pagenum == 1) { } else { echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=1'> <<-First</a>"; echo " "; $previous = $pagenum-1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$previous'> <-Previous</a>"; } //this does the same above, only checking to see if we are on the last page //and then generating the NExt and Last link if($pagenum == $last) { } else { $next = $pagenum+1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$next'>Next-></a>"; echo " "; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$last'>Last->></a>"; } ?>
  5. go check this out, follow this tutorial, and you can do it with a million links. http://marek.litomisky.com/2007/01/10/php-switch-navigation-with-mod_rewrite/
  6. try putting the if statement where the header is in the first few lines of the code. are you getting a header alerady sent error? sometimes header doesnt work like it should if there are other things before it. Chad
  7. I tried this, it gets rid of the neg values in my limit, but now its not displaying information past the first page. $pagenum = $_GET['pagenum']; if (empty($pagenum) || !is_numeric($pagenum)) { $pagenum = 1; } else { $pagenum = $_GET['pagenum']; }
  8. try checking your spelling in the img src, you have it as scr.... thats gonna be the issue. its not the php its the html. Chad
  9. Its a simple catalog, where you can view products, and view them by category. Im using pagination to make the information more manageable. but when the user goes past page 1 of entires, my limit values goes negative. im not seeing where im going wrong. here is my code. thanx code: <?php require('dbconnect.php'); // if($_GET['page']) { $pagesection = $_GET['page']; } if(isset($_GET['cat'])) { $prodCat = $_GET['cat']; echo "<br />"; echo "Category: ".$prodCat; } // if (empty($pagenum) || !is_numeric($pagenum)){ $pagenum = 1;} $pagenum = $_GET['pagenum']; //make sure page number isnt below 1 or more than maxpages if($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //get sql results and count //see what cat is called if($prodCat == 'all') { $data = "SELECT * FROM products"; $query = mysql_query($data); } else { $data = "SELECT product_name, product_price, product_dscrb, product_img FROM products WHERE category = '$prodCat'"; $query = mysql_query($data); } $rows = mysql_num_rows($query); //number of results per page $page_rows = 3; //tells the page number of our last page $last = ceil($rows/$page_rows); //sets the range to display in our query $max = ' LIMIT '.($pagenum-1) * $page_rows.','.$page_rows; $limit = (($pagenum - 1) * $page_rows); //echo "limit ".$limit; //echo "pagenum ".$pagenum; //echo "pagerow ".$page_rows; $maxquery = $data.$max; $qdata = mysql_query($maxquery); //run query to display results *style for display* //add $max to it for limiting result echo "<table>"; // initiate counter $i = 0; while($info = mysql_fetch_array($qdata)) { $html = '<div id="productThumb">'; $html .= '<h3>product id: '.$info['product_id'].'</h3>'; $html .= '<h2>product name: '.$info['product_name'].'</h2>'; $html .= '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$info['product_dscrb'].'</span>'; $html .= '</div>'; if(($i + 1) % 3 == 1){ echo "<tr><td>$html</td>"; } elseif(($i + 1) % 3 == 2){ echo "<td>$html</td>"; } elseif(($i + 1) % 3 == 0){ echo "<td>$html</td></tr>"; } // increment counter $i++; // unset html var unset($html); } echo "</table>"; /*while($info = mysql_fetch_array($qdata)) { echo '<div id="productThumb">'; echo '<h3>product id: '.$info['product_id'].'</h3>'; echo '<h2>product name: '.$info['product_name'].'</h2>'; echo '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; echo '<span>Product Describtion '.$info['product_dscrb'].'</span>'; echo '</div>'; }*/ //shows user what page they are on and the total number of pages echo "<p>--page $pagenum of $last--<p>"; //check if on page 1, if so we dont need a link to the prev page or first page so do nothing //if we arent on page 1 we generate links to the first page and to the prev pages if($pagenum == 1) { } else { echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=1'> <<-First</a>"; echo " "; $previous = $pagenum-1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$previous'> <-Previous</a>"; } //this does the same above, only checking to see if we are on the last page //and then generating the NExt and Last link if($pagenum == $last) { } else { $next = $pagenum+1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$next'>Next-></a>"; echo " "; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$last'>Last->></a>"; } ?>
  10. ok so what i have going on here is a catalog system where users can go and view products and view them by order category. each page displays no more than 9 entires at a time thru pagination. the thing is, when you try and view page 2 or results or press the next link, i get an error.... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. so i figure it has to do something with the pagenum variable, but dont know how to fix it. heres my code. thanx for the help. <?php require('dbconnect.php'); // if($_GET['page']) { $pagesection = $_GET['page']; } if(isset($_GET['cat'])) { $prodCat = $_GET['cat']; echo "<br />"; echo "Category: ".$prodCat; } // if (empty($pagenum) || !is_numeric($pagenum)){ $pagenum = 1;} $pagenum = $_GET['pagenum']; //make sure page number isnt below 1 or more than maxpages if($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //get sql results and count //see what cat is called if($prodCat == 'all') { $data = "SELECT * FROM products"; $query = mysql_query($data); } else { $data = "SELECT product_name, product_price, product_dscrb, product_img FROM products WHERE category = '$prodCat'"; $query = mysql_query($data); } $rows = mysql_num_rows($query); //number of results per page $page_rows = 3; //tells the page number of our last page $last = ceil($rows/$page_rows); //sets the range to display in our query $max = ' LIMIT '.($pagenum-1) * $page_rows.','.$page_rows; $limit = (($pagenum - 1) * $page_rows); //echo "limit ".$limit; //echo "pagenum ".$pagenum; //echo "pagerow ".$page_rows; $maxquery = $data.$max; $qdata = mysql_query($maxquery); //run query to display results *style for display* //add $max to it for limiting result echo "<table>"; // initiate counter $i = 0; while($info = mysql_fetch_array($qdata)) { $html = '<div id="productThumb">'; $html .= '<h3>product id: '.$info['product_id'].'</h3>'; $html .= '<h2>product name: '.$info['product_name'].'</h2>'; $html .= '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; $html .= '<br />'; $html .= '<span>Product Describtion '.$info['product_dscrb'].'</span>'; $html .= '</div>'; if(($i + 1) % 3 == 1){ echo "<tr><td>$html</td>"; } elseif(($i + 1) % 3 == 2){ echo "<td>$html</td>"; } elseif(($i + 1) % 3 == 0){ echo "<td>$html</td></tr>"; } // increment counter $i++; // unset html var unset($html); } echo "</table>"; /*while($info = mysql_fetch_array($qdata)) { echo '<div id="productThumb">'; echo '<h3>product id: '.$info['product_id'].'</h3>'; echo '<h2>product name: '.$info['product_name'].'</h2>'; echo '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; echo '<span>Product Describtion '.$info['product_dscrb'].'</span>'; echo '</div>'; }*/ //shows user what page they are on and the total number of pages echo "<p>--page $pagenum of $last--<p>"; //check if on page 1, if so we dont need a link to the prev page or first page so do nothing //if we arent on page 1 we generate links to the first page and to the prev pages if($pagenum == 1) { } else { echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=1'> <<-First</a>"; echo " "; $previous = $pagenum-1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$previous'> <-Previous</a>"; } //this does the same above, only checking to see if we are on the last page //and then generating the NExt and Last link if($pagenum == $last) { } else { $next = $pagenum+1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$next'>Next-></a>"; echo " "; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$last'>Last->></a>"; } ?>
  11. so whats going on here is that if i comment out the area where the limit is added onto the query the query works and my data gets displayed. if i try to add into the mysql query the limit statement, its goes wrong. what can i do? <?php require('dbconnect.php'); // if($_GET['page']) { $pagesection = $_GET['page']; } if(isset($_GET['cat'])) { $prodCat = $_GET['cat']; echo $prodCat; } // if(!(isset($pagenum))) { //no page number default to 1 $pagenum = 1; } //get sql results and count //see what cat is called if($prodCat == 'all') { $data = mysql_query("SELECT * FROM products"); } else { $data = mysql_query("SELECT product_name, product_price, product_dscrb, product_img FROM products WHERE category = '$prodCat'"); } // $rows = mysql_num_rows($data); //number of results per page $page_rows = 3; //tells the page number of our last page $last = ceil($rows/$page_rows); //make sure page number isnt below 1 or more than maxpages if($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //sets the range to display in our query //$max = ' LIMIT '.($pagenum-1) * $page_rows.','.$page_rows; //$maxquery = $data.$max; //echo $maxquery; //run query to display results *style for display* //add $max to it for limiting result //$data = mysql_query($maxquery); while($info = mysql_fetch_array($data)) { echo '<div id="productThumb">'; echo '<h3>product id: '.$info['product_id'].'</h3>'; echo '<h2>product name: '.$info['product_name'].'</h2>'; echo '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; echo '<span>Product Describtion '.$info['product_dscrb'].'</span>'; echo '</div>'; } //shows user what page they are on and the total number of pages echo "<p>--page $pagenum of $last--<p>"; //check if on page 1, if so we dont need a link to the prev page or first page so do nothing //if we arent on page 1 we generate links to the first page and to the prev pages if($pagenum == 1) { } else { echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=1'> <<-First</a>"; echo " "; $previous = $pagenum-1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$previous'> <-Previous</a>"; } //this does the same above, only checking to see if we are on the last page //and then generating the NExt and Last link if($pagenum == $last) { } else { $next = $pagenum+1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$next'>Next-></a>"; echo " "; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$last'>Last->></a>"; } ?>
  12. wow, i thought it was through nested loops. The way you showed me, is it possible to use a while loop instead of a for loop, because im pulling data from a database, and im echoing divs with data inside like this while($info = mysql_fetch_array($data)) { echo '<div id="productThumb">'; echo '<h3>product id: '.$info['product_id'].'</h3>'; echo '<h2>product name: '.$info['product_name'].'</h2>'; echo '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; echo '<span>Product Describtion '.$info['product_dscrb'].'</span>'; echo '</div>'; }
  13. I need to take my mysql result and take those results and print them out, one by one, in a 3 by 3 grid, i understand that a nested loop is what it will take to make this happen, but im having trouble writing it, if someone can get me started in the right direction, it would be most appriciated.
  14. Im trying to have a list of products for the user to view. in my index.php i have this code . .it contains the viewproducts.php, and has links to pass variables to the url. index.php <?php session_start(); if(!$_SESSION['USERNAME'] == '') { $sessionUser = $_SESSION['USERNAME']; $sessionLogged = $_SESSION['LOGGEDIN']; } else { header("Location: ../login.php?logout='yes'"); } if($_POST['logout']) { session_destroy(); $logoutValue = 'yes'; header("Location: ../login.php?logout='yes'"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> <link rel="stylesheet" href="assets/styles/master.css" type="text/css" media="screen" title="Master" charset="utf-8" /> <!--[if IE 6]> <link rel="stylesheet" href="assets/styles/ie6.css" type="text/css" media="screen" title="Master" charset="utf-8" /> <![endif]--> </head> <body> <div id="container"> <div id="banner"> <h1><a href="index.php">Rock 925 - Est. 1990</a></h1> </div><!--end of "banner"--> <div id="sideNav"> <div id="searchBox"> <br /><br /> <form action="search.php" method="GET" name="form1" target="_self" id="form1"> <label> <input name="SearchString" type="text" id="SearchString" size="15" value="Enter Keywords" /> </label> <input type="submit" name="Submit" id="submit" value="Search" align="baseline" /> </form> <br /> <center><hr /></center> </div><!--end of "searchBox"--> <div> <h3>Site Management</h3> <br /><br /> <ul> <li><a href="index.php?page=addprod">Add Product</a></li> <li><a href="index.php?page=addcat">Add Category</a></li> <li><a href="index.php?page=viewall&cat=all">View all Products</a></li> <li><a href="#">View by Category</a></li> <li class="sublist"><a href="index.php?page=viewall&cat=pendants" class="subcategory">Pendants</a></li> <li class="sublist"><a href="index.php?page=viewall&cat=chains" class="subcategory">Chains</a></li> <li class="sublist"><a href="index.php?page=viewall&cat=earings" class="subcategory">Earings</a></li> <li class="sublist"><a href="index.php?page=viewall&cat=rings" class="subcategory">Rings</a></li> <li class="sublist"><a href="index.php?page=viewall&cat=misc" class="subcategory">Misc</a></li> </ul> <br /> <center><hr /></center> </div><!--end of "categoryBox"--> <div id="mailingBox"> <form class="mailingList" enctype="multipart/form-data" method="post" action=""> <h2>Join our Mailing List</h2> <label class="desc" id="title0" for="Field0"> <span class="smText">Your Email Address</span> </label> <input id="Field0" class="field text large" name="Field0" tabindex="1" size="15" type="text" maxlength="255" value="" /> <input id="saveForm" class="btTxt" type="submit" tabindex="2" value="Submit" /> </form> </div><!--end "mailingBox"--> </div><!--end of "sideNav"--> <div id="topNav"> <ul> </ul> </div><!--end of "topNav"--> <div id="mainContent"> <div class="box"> <div class="box-outer"> <div id="varContent"> <!------------------------------------------------ DO NOT CHANGE ANYTHING ABOVE THIS LINE!! ---> <!------------------------------------------------ **START** EDITABLE CONTENT BELOW!! ---> <div id="userInfo"> <?php if(!isset($sessionUser) =='') { echo "<span>Welcome back ".$sessionUser."</span>"; echo "<br />"; } if(!isset($sessionLogged) =='') { echo "<span>Logged in at ".$sessionLogged."</span>"; echo "<br />"; } ?> <a href='<?php echo "../login.php?logout=yes";?>' >Logout</a> </div><!--end of userInfo --> <div id='dynamicContent'> <?php $page = $_GET['page']; switch($page){ case "addprod": $content = "addproduct.php"; break; case "viewall": $content = "viewproducts.php"; break; default: $content = "addproduct.php"; break; } include($content); ?> </div> <!------------------------------------------------ **END** EDITABLE CONTENT!! ---> <!------------------------------------------------ DO NOT CHANGE ANYTHING BELOW THIS LINE!! ---> </div> </div> </div> </div><!--end of "mainContent"--> <div id="footer"> <br /><br /><br /><br /> <br /><br /><br /><br /> <p align="center">©2008 Rock9Twenty5.com All Rights Reserved.</p> <br /><br /><br /><br /> </div><!--end of "container"--> </body> </html> and here is the viewproducts.php <?php require('dbconnect.php'); // if($_GET['page']) { $pagesection = $_GET['page']; } if($_GET['cat']) { $prodCat = $_GET['cat']; echo $prodCat; } // if(!(isset($pagenum))) { //no page number default to 1 $pagenum = 1; } //get sql results and count //see what cat is called if($prodCat == 'all') { $data = mysql_query("SELECT * FROM products"); } else { $data = mysql_query("SELECT product_name, product_price, product_dscrb, product_img FROM products WHERE category = '$prodCat'"); } // $rows = mysql_num_rows($data); //number of results per page $page_rows = 3; //tells the page number of our last page $last = ceil($rows/$page_rows); //make sure page number isnt below 1 or more than maxpages if($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //sets the range to display in our query $max = ' LIMIT '.($pagenum-1) * $page_rows.','.$page_rows; $maxquery = $data.$max; //run query to display results *style for display* //add $max to it for limiting result $data_p = mysql_query($maxquery)or die(mysql_error()); while($info = mysql_fetch_array($data_p)) { echo '<div id="productThumb">'; echo '<h3>product id: '.$info['product_id'].'</h3>'; echo '<h2>product name: '.$info['product_name'].'</h2>'; echo '<img height="140" width="100" src="'.$info['product_img'].'"</img>'; echo '<span>Product Describtion '.$info['product_dscrb'].'</span>'; echo '</div>'; } //shows user what page they are on and the total number of pages echo "<p>--page $pagenum of $last--<p>"; //check if on page 1, if so we dont need a link to the prev page or first page so do nothing //if we arent on page 1 we generate links to the first page and to the prev pages if($pagenum == 1) { } else { echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=1'> <<-First</a>"; echo " "; $previous = $pagenum-1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$previous'> <-Previous</a>"; } //this does the same above, only checking to see if we are on the last page //and then generating the NExt and Last link if($pagenum == $last) { } else { $next = $pagenum+1; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$next'>Next-></a>"; echo " "; echo "<a href='{$_SERVER['PHP_SELF']}?page=$pagesection&pagenum=$last'>Last->></a>"; } ?> i have it writing a sql query which is dependent on the cat variable set by the link in index.php... i think something is wrong with the way im executing the query to mysql. i have some other code in there for pagination as well.... note: i was able to get all the entries out of the table, but when i try and modify the code so they sort, it breaks.
×
×
  • 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.