Jump to content

orgzchaos

Members
  • Posts

    15
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

orgzchaos's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. This code takes and deletes exact duplicates from the database. <?php $con = mysql_connect("myhost","myacc",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $runme="DELETE bad_rows.* from wp_posts as bad_rows inner join ( select post_title, MIN(id) as min_id from wp_posts group by post_title having count(*) > 1 ) as good_rows on good_rows.post_title = bad_rows.post_title and good_rows.min_id <> bad_rows.id"; $result=mysql_query($runme); mysql_close($con); ?> Now instead I am looking to use similar_text functionality to check for duplicates in the database and delete every match besides the one with the lowest ID ( the original ). What would be the simplest and resource efficient way to do that? Samples would help a lot. Thanks
  2. Throwing this error: Warning: illegal string offset $row is a string, so I was wondering how $row['xxxxx'] would work? Thanks
  3. All recommendations followed and below is what I got. <?php include "base.php"; if (!isset($table_content)) { $table_content=""; } if (!isset($pagination_options)) { $pagination_options=""; } if (!isset($pagination_links)) { $pagination_links=""; } if (!isset($total_results)) { $total_results=""; } $result = mysql_query("SELECT COUNT(*) FROM persons"); $rows = mysql_fetch_row($result); $numrows = $rows[0]; if (isset($_POST['resultsperpage'])) { $_SESSION['resultsperpage'] = $_POST['resultsperpage']; } else if (!isset($_SESSION['resultsperpage'])) { $_SESSION['resultsperpage'] = 10; } $totalpages = ceil($numrows / $_SESSION['resultsperpage']); if (isset($_GET['id']) && is_numeric($_GET['id'])) { // get id value $id = $_GET['id']; // delete the entry $result = mysql_query("DELETE FROM persons WHERE id=$id") or die(mysql_error()); } //check if multiple entries are selected if (isset($_POST['usercheckbox'])) { if (is_array($_POST['usercheckbox'])){ $id=$_POST['usercheckbox']; $result = mysql_query("DELETE FROM persons WHERE id IN (" . implode(', ', $id) . ")") or die(mysql_error()); } } if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $_SESSION['resultsperpage']; $limit = $_SESSION['resultsperpage']; $result = mysql_query("SELECT id,username,name,email,level FROM persons LIMIT $offset,$limit"); while ($list = mysql_fetch_assoc($result)) { $id = $list['id']; $username = $list['username']; $name = $list['name']; $email = $list['email']; $level = $list['level']; $table_content .= "<tr><td><input name='usercheckbox[]' type='checkbox' value='".$id."' title='Select/Deselect User'></td> <td>".$username."</td> <td>".$name."</td> <td>".$email."</td> <td>".$level."</td> <td><a href='view.php?id=".$id."'><img src='images/view.png' title='View details' class='menuentry'><a href='edit.php?id=".$id."'><img src='images/edit.png' title='Edit' class='menuentry'><a href='delete.php?id=".$id."'><img src='images/remove.png' title='Delete' class='menuentry'></tr>"; } for ($i = 10; $i <= 90; $i += 10) { if ( $_SESSION['resultsperpage'] == $i ) { $pagination_options .= "<option value='".$i."' selected='yes'>".$i."</option>"; } else { $pagination_options .= "<option value='".$i."'>".$i."</option>"; } } if ( $_SESSION['resultsperpage'] == $total_results ) { $pagination_options .= "<option value='100' selected='yes'>All</option>"; } else { $pagination_options .= "<option value='100'>All</option>"; } if ( $totalpages == 0 ) { $pagination_links .= "No entries"; } else { if ( $currentpage > 1 ) { $tmppage=$currentpage-1; } else { $tmppage=1; }; $pagination_links .= "<a href='usersopt.php?currentpage=".$tmppage."'><img src='images/goback.png' class='footerimgB' title='Previous Page'></a>"; } for ($i = 1; $i <= $totalpages; $i++) { if ( $i == $currentpage ) { $pagination_links .= "<b>&nbsp<a href='usersopt.php?currentpage=$i'>$i</a></b>"; } else { $pagination_links .= "&nbsp<a href='usersopt.php?currentpage=$i'>$i</a>"; } } if ( $currentpage < $totalpages ) { $tmppage=$currentpage+1; } else { $tmppage=$currentpage; }; $pagination_links .= "&nbsp&nbsp<a href='usersopt.php?currentpage=".$tmppage."'><img src='images/goforward.png' class='footerimgB' title='Next Page'></a></span></div>"; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>User Management</title> <script language='Javascript'> checked = false; function checkedAll () { if (checked == false){checked = true}else{checked = false} for (var i = 0; i < document.getElementById('userlisting').elements.length; i++) { document.getElementById('userlisting').elements[i].checked = checked; } } </script> <style type="text/css"> img.footerimgA {vertical-align:-23%; margin-right: 5px;border: none!important;} img.footerimgB {vertical-align:-26%; margin-right: 5px;border: none!important;} img.footerimgC {vertical-align: -30%; margin-right: 5px;border: none!important;} img.menuentry { border: none!important; margin-left:5px; margin-right:5px; } .breaklarge{ margin-left: 320px; } .breaksmall{ margin-left: 30px; } .pagination{ margin:2px; width:100px; } a:link {color:#000000;} a:visited {color:#000000;} a:hover {color:#000000;} a:active {color:#000000;} a:link {text-decoration:none;} a:visited {text-decoration:none;} a:hover {text-decoration:none;} a:active {text-decoration:none;} #mainbox { margin-left:200px; margin-right:200px; margin-top:50px; } #footer { font-family:"Arial","Trebuchet MS", Arial, Helvetica, sans-serif; font-size:0.7em; width:100%; margin-top:20px; } #customers { font-family:"Arial","Trebuchet MS", Arial, Helvetica, sans-serif; width:100%; border-collapse:collapse; } #customers td, #customers th { font-size:0.8em; border:1px solid #006699; padding:3px 7px 2px 7px; } #customers tr td:first-child, #customers tr th:first-child {background-color:#FFFFFF; width:1px; text-align:center;} #customers tr td:last-child, #customers tr th:last-child {width:78px;} #customers tr td:nth-child(5), #customers tr th:nth-child(5) {width:10px; text-align:center;} #customers th { font-size:0.8em; text-align:left; padding-top:2px; padding-bottom:1px; background-color:#006699; color:#ffffff; } #customers td { padding-top:1.2px; padding-bottom:0.7px; font-size:0.75em; color:#000000; background-color:#FFFFFF; } #customers tr.alt td { color:#000000; background-color:#EAF2D3; } </style> </head> <body> <div id="mainbox"> <form id="userlisting" action="usersopt.php" method="post"> <table id="customers"> <tr> <th><input name="checkall" type="checkbox" onclick="checkedAll();" title="Select/Deselect All"></th> <th>Username</th> <th>Name</th> <th>Email Address</th> <th>Level</th> <th>Options</th> </tr> <?php echo $table_content; ?> </table></form><form id="resultsperpage" action="usersopt.php" method="post"><div id="footer"> <div style="float: left">Results per page: <select style="font-size:10px;" name="resultsperpage" onchange="this.form.submit()"> <?php echo $pagination_options; ?> </select></div></form><div style="float: right";><a href="search.php" title="Search"><img src="images/search.png" class="footerimgC">Search</a><span class="breaksmall"> </span><a href="newuser.php" title="Add new user"><img src="images/adduser.png" class="footerimgA">Add New</a><span class="breaksmall"> </span><a href="#" title="Delete selected users" onclick="userlisting.submit()"><img src="images/deletefooter.png" class="footerimgA">Delete Selected</a><span class="breaksmall"></span><span class="pagination"> <?php echo $pagination_links; ?> </div> </div> </body> </html> I am happy how PHP tags are reduced to just three but still the long concatenated and initial declarations ( the ones at the top ) didn't made things looks perfect thou I have explored the options and there seems little that can be done about it without getting more PHP tags in the code, unless off course there is a work around that I am not aware of. Anyways, please let me know if there is something else that I should be looking out for. Thanks
  4. I have adjusted the code reading the tips above besides getting rid of the PHP echos. If I invert the process i.e. use <?php ?> tags instead of the HTML echos then there will be way too many php tags in the code. Any comments on that?
  5. Noted the earlier comment and adjusting my codes. Secondly, on the later half you are referring to something like this?
  6. Please find below a part of code that I am working with. Please suggest some improvements as to make this code more presentable professionally. <?php include "base.php"; echo" <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> <html> <head> <title>User Management</title> <script language='Javascript'> checked = false; function checkedAll () { if (checked == false){checked = true}else{checked = false} for (var i = 0; i < document.getElementById('userlisting').elements.length; i++) { document.getElementById('userlisting').elements[i].checked = checked; } } </script> <style type=\"text/css\"> img.footerimgA {vertical-align:-23%; margin-right: 5px;border: none!important;} img.footerimgB {vertical-align:-26%; margin-right: 5px;border: none!important;} img.footerimgC {vertical-align: -30%; margin-right: 5px;border: none!important;} .breaklarge{ margin-left: 320px; } .breaksmall{ margin-left: 30px; } .pagination{ margin:2px; width:100px; } a:link {color:#000000;} a:visited {color:#000000;} a:hover {color:#000000;} a:active {color:#000000;} a:link {text-decoration:none;} a:visited {text-decoration:none;} a:hover {text-decoration:none;} a:active {text-decoration:none;} #mainbox { margin-left:200px; margin-right:200px; } #footer { font-family:\"Arial\",\"Trebuchet MS\", Arial, Helvetica, sans-serif; font-size:0.7em; width:100%; margin-top:20px; } #customers { font-family:\"Arial\",\"Trebuchet MS\", Arial, Helvetica, sans-serif; width:100%; border-collapse:collapse; } #customers td, #customers th { font-size:0.8em; border:1px solid #006699; padding:3px 7px 2px 7px; } #customers tr td:first-child, #customers tr th:first-child {background-color:#FFFFFF; width:1px; text-align:center;} #customers tr td:last-child, #customers tr th:last-child {width:78px;} #customers tr td:nth-child(5), #customers tr th:nth-child(5) {width:10px; text-align:center;} #customers th { font-size:0.8em; text-align:left; padding-top:2px; padding-bottom:1px; background-color:#006699; color:#ffffff; } #customers td { padding-top:1.2px; padding-bottom:0.7px; font-size:0.75em; color:#000000; background-color:#FFFFFF; } #customers tr.alt td { color:#000000; background-color:#EAF2D3; } #customers imgspc { margin-left:5px; margin-right:5px; } </style> </head> <body> <div id=\"mainbox\"> <form id=\"userlisting\" action=\"users.php\" method=\"post\"> <table id=\"customers\"> <tr> <th><input name=\"checkall\" type=\"checkbox\" onclick=\"checkedAll();\" title=\"Select/Deselect All\"></th> <th>Username</th> <th>Name</th> <th>Email Address</th> <th>Level</th> <th>Options</th> </tr>"; if (isset($_POST['resultsperpage'])) { $_SESSION['resultsperpage'] = $_POST['resultsperpage']; } if (isset($_GET['id']) && is_numeric($_GET['id'])) { // get id value $id = $_GET['id']; // delete the entry $result = mysql_query("DELETE FROM persons WHERE id=$id") or die(mysql_error()); } //check if multiple entries are selected if (isset($_POST['usercheckbox'])) { if (is_array($_POST['usercheckbox'])){ $id=$_POST['usercheckbox']; $result = mysql_query("DELETE FROM persons WHERE id IN (" . implode(', ', $id) . ")") or die(mysql_error()); } } $result = mysql_query("SELECT * FROM persons ORDER BY id DESC"); $total_results = mysql_num_rows($result); $total_pages = ceil($total_results / $_SESSION['resultsperpage']); if ($_SESSION['resultsperpage'] == 100) { $_SESSION['resultsperpage'] = $total_results; } if (isset($_GET['page']) && is_numeric($_GET['page'])) { $show_page = $_GET['page']; // make sure the $show_page value is valid if ($show_page > 0 && $show_page <= $total_pages) { $start = ($show_page -1) * $_SESSION['resultsperpage']; $end = $start + $_SESSION['resultsperpage']; } else { // error - show first set of results $start = 0; $end = $_SESSION['resultsperpage']; } } else { // if page isn't set, show first set of results $show_page = 1; $start = 0; $end = $_SESSION['resultsperpage']; } echo "</p>"; for ($i = $start; $i < $end; $i++) { // make sure that PHP doesn't try to show results that don't exist if ($i == $total_results) { break; } echo" <tr><td><input name=\"usercheckbox[]\" type=\"checkbox\" value=\"".mysql_result($result, $i, 'id')."\" title=\"Select/Deselect User\"></td> <td>".mysql_result($result, $i, 'username')."</td> <td>".mysql_result($result, $i, 'name')."</td> <td>".mysql_result($result, $i, 'email')."</td> <td>".mysql_result($result, $i, 'level')."</td> <td><imgspc><a href=\"view.php?id=".mysql_result($result, $i, 'id')."\"><img src=\"images/view.png\" title=\"View\"></imgspc><imgspc><a href=\"edit.php?id=".mysql_result($result, $i, 'id')."\"><img src=\"images/edit.png\" title=\"Edit\"></imgspc><imgspc><a href=\"delete.php?id=".mysql_result($result, $i, 'id')."\"><img src=\"images/remove.png\" title=\"Delete\"></imgspc></tr>"; } echo"</table></form><form id=\"resultsperpage\" action=\"users.php\" method=\"post\"><div id=\"footer\"> <div style=\"float: left\">Results per page: <select style=\"font-size:10px;\" name=\"resultsperpage\" onchange=\"this.form.submit()\">"; for ($i = 10; $i <= 90; $i += 10) { if ( $_SESSION['resultsperpage'] == $i ) { echo "<option value=\"".$i."\" selected=\"yes\">".$i."</option>"; } else { echo "<option value=\"".$i."\">".$i."</option>"; } } if ( $_SESSION['resultsperpage'] == $total_results ) { echo "<option value=\"100\" selected=\"yes\">All</option>"; } else { echo "<option value=\"100\">All</option>"; } echo "</select></div></form><div style=\"float: right\";><a href=\"search.php\" title=\"Search\"><img src=\"images/search.png\" class=\"footerimgC\">Search</a><span class=\"breaksmall\"> </span><a href=\"newuser.php\" title=\"Add New User\"><img src=\"images/adduser.png\" class=\"footerimgA\">Add New</a><span class=\"breaksmall\"> </span><a href=\"#\" title=\"Delete Selected Users\" onclick=\"userlisting.submit()\"><img src=\"images/deletefooter.png\" class=\"footerimgA\">Delete Selected</a><span class=\"breaksmall\"></span><span class=\"pagination\">"; if ( $total_pages == 0 ) { echo "No entries"; } else { if ( $show_page > 1 ) { $tmppage=$show_page-1; } else { $tmppage=1; }; echo "<a href='users.php?page=".$tmppage."'><img src='images/goback.png' class='footerimgB' title='Previous Page'></a>"; } for ($i = 1; $i <= $total_pages; $i++) { if ( $i == $show_page ) { echo"<b>&nbsp<a href='users.php?page=$i'>$i</a></b>"; } else { echo"&nbsp<a href='users.php?page=$i'>$i</a>"; } } if ( $show_page < $total_pages ) { $tmppage=$show_page+1; } else { $tmppage=$show_page; }; echo "&nbsp&nbsp<a href='users.php?page=".$tmppage."'><img src='images/goforward.png' class='footerimgB' title='Next Page'></a></span></div> </div> </div> </body> </html>"; ?>
  7. Code I have shown is just a test case for the actual scenario and the onchange function is a necessary feature for that.
  8. Worked. Is there any way to differentiate between the two submits on the server side? i.e. the receiving ( or action ) php script knows how the form was submitted i.e. either through the onchange or onclick? I know it is unlikely but still it may be useful if there was some way.
  9. I am using the same function for the onChange condition of the drop down menu and it is working fine.
  10. That is not the problem, I just made a mistake while making a test case for the forums. Code on the actual file is fine and still not working. I just tried the following code and no results: <?php if (isset($_POST['checking'])) { echo $_POST['checking']; } if (isset($_POST['test'])) { echo $_POST['test']; } ?> <form id="testform2" action="testform.php" method="post"> <select name="checking" onchange="this.form.submit()"><option value="5">5</option><option value="6">6</option></select> <input type="text" name="test" id="test"> <a href="#" onclick="this.form.submit()">submit it!</a> </form>
  11. <?php if (isset($_POST['checking'])) { echo $_POST['checking']; } if (isset($_POST['test'])) { echo $_POST['test']; } ?> <form id="testform2" action="testform.php" method="post"> <select name="checking" onchange="this.form.submit()"><option value="5">5</option><option value="6">6</option></select> <input type="text" name"test" id="test"> <a href="#" onclick="this.form.submit()">submit it!</a> </form> It works when I try to submit by selecting a new value from the dropdown box but when I try to click the link it won't display the text field value. That is a test case for a problem I m having in one of my codes.
  12. Tinybox helps place contents in a simple pop up, however the problem i m having is that whenever i try to post a form from the pop up window, it simply opens up the action file within the parent window of the pop up. I found a solution to this problem but i m not understanding what it means. Can someone explain it? Here is the solution: http://www.scriptiny.com/qa/1624/how-do-you-post-a-form Need some explaination.
  13. Okay, I was looking around the sandbox seeing a couple of sample codes but they all seem too confusing as that is the first time I am doing that. I just want a simple payments check which verifies the transaction amount and the receiver's id is correct and nothing else. Which code should I go for?
  14. Hi I will be making a php code which will verify if the user have successfully made the relevant payments. I have never worked on such scripts and this would be my first time. I was looking around and got a rough idea that payment processors do provide some kind of demos to test script functionality without actually making transactions. I was wondering if I can find some articles about PayPal and 2CheckOut payment processors and how to go around them. I believe 2checkout provide demos for testing purposes, does paypal? I only have a 2checkout account as I am from a non supported paypal country, but guess I can just make an account for testing purposes but offcourse no transactions will be there!
×
×
  • 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.