-
Posts
92 -
Joined
-
Last visited
Everything posted by MsKazza
-
Oh right, so whatever is typed into the form basically just stays there? Ajax just executes the update statement and leaves the page alone. So in theory i edit a product description, click submit, it executes the update, then i see an error correct it, submit again and again it executes the update while the page stays as I typed it. **lightbulb moment** I thought it was somehow refreshing the page without reloading. In that case If i'm adding something to a mysql table via a form and have the results displayed in a separate div, how is this updated to reflect the new information, do i somehow need to make the div reload? Thanks very much for the quick response.
-
Hi, I have been reading up on ajax using jquery, and theres something I can't seem to find, i have a form that gets the field values from mysql when the page loads, what is the best way to use ajax to edit this form? Obv the ajax request will execute the mysql update statement but how do i get the edited data back into the form, ready to be worked with again. thanks, hope i made sense, just looking for a little direction. MsKazza
-
Thank you for your reply, i don't want them to be echo'd on a loop, i want to keep them in their own rows, so if there is no number 3, that row will become the text box, and a new number 3 will be chosen. I was hoping someone could please help me get this to work properly displaying the rows 1 through 6 or displaying the textbox if associated number doesn't exist. thanks
-
Hi there, I was hoping someone could provide an insight as to why this is not working, it is not listing the products in the order they should be, but it is still listing all 6, just random. any help much appreciated. I would image there is a much easier way to do this i just don't know it. <?php $result_product = mysqli_query($con,"SELECT * FROM products WHERE NOT specials='0' AND product_publish='y'"); ?> <form id="specials" name="specials" action="" method="post"> <table > <?php while($row_product1 = mysqli_fetch_assoc($result_product)){ if ($row_product1['specials'] = 1) { echo "<tr><td>"; echo $row_product1['product_code']; echo "</td><td>"; echo $row_product1['product_name']; echo "</td><td><span class=\"glyphicon glyphicon-trash\"></td></tr>"; } else { echo "<tr><td><input type=\"text\" id=\"speical1code\"></td><td>add special</td></tr>"; } }?> <?php while($row_product2 = mysqli_fetch_array($result_product)){ if ($row_product2['specials'] = 2) { echo "<tr><td>"; echo $row_product2['product_code']; echo "</td><td>"; echo $row_product2['product_name']; echo "</td><td><span class=\"glyphicon glyphicon-trash\"></td></tr>"; } else { echo "<tr><td><input type=\"text\" id=\"speical1code\"></td><td>add special</td></tr>"; } }?> <?php while($row_product3 = mysqli_fetch_array($result_product)) { if ($row_product3['specials'] = 3) { echo "<tr><td>"; echo $row_product3['product_code']; echo "</td><td>"; echo $row_product3['product_name']; echo "</td><td><span class=\"glyphicon glyphicon-trash\"></td></tr>"; } else { echo "<tr><td><input type=\"text\" id=\"speical1code\"></td><td>add special</td></tr>"; } }?> <?php while($row_product4 = mysqli_fetch_array($result_product)) { if ($row_product4['specials'] = 4) { echo "<tr><td>"; echo $row_product4['product_code']; echo "</td><td>"; echo $row_product4['product_name']; echo "</td><td><span class=\"glyphicon glyphicon-trash\"></td></tr>"; } else { echo "<tr><td><input type=\"text\" id=\"speical1code\"></td><td>add special</td></tr>"; } }?> <?php while($row_product5 = mysqli_fetch_array($result_product)) { if ($row_product5['specials'] = 5) { echo "<tr><td>"; echo $row_product5['product_code']; echo "</td><td>"; echo $row_product5['product_name']; echo "</td><td><span class=\"glyphicon glyphicon-trash\"></td></tr>"; } else { echo "<tr><td><input type=\"text\" id=\"speical1code\"></td><td>add special</td></tr>"; } }?> <?php while($row_product6 = mysqli_fetch_array($result_product)) { if ($row_product6['specials'] = "9") { echo "<tr><td>"; echo $row_product6['product_code']; echo "</td><td>"; echo $row_product6['product_name']; echo "</td><td><span class=\"glyphicon glyphicon-trash\"></td></tr>"; } else { echo "<tr><td><input type=\"text\" id=\"speical1code\"></td><td>add special</td></tr>"; } }?> </table> </form>
-
Thank you for your reply. I have figured it out it wasn't picking up the news_id properly on post. But thank you for your suggestion on the PDO i will look into it. thanks
-
Hi all, Hoping someone might have an insight as to why this isn't working for me. The post is working as everything echo's ok, and there are no error messages, however it doesn't update at all. The db connection must be working as the text boxes on forms have an echo of the current content which displays ok. $recordID = $_GET["recordID"]; $result = mysqli_query($con,"SELECT * FROM news WHERE news_id = '$recordID'"); $row = mysqli_fetch_array($result); if (isset($_POST['submit'])) { $news_id = $_POST['recordID']; $news_title = $_POST['news_title']; $news_content = $_POST['news_content']; $publish = $_POST['publish']; $facebook = $_POST['facebook']; echo $news_id; echo $news_title; echo $news_content; echo $publish; echo $facebook; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Perform queries mysqli_query($con,"UPDATE news SET news_title='$news_title', news_content='$news_content', publish='$publish', facebook='$facebook' WHERE news_id='$news_id'"); mysqli_close($con);
-
opps nevermind I managed to sort it out, error in the second query, sily me. Thanks again to all who helped me get it sorted
-
thank you for your reply, I couldn't quite figure out how to use what you had suggested, but you mentioned about the & so i've changed my links to <a href='?recordID=$recordID¤tpage=$x'> and it seems to be working ok for now. Thanks very much Just one last thing if someone wouldn't mind, since changing the query, my images etc on the grid layout aren't displaying correctly, hoping someone could suggest why. while($row1 = mysqli_fetch_assoc($result)) { $prod_name = $row1['product_name']; $slug = $row1['slug']; $image = $row1['product_image_big1']; if(strlen($prod_name)>24){ $prod_name=substr($prod_name,0,24).' ...'; } if (['$result'] > 0){ $count1++; echo "<td align='center' valign='top'>"; echo "<table align='center' bgcolor='#ffffff' width='160'><tr><td height='5' align='center'>"; echo "</td></tr><tr><td align='center'>"; echo "<a href='product.php?name=" . $slug . "' class='topbar'>"; echo "<img src='eCommerceAssets/images/products/"; echo $row1['product_image_big1']; echo "' width='150' height='200'>"; echo "</a>"; echo "</td></tr><tr><td align='center'>"; echo "<strong><a href='product.php?name=" . $slug . "' class='prod-name'>"; echo $prod_name; echo "</a></strong><br />"; echo "<a href='product.php?name=" . $slug . "' class='button'>More Info</a><br />"; echo "</td></tr></table><br /><br />"; echo "</td>"; As you can see i've tried getting row directly from database, i've tried concatenating it to the link and assigning the row['x'] to a variable. The variable prod_name shows just fine, but the others slug and image don't suggestions? thanks
-
Thank you to all who contributed a useful answer. @Jacques1 I am well aware that you don't just append an i to mysql, I didn't. I do understand the principal behind pagination but when I tried to look up an example of pagination or where i could learn it myself only these kinds of tutorials appeared. I spent hours searching Google to try help me fix the code myself before posting on here. I don't enjoy following this kind of tutorial, and I certainly don't copy and paste, I type out the examples trying to understand it line by line. I was asking for help not criticism. Now i have the pagination more or less working with my grid layout, however I still cannot figure out how to pass the recordID along in the links I tried to append them to the pagination links to no avail, so if someone could please give me a clue as to where it might go i would really appreciate it. The first page shows the correct results. I am aware of the risk of sql injection and will amend my code once i have it working. Below is the whole code as it is now. <?php $recordID = $_GET["recordID"]; // find out how many rows are in the table $query = mysqli_query($con, "SELECT COUNT(*) FROM products WHERE sub_category='$recordID'"); $r = mysqli_fetch_array($query); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 19; // 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 $query = "SELECT product_id, product_name FROM products WHERE sub_category=$recordID LIMIT $offset, $rowsperpage"; $result = mysqli_query($con, $query); // always make sure you get a valid result!!! if($result == false) { die("Query failed: ".mysqli_error().PHP_EOL.$query); } echo "<b>You are viewing page " . $currentpage . " of " . $totalpages . "</b><br />"; echo "We found " . $numrows . " products for " . $row_subcategory['subcat_name'] . "<br /><br />"; ?> <?php if ($result == NULL) { echo "There are no products to display in this category"; } else { ?> <table align="center" border=0 width="550px" cellpadding="5" cellspacing="5"><tr> <?php $count1 = 0; $max1 = 3; while($row1 = mysqli_fetch_assoc($result)) { $prod_name = $row1['product_name']; $slug = $row1['slug']; $image = $row1['product_image_big1']; if(strlen($prod_name)>24){ $prod_name=substr($prod_name,0,24).' ...'; } if (['$result'] > 0){ $count1++; echo "<td align='center' valign='top'>"; echo "<table align='center' bgcolor='#ffffff' width='160'><tr><td height='5' align='center'>"; echo "</td></tr><tr><td align='center'>"; echo "<a href='product.php?name=" . $slug . "' class='topbar'>"; echo "<img src='eCommerceAssets/images/products/" . $image . "' width='150' height='200'>"; echo "</a>"; echo "</td></tr><tr><td align='center'>"; echo "<strong><a href='product.php?name=" . $slug . "' class='prod-name'>"; echo $prod_name; echo "</a></strong><br />"; echo "<a href='product.php?name=" . $slug . "' class='button'>More Info</a><br />"; echo "</td></tr></table><br /><br />"; echo "</td>"; if($count1 >= $max1){ //reset counter $count1 = 0; //end and restart echo '</tr><tr>'; } } elseif ($result = 0) { echo 'There are no products available.'; } } ?> </tr></table> <?php } // close while loop echo "<br />"; /****** 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 "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> </span>"; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a></span> "; } // 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 "<span class='active'> <b>$x</b> </span>"; // if not current page... } else { // make it a link echo "<span class='rest'><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> </span>"; } // 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 "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a></span>"; // echo forward link for lastpage echo "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a></span>"; } // end if /****** end build pagination links ******/ // close if ?>
-
thank you for your help i think that is sorted, however now i am getting this error: Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in/home/adlantic1361/public_html/sub_category.php on line 87 You are viewing page 1 of 0 We found products for and the "viewing page 1 of * and found * products for tshirt" isn't working either. I would assume that the count isn't working properly. Also my recordID isn't being passed from page to page I was following the tutorial here : http://www.phpfreaks.com/tutorial/basic-pagination#comment-805
-
Hi, I'm hoping someone might be able to help me out with something, whilst trying to implement pagination I keep getting the following error : Catchable fatal error: Object of class mysqli could not be converted to string in I know that this is because of a mix of mysqli and mysql however I cannot figure out for the life of me where the mysql is. As far as I know the whole thing is in mysqli. Was hoping someone could help me figure out why i'm getting this error. Thanks, MsKazza $recordID = $_GET["recordID"]; $rs_result = mysqli_query($con,"SELECT COUNT(product_id) FROM products WHERE category=$recordID") or trigger_error("Query Failed! SQL: $con - Error: ".mysqli_error(), E_USER_ERROR); $row = mysqli_fetch_row($rs_result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 18; // 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; $rs_result = mysqli_query ($con, "SELECT * FROM products INNER JOIN images ON products.product_code=images.product_code WHERE sub_category=$recordID ORDER BY product_id ASC LIMIT $offset, $rowsperpage") or trigger_error("Query Failed! SQL: $con - Error: ".mysqli_error(), E_USER_ERROR); ?> <?php if ($rs_result == NULL) { echo "There are no products to display in this category"; } else { ?> <table align="center" border=0 width="550px" cellpadding="5" cellspacing="5"><tr> <?php $count1 = 0; $max1 = 3; while($row1 = mysqli_fetch_assoc($rs_result)) { $prod_name = $row1['product_name']; if(strlen($prod_name)>24){ $prod_name=substr($prod_name,0,24).' ...'; } if (['$rs_result'] > 0){ $count1++; echo '<td align="center" valign="top">'; echo '<table align="center" bgcolor="#ffffff" width="160"><tr><td height="5" align="center">'; echo '</td></tr><tr><td align="center">'; echo '<a href="product.php?name='; echo $row1['slug']; echo '" class="topbar">'; echo '<img src="eCommerceAssets/images/products/'; echo $row1['product_image_big1']; echo '" width="150" height="200">'; echo '</a>'; echo '</td></tr><tr><td align="center">'; echo '<strong><a href="product.php?name='; echo $row1['slug']; echo '" class="prod-name">'; echo $prod_name; echo '</a></strong><br />'; echo '<a href="product.php?name='; echo $row1['slug']; echo '" class="button">More Info</a><br />'; echo '</td></tr></table><br /><br />'; echo '</td>'; if($count1 >= $max1){ //reset counter $count1 = 0; //end and restart echo '</tr><tr>'; } } elseif ($rs_result = 0) { echo 'There are no products available.'; } } ?> </tr></table> <?php } // close while loop echo "<br />"; /****** build the pagination links ******/ echo "<div class='pagination'>"; // 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 "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> </span>"; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a></span> "; } // 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 "<span class='active'> <b>$x</b> </span>"; // if not current page... } else { // make it a link echo "<span class='rest'><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> </span>"; } // 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 "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a></span>"; // echo forward link for lastpage echo "<span class='rest'> <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a></span>"; } // end if echo "</div>"; /****** end build pagination links ******/ // close if ?> </div>
-
no its part of an insert statement, its not already in db, i just want the second box to somehow rearrange the 'slug' text like in the sql statement, adding the category and product name, removing spaces, etc. e.g. product name : (text box here) category : (select box here) subcategory : (select box here) slug : ([get subcategory from user selection]\[altered product name from user selection]) - user can't edit this box its automatically generated. before it inserts into db
-
this is what my links look like to make them userfriendly : domain.ie/product?name=t-shirts/valueweight-t the 'slug' (not sure where that name came from, its just what i know it as) is the part after name= , makes the search engines like the product names more. Usually I run the following sql query on the database to create these 'slugs' as don't want user to make them. UPDATE products INNER JOIN sub_categories ON sub_categories.id = products.sub_category SET slug = replace(trim(lower(concat(sub_categories.subcat_name,'/',products.product_name))), ' ', '-'); UPDATE products SET slug = replace(slug, '&', '-'); UPDATE products SET slug = replace(slug, '---', '-'); UPDATE products SET slug = replace(slug, ''', ''); as explained (hopefully clearly) in above post I want to try find some way to do this in php as the user enters the product information. thanks.
-
Thank you both for your replies. ginerjm - I did put my code in the attached file. Is that not why there is the option to attach a file? fastsol - Thank you so much that was great, worked a charm, now all i have to do is try make it drag and drop file upload MsKazza
-
Hi, I've created a page that adds a product to our database, one of the fields is a 'slug' which i usually create by running a mysql snippet once the product has been added (please see attached file). I was hoping if someone might be able to tell me if there is a way to do the same thing but in php when the user has entered the product name then tabs or clicks into slug the script automatically populates the field based on the product name entered and the rules as per the sql file. Hope i've explained clearly. thanks, MsKazza create slug.txt
-
Hi, I have the attached page that uploads files to the server and then emails the intended recipient, however I can't figure out how to include the link to the uploaded files. Everything else works just fine, so any help on this would be much appreciated. thanks, MsKazza P.s. if anyone could point me in the direction of how to make my upload section like the attach files portion of these forum posts would love to upgrade mine. thanks. index.php
-
Can anyone pls offer some suggestions???
-
I´m running it on my local machine whilst it´s in development using Xampp, i´m not sure how to turn on all error reporting. At the moment i have the code as such: <td><? if ($vTakeout=='y') {?> <img src="takeoutyes.jpg"> <? } elseif ($vTakeout=='n') { ?> <img src="takeoutno.jpg"> <? } ?> </td> but all that happens is i get a white space on the page, i have it in text format below, so it´s picking up the db okay. I´m using Dreamweaver and Xampp
-
I am creating a site for a restaurant directory, on the listing form users can select from different options, e.g. takeout, parking, tv, disabled, etc via checkboxes. How can i make it on the listings page so that if the mysql field = y it displays the appropriate image rather than text? e.g. if takeout=y then display takeout.gif if takeout=n then no image to display. I want all the images to appear in a line along the end of the listing so site visitors can see the features offered by the restaurants. if field = no, i don´t want it to display an image at all, how can i do that without leaving a big space. In other words i only want it to display pics for fields that have a Y in them i have just tried it using the following: <td><? if (vTakeout='y')?> <img src="takeoutyes.jpg"> <? else if (vTakeout='n')?> <img src="takeoutno.jpg"> <? end if?> </td> and get this error: Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\Diningout\site... on line 223 i have also tried the following, but nothing happens. <td><? if (vTakeout=='y') {?> <img src="takeoutyes.jpg"> <? } elseif (vTakeout=='n') { ?> <img src="takeoutno.jpg"> <? } ?> </td> i know that the page is reading the fields correctly as i´ve put in the field in text format to show y or n thanks in advance for your help MsKazza