Jump to content

strago

Members
  • Posts

    93
  • Joined

  • Last visited

Everything posted by strago

  1. lol...yah, that was easy!!!! UPDATE phpbb_users SET user_id = (user_id + 8447001)
  2. php 5.5.42 Database name: forums Table name: phpbb_users Row name: user_id What SQL query can I run in phpMyAdmin to update the user_id in every row, adding 8447002 to each user_id?
  3. Is it possible to add this code function showBBcodes($db_pagetext) { // BBcode array $find = array( '~\[b\](.*?)\[/b\]~s', '~\[i\](.*?)\[/i\]~s', '~\[u\](.*?)\[/u\]~s', '~\[quote\](.*?)\[/quote\]~s', '~\[size=(.*?)\](.*?)\[/size\]~s', '~\[color=(.*?)\](.*?)\[/color\]~s', '~\[url\]((?:ftp|https?)://.*?)\[/url\]~s', '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s' ); // HTML tags to replace BBcode $replace = array( '<b>$1</b>', '<i>$1</i>', '<span style="text-decoration:underline;">$1</span>', '<pre>$1</'.'pre>', '<span style="font-size:$1px;">$2</span>', '<span style="color:$1;">$2</span>', '<a href="$1">$1</a>', '<img src="$1" alt="" />' ); // Replacing the BBcodes with corresponding HTML tags return preg_replace($find,$replace,$db_pagetext); } in the code below? <?php $records_per_page = 500; $query = $_GET['thread']; $q2 = str_replace('-', ' ', $query); mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("DATABASE") or die(mysql_error()); //Get the page string $page = isset($_GET['thread']) ? mysql_real_escape_string(trim($_GET['thread'])) : ''; if(!empty($page)) { //Create the BASE query $FROM = "FROM post WHERE `threadid` = '$query'"; //Create and execute query to get total count of records $query = "SELECT COUNT(*) {$FROM}"; $result = mysql_query($query) or die(mysql_error()); $total_records = mysql_result($result, 0); $total_pages = ceil($total_records / $records_per_page); //Get selected page (or set to page 1) $page = isset($_GET['page']) ? intval($_GET['page']) : 1; //Ensure page is between 1 and total pages $page = max(min($total_pages, $page), 1); //Calc limit start value $limit = ($page - 1) * $records_per_page; //Create and execute query to get current page's records $query = "SELECT threadid, title, postid, username, dateline, pagetext {$FROM} ORDER by `postid` ASC LIMIT {$limit}, {$records_per_page}"; $result = mysql_query($query) or die(mysql_error()); $grab = mysql_fetch_array($result); echo "<html><head><title>Title - $grab[title]</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> </head><body> <H1>$grab[title]</H1>"; //Determine if there were results if(!mysql_num_rows($result)) { echo "No results"; } else { //Create results output mysql_data_seek($result, 0); while ($row = mysql_fetch_assoc($result)) { $db_pagetext = $row["pagetext"]; //http://www.digitcodes.com/create-simple-php-bbcode-parser-function/ $db_pagetext = str_ireplace('[i]', '<i>', $db_pagetext); $db_pagetext = str_ireplace('[/i]', '</i>', $db_pagetext); $db_pagetext = str_ireplace('[b]', '<b>', $db_pagetext); $db_pagetext = str_ireplace('[/b]', '</b>', $db_pagetext); $db_pagetext = str_ireplace('[u]', '<u>', $db_pagetext); $db_pagetext = str_ireplace('[/u]', '</u>', $db_pagetext); $results[]="<HR>Posted by {$row['username']}<P>$db_pagetext"; } echo implode("<br>\n", $results); } } echo `Footer text goes here.` ?>
  4. Using mysqldump -u root -pXXXXXXXX db > /path/back-ups/db-$datestamp.sql Instead of showing up like... INSERT INTO `phpbb_reports_reasons` VALUES (1,'warez','The post contains links to illegal or pirated software.',1),(2,'spam','The reported post has the only purpose to advertise for a website or another product.',2),(3,'off_topic','The reported post is off topic.',3),(4,'other','The reported post does not fit into any other category, please use the further information field.',4); is there a way to change the mysqldump code to make it come out like... INSERT INTO `phpbb_reports_reasons` (`reason_id`, `reason_title`, `reason_description`, `reason_order`) VALUES(1, 'warez', 'The post contains links to illegal or pirated software.', 1); INSERT INTO `phpbb_reports_reasons` (`reason_id`, `reason_title`, `reason_description`, `reason_order`) VALUES(2, 'spam', 'The reported post has the only purpose to advertise for a website or another product.', 2); INSERT INTO `phpbb_reports_reasons` (`reason_id`, `reason_title`, `reason_description`, `reason_order`) VALUES(3, 'off_topic', 'The reported post is off topic.', 3); INSERT INTO `phpbb_reports_reasons` (`reason_id`, `reason_title`, `reason_description`, `reason_order`) VALUES(4, 'other', 'The reported post does not fit into any other category, please use the further information field.', 4); in the back-up?
  5. Original code. $row = mysql_fetch_assoc ($result); echo "<TABLE border=1>\n"; echo "<TR>\n"; foreach ($row as $heading=>$column) { echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>$heading</a></b></TD>"; } echo "</TR>\n"; How do I make the code below show the column names with a space between the words? $row = mysql_fetch_assoc ($result); echo "<TABLE border=1>\n"; echo "<TR>\n"; foreach ($row as $heading=>$column) if($column == 'ColumnOne') { echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>Column One</a></b></TD>"; } if($column == 'AnotherColumn') { echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>Another Column</a></b></TD>"; } else { echo "<TD><b><a href={$_SERVER['PHP_SELF']}?order=$heading>$heading</a></b></TD>"; } echo "</TR>\n";
  6. That's exactly what I'm trying to do. You're looking at a php n00bie!! Am I even geting close?? <?php require 'config.php'; mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('Cannot select database'); // process any search term $search = ''; // default to an empty string if(isset($_GET['search'])){ $search = trim($_GET['search']); $search = preg_replace('/\s+/', ' ', $search); // replace multiple white-space with one space } // produce the where condition here... // ... your code that you need to figure out for multiple keywords goes here (this is the only place you need to have any keyword logic) //create an array to eliminate errors checking array $search_exploded = array(); //create a new array exploding the spaces of multiple search terms $search_exploded = explode(" ", $search); //if is multiple search terms if (count($search_exploded > 0)) { //loop through array foreach ($search_exploded as $search_term) { //only with certain amount of characters if (strlen($search_term) >= $search_term_length) { //create new array and lower all the words $search_terms[] = strtolower($search_term); } } } else { //if is a single search term $search_terms = strtolower($search); } $start_from = ($page-1) * $rows_per_page; // fake a where_condition for testing - i.e. works when one keyword is entered if($search != '') $construct_query = array(); if ($search != '' && !is_array($search)) { { $where_condition = "Title LIKE '%" . $search . "%'". ""; } if (is_array($search) && count($search) > 0) { $where_condition[] = "Title LIKE '%" . $search['0'] . "%'"; } // get and calculate the total number of pages $query = "SELECT COUNT(*) FROM $table_name WHERE $where_condition"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / $rows_per_page); // get and limit the requested page number if (isset($_GET["page"])){ $page = (int)$_GET["page"]; } else { $page=1; // not set, default to 1 } if($page < 1){ $page = 1; } if($total_pages > 0 && $page > $total_pages){ $page = $total_pages; } // produce and run the main query $start_from = ($page-1) * $rows_per_page; $query = "SELECT * FROM $table_name WHERE $where_condition ORDER BY Title ASC LIMIT $start_from, $rows_per_page"; $result = mysql_query($query); $count = mysql_num_rows($result); if($count <= 0){ // no matching rows echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>"; } else { // one or more matching row echo "<TABLE border=1><tr><td><b>Link</b></td><td><b>Gravity</b></td><td><b>InitialEarningsPerSale</b></td><td><b>AverageEarningsPerSale</b></td><td><b>ActivateDate</b></td></TR><TR>"; while($row = mysql_fetch_array($result)){ echo "<tr><td>".$row['Link']."</td><td>".$row['Gravity']."</td><td>".$row['InitialEarningsPerSale']."</td><td>".$row['AverageEarningsPerSale']."</td><td>".$row['ActivateDate']."</td></tr>"; } echo "</table>"; } // produce the pagination links if($total_pages > 1){ // no point if there's only one page for ($i=1; $i<=$total_pages; $i++) { echo "<a href='?search=$search&page=".$i."'>".$i."</a> "; } } } ?>
  7. This got the page numbers correct, along with an error being generated when some one tries to enter a page number higher than the number of actual pages... $search = $_GET['search']; $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); $keywords = explode(" ", $search); $keywords = array_diff($keywords, array("")); for ($i=0; $i<count($keywords); $i++) $query = "SELECT COUNT(*) FROM xxxx WHERE Title LIKE '%".$keywords[$i]."%'". " ORDER BY Title ASC"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / 20); $page = $_GET["page"]; if ($page > $total_pages) { //Spits out the $count <= 0 error. echo ""; } for ($i=1; $i<=$total_pages; $i++) { echo "<a href='search.php?search=$value&page=".$i."'>".$i."</a> "; QuickOldCar, how do I get your code working in the main script? It spits out for example SELECT * FROM xxxxx WHERE Title LIKE '%google%' AND Title LIKE '%facebook%' SELECT * FROM xxxxx WHERE Title LIKE '%google%' OR Title LIKE '%facebook%' SELECT * FROM xxxxx WHERE Title LIKE '%google%' OR Title LIKE '%facebook%' In the main search script, where it shows the keywords, it spits out You searched for facebook google facebook at search.php?search=google+facebook so I'm guessing I might be close. I'm guessing the construct_query area might need a litle changing. <?php require 'config.php'; mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('Cannot select database'); if(isset($_GET['search'])) { $search = $_GET['search']; } $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); $keywords = array(); $keywords = explode(" ", $search); $keywords = array_diff($keywords, array("")); if (is_null($search_term_length)) { $search_term_length = "3"; } if (is_null($and_or)) { $and_or = "OR"; } //if is multiple search terms if (count($keywords > 0)) { //loop through array foreach ($keywords as $search_term) { //only with certain amount of characters if (strlen($search_term) >= $search_term_length) { //create new array and lower all the words $keywords[] = strtolower($search_term); } } } else { //if is a single search term $keywords = strtolower($search); } if ($search == NULL or $search == '%') { } else { for ($i=0; $i<count($keywords); $i++) { /* construct and run our query */ if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 20; $construct_query = array(); if ($keywords != '' && !is_array($keywords)) { $construct_query = "SELECT * FROM xxxxx " . "WHERE Title LIKE '%" . $keywords . "%'"; } elseif (is_array($keywords) && count($keywords) > 0) { $construct_query[] = "SELECT * FROM xxxxx " . "WHERE Title LIKE '%" . $keywords['0'] . "%'"; unset($keywords['0']); foreach ($keywords as $additional_term) { $construct_query[] = " $and_or Title LIKE '%" . $additional_term . "%'"; } } $query_term = ''; if (count($construct_query) > 0) { $query_term = implode('', $construct_query); } //$search2 = "SELECT * FROM xxxxx " . "WHERE Title LIKE '%".$keywords[$i]."%'". " ORDER BY Title ASC LIMIT $start_from, 20"; } //Store the results in a variable or die if query fails $result = mysql_query($search2); } if ($search == NULL or $search == '%'){ } else { //Count the rows retrived $count = mysql_num_rows($result); } echo "<html><head><title>Your Title Here</title></head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\"><center><br /><form name=\"searchform\" method=\"GET\" action=\"search.php\"> <input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" /> <input type=\"submit\" value=\"Search\" /></form>"; if ($search == NULL) { } else { echo "You searched for <b><FONT COLOR=\"blue\">"; foreach($keywords as $value) { print "$value "; } echo "</font></b>"; } echo "<p> </p><br /></center>"; if (strlen($search) < 3){ echo "<center><b><FONT COLOR=\"red\">Search term must be three characters or longer.</font></b><br /></center>"; } //If no results are returned print it elseif ($count <= 0){ echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>"; //ELSE print the data in a table } else { //Table header echo "<TABLE border=1><tr><td><b>Link</b></td><td><b>Gravity</b></td><td><b>InitialEarningsPerSale</b></td><td><b>AverageEarningsPerSale</b></td><td><b>ActivateDate</b></td></TR><TR>"; while($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['Link']."</td><td>".$row['Gravity']."</td><td>".$row['InitialEarningsPerSale']."</td><td>".$row['AverageEarningsPerSale']."</td><td>".$row['ActivateDate']."</td></tr>"; $row_count++; } } echo "</table>"; $search = $_GET['search']; $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); $keywords = explode(" ", $search); $keywords = array_diff($keywords, array("")); for ($i=0; $i<count($keywords); $i++) $query = "SELECT COUNT(*) FROM xxxxx WHERE Title LIKE '%".$keywords[$i]."%'". " ORDER BY Title ASC"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / 20); $page = $_GET["page"]; if ($page > $total_pages) { echo ""; } for ($i=1; $i<=$total_pages; $i++) { echo "<a href='search.php?search=$value&page=".$i."'>".$i."</a> "; }; //require "footer.php"; ?>
  8. $query = "SELECT COUNT(*) FROM table WHERE Title LIKE '%".$keywords[$i]."%'". " ORDER BY Title ASC LIMIT $start_from, 10"; $query = "SELECT COUNT(*) FROM table WHERE Title LIKE '%".$keywords[$i]."%'"; both generate page numbers like it's counting the complete table!! Is there any way to fix #1 so if the search has multiple keywords, it just has to have one of the keywords, any keyword in the search and it shows up? I even tried the original search script before my changes, and it still did it!
  9. It does the same thing. I'm gussing {$keywords} should be something else, but what ever I put there, doesn't generate the correct number of pages.
  10. if (strlen($search) < 3){ did it. Any one know how to get this to show the correct number of pagnation links?? $query = "SELECT COUNT(*) {$keywords}"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / 20); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='search.php?search=$value&page=".$i."'>".$i."</a>"; If I have $query = "SELECT COUNT(*) FROM databasename"; the links show up as if it think's it's trying to show the whole database. $query = "SELECT COUNT(*) {$keywords}"; only generates one link, to page one that's the exact same results. Change 1 in the URL to say 2 and you then get page two.
  11. $search2 = "SELECT * FROM database " . "WHERE Title LIKE '%".$keywords[$i]."%'". " ORDER BY Title ASC LIMIT $start_from, 20";
  12. I'm trying to only let searches work if they have three or more characters. if ($search2 == NULL){ spits out an error if you search with no characters. If I replace it with if (strlen($search2) < 3){ it spits out an error if there are no characters, but still goes through if you do a search with just one or two characters. For breaking the results up in to pages when a search has over 20 results... $query = "SELECT COUNT(*) {$keywords}"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / 20); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='search.php?search=$value&page=".$i."'>".$i."</a>"; }; only generates one link, to page one that's the exact same results. Change 1 in the URL to say 2 and you then get page two. <?php require 'config.php'; mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('Cannot select database'); if(isset($_GET['search'])) { $search = $_GET['search']; } $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); $keywords = explode(" ", $search); $keywords = array_diff($keywords, array("")); if ($search == NULL or $search == '%'){ } else { for ($i=0; $i<count($keywords); $i++) { /* construct and run our query */ if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 20; $search2 = "SELECT * FROM clickbank " . "WHERE Title LIKE '%".$keywords[$i]."%'". " ORDER BY Title ASC LIMIT $start_from, 20"; } //Store the results in a variable or die if query fails $result = mysql_query($search2); } if ($search2 == NULL or $search2 == '%'){ } else { //Count the rows retrived $count = mysql_num_rows($result); } echo "<html><head><title>Your Title Here</title></head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\"><center><br /><form name=\"searchform\" method=\"GET\" action=\"search.php\"> <input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" /> <input type=\"submit\" value=\"Search\" /></form>"; if ($search2 == NULL) { } else { echo "You searched for <b><FONT COLOR=\"blue\">"; foreach($keywords as $value) { print "$value "; } echo "</font></b>"; } echo "<p> </p><br /></center>"; //if ($search2 == NULL){ if (strlen($search2) < 3){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; } elseif ($search2 == '%'){ echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>"; //If no results are returned print it } elseif ($count <= 0){ echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>"; //ELSE print the data in a table } else { //Table header echo "<TABLE border=1><tr><td><b>Link</b></td><td><b>Gravity</b></td><td><b>InitialEarningsPerSale</b></td><td><b>AverageEarningsPerSale</b></td><td><b>ActivateDate</b></td></TR><TR>"; while($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['Link']."</td><td>".$row['Gravity']."</td><td>".$row['InitialEarningsPerSale']."</td><td>".$row['AverageEarningsPerSale']."</td><td>".$row['ActivateDate']."</td></tr>"; $row_count++; } } echo "</table>"; if ($search2 == NULL or $search2 == '%') { } else { mysql_free_result($result); } $query = "SELECT COUNT(*) {$keywords}"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / 20); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='search.php?search=$value&page=".$i."'>".$i."</a>"; }; require "footer.php"; ?>
  13. NOW I understand why it made no sense. I was trying to get the order by settings the wrong way. This does it, using an if statement based on the URL... if($_GET['order'] == 'Link') { $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order ASC LIMIT $start_from, 50"; } if($_GET['order'] == 'Gravity') { $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order +0 DESC LIMIT $start_from, 50"; } if($_GET['order'] == 'ActivateDate') { $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order DESC LIMIT $start_from, 50"; } if($_GET['order'] == 'InitialEarningsPerSale') { $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order +0 DESC LIMIT $start_from, 50"; } if($_GET['order'] == 'AverageEarningsPerSale') { $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order +0 DESC LIMIT $start_from, 50"; } $result = mysql_query ($query); /* make sure data was retrieved '$' */ $numrows = mysql_num_rows($result); if ($numrows == 0) { echo "No data to display!"; exit; }
  14. $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY Links $order ASC LIMIT $start_from, ActivateDate $order DESC LIMIT $start_from, Gravity $order +0 DESC LIMIT $start_from, InitialEarningsPerSale $order +0 DESC LIMIT $start_from, AverageEarningsPerSale $order +0 DESC LIMIT $start_from, 50"; and even trying out just a simple version... $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY Gravity DESC, InitialEarningsPerSale DESC, AverageEarningsPerSale DESC, Links ASC"; spits out... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/site8/public_html/CB/search.php on line 36 $default_sort = 'Gravity'; $allowed_order = array ('Link', 'Gravity','ActivateDate', 'InitialEarningsPerSale', 'AverageEarningsPerSale'); $search = $_GET['q']; /* if order is not set, or it is not in the allowed * list, then set it to a default value. Otherwise, * set it to what was passed in. */ if (!isset ($_GET['order']) || !in_array ($_GET['order'], $allowed_order)) { $order = $default_sort; } else { $order = $_GET['order']; } /* construct and run our query */ if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 50; $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY Gravity DESC, InitialEarningsPerSale DESC, AverageEarningsPerSale DESC, Links ASC"; $result = mysql_query ($query); /* make sure data was retrieved '$' */ $numrows = mysql_num_rows($result); if ($numrows == 0) { echo "No data to display!"; exit; }
  15. How do you have all of these in the same query? Gravity, InitialEarningsPerSale, and AverageEarningsPerSale having... ORDER BY $order +0 DESC LIMIT $start_from, 50"; ActivateDate having... ORDER BY $order DESC LIMIT $start_from, 50"; Links having... ORDER BY $order ASC LIMIT $start_from, 50";
  16. How would I have one query with the ORDER BY settings based on columns?? One has +0 DESC so the numbers show up in the correct order and decending, one is just DESC, and one is just ASC. Gravity, InitialEarningsPerSale, and AverageEarningsPerSale having... $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order +0 DESC LIMIT $start_from, 50"; ActivateDate having... $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order DESC LIMIT $start_from, 50"; Links having... $query = "SELECT Link,Gravity,ActivateDate,CONCAT('$', InitialEarningsPerSale) as InitialEarningsPerSale,CONCAT('$', AverageEarningsPerSale) as AverageEarningsPerSale FROM clickbank WHERE `Title` LIKE '%{$search}%' ORDER BY $order ASC LIMIT $start_from, 50";
  17. How do you add the dollar sign to the results of a query? $query = "SELECT Table1,Table2,Table3 FROM database ORDER BY $order DESC LIMIT $start_from, 50"; shows the amount $query = "SELECT Table1,Table2,'$'Table3 FROM database ORDER BY $order DESC LIMIT $start_from, 50"; removes the amount and only shows the dollar sign. Complete script... /* construct and run our query */ if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 50; $query = "SELECT Table1,Table2,'$'Table3 FROM database ORDER BY $order DESC LIMIT $start_from, 50"; $result = mysql_query ($query); /* make sure data was retrieved */ $numrows = mysql_num_rows($result); if ($numrows == 0) { echo "No data to display!"; exit; } /* now grab the first row and start the table */ $row = mysql_fetch_assoc ($result); echo "<TABLE border=1>\n"; echo "<TR>\n"; foreach ($row as $heading=>$column) { /* check if the heading is in our allowed_order * array. If it is, hyperlink it so that we can * order by this column */ echo "<TD><b>"; if (in_array ($heading, $allowed_order)) { echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>"; } else { echo $heading; } echo "</b></TD>\n"; } echo "</TR>\n"; /* reset the $result set back to the first row and * display the data */ mysql_data_seek ($result, 0); while ($row = mysql_fetch_assoc ($result)) { echo "<TR>\n"; foreach ($row as $column) { echo "<TD>$column</TD>\n"; } echo "</TR>\n"; } echo "</TABLE>\n"; ?>
  18. I got the script geting the data. How would I add an if to it, where if it's the title, it'll show up as <A HREF="http://www.domain.com/info/**ID**.html">**Title**</a> I think the part that needs messed with is... mysql_data_seek ($result, 0); while ($row = mysql_fetch_assoc ($result)) { echo "<TR>\n"; foreach ($row as $column) { echo "<TD>$column</TD>\n"; } echo "</TR>\n"; } echo "</TABLE>\n"; The complete script... /* construct and run our query */ if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 50; $query = "SELECT Title,Id,URL,Description FROM XXXXXX ORDER BY $order ASC LIMIT $start_from, 50"; $result = mysql_query ($query); /* make sure data was retrieved */ $numrows = mysql_num_rows($result); if ($numrows == 0) { echo "No data to display!"; exit; } /* now grab the first row and start the table */ $row = mysql_fetch_assoc ($result); echo "<TABLE border=1>\n"; echo "<TR>\n"; foreach ($row as $heading=>$column) { /* check if the heading is in our allowed_order * array. If it is, hyperlink it so that we can * order by this column */ echo "<TD><b>"; if (in_array ($heading, $allowed_order)) { echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>"; } else { echo $heading; } echo "</b></TD>\n"; } echo "</TR>\n"; /* reset the $result set back to the first row and * display the data */ mysql_data_seek ($result, 0); while ($row = mysql_fetch_assoc ($result)) { echo "<TR>\n"; foreach ($row as $column) { echo "<TD>$column</TD>\n"; } echo "</TR>\n"; } echo "</TABLE>\n";
  19. I think it's the code the generates the 1, 2, 3.... links that's messed up. If I have say 50 results and have it set up to show up to 100 results per page, the 1 still shows up at the bottom of the page where it links to the results. If I have it 50 per page and have 200 results it'll show 1 2 3 4 and at 4 it hasn't gone through them all, you can replace the number up to 10 before you get to the end, generating 462 results, when there are actually just 200 results. The results are showing up two or three times!! Part probably messed up... <?php $query = "SELECT COUNT(*) FROM database"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / 50); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='sort.php?order=$order&page=".$i."'>".$i."</a> "; }; ?> The complete script... <?php /* set the allowed order by columns */ $default_sort = 'Title'; $allowed_order = array ('Title', 'Description','URL'); /* if order is not set, or it is not in the allowed * list, then set it to a default value. Otherwise, * set it to what was passed in. */ if (!isset ($_GET['order']) || !in_array ($_GET['order'], $allowed_order)) { $order = $default_sort; } else { $order = $_GET['order']; } /* connect to db */ mysql_connect ('localhost','root', 'password'); mysql_select_db ('database'); /* construct and run our query */ if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 20; $query = "SELECT * FROM database ORDER BY $order ASC LIMIT $start_from, 50"; $result = mysql_query ($query); /* make sure data was retrieved */ $numrows = mysql_num_rows($result); if ($numrows == 0) { echo "No data to display!"; exit; } /* now grab the first row and start the table */ $row = mysql_fetch_assoc ($result); echo "<TABLE border=1>\n"; echo "<TR>\n"; foreach ($row as $heading=>$column) { /* check if the heading is in our allowed_order * array. If it is, hyperlink it so that we can * order by this column */ echo "<TD><b>"; if (in_array ($heading, $allowed_order)) { echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>"; } else { echo $heading; } echo "</b></TD>\n"; } echo "</TR>\n"; /* reset the $result set back to the first row and * display the data */ mysql_data_seek ($result, 0); while ($row = mysql_fetch_assoc ($result)) { echo "<TR>\n"; foreach ($row as $column) { echo "<TD>$column</TD>\n"; } echo "</TR>\n"; } echo "</TABLE>\n"; ?> <?php $query = "SELECT COUNT(*) FROM database"; $result = mysql_query($query); $row = mysql_fetch_row($result); $total_records = $row[0]; $total_pages = ceil($total_records / 50); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='sort.php?order=$order&page=".$i."'>".$i."</a> "; }; ?> I think the part generating the pages doesn't know about the rest of the script, and probably needs to be merged in with the main script code, and geting the results to only show up once per result.
  20. How do you use a form to select where files get moved to after being uploaded, and for zip files, unzipped?? No matter what I try doing, they show up at /full_path/calendar/images/ instead of /full_path/calendar/images/FormInfo. <?php if($_FILES["zip_file"]["name"]) { $filename = $_FILES["zip_file"]["name"]; $directory = $_FILES["directory"]["name"]; //Is this even correct?? $source = $_FILES["zip_file"]["tmp_name"]; $type = $_FILES["zip_file"]["type"]; $name = explode(".", $filename); $accepted_types = array('application/zip', 'application/tiff', 'application/png', 'application/gif', 'application/jpg', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed'); foreach($accepted_types as $mime_type) { if($mime_type == $type) { $okay = true; break; } } $continue = strtolower($name[1]) == 'zip' ? true : false; if(!$continue) { $message = "The file you are trying to upload is not a correct file. Please try again."; } $target_path = "/full_path/calendar/images/".$filename; // change this to the correct site path if(move_uploaded_file($source, $target_path)) { $zip = new ZipArchive(); $x = $zip->open($target_path); if ($x === true) { $zip->extractTo("/full_path/calendar/images/"); // change this to the correct site path $zip->close(); unlink($target_path); } $message = "Your file was uploaded. If it was a Zip file, it has also been unzipped."; } else { $message = "There was a problem with the upload. Please try again."; } } ?> <title>File Uploaded</title> </head> <body> <?php if($message) echo "<p>$message</p>"; ?> <form enctype="multipart/form-data" method="post" action=""> <label>Choose an image file to upload. To upload multiple images at one time, convert them to a .zip file and upload. <P><input type="file" name="zip_file" /></label> <P> Select Directory: <select name="directory" id="directory"> <option value="DirectoryName" selected>DirectoryName</option> <P> <input type="submit" name="submit" value="Upload" /> </form> </body> </html>
  21. `counter` varchar(256) collate utf8_unicode_ci NOT NULL default '0', I just tried changing it from ORDER by `counter` DESC to ORDER by counter + 0 DESC and that made it start sorting correctly.
  22. $query = "SELECT id, title, seo, source, counter {$FROM} ORDER by `counter` DESC LIMIT {$limit}, {$records_per_page}"; spits it out like this... 2 2 14 12 1 1 How do you make it show up as 14 12 2 2 1 1
  23. Thanks. That did exactly what I was trying to do, completly remove the $db_source value if it had a : in it.
  24. $source = str_replace("", "", $db_source).')'; $source = "(" . $source; $source = str_replace('()', '', $source); What can I add to this so that if there's a : in it, it all get's competly removed. It would be in these formats... (Text 7:9) (Text 1:26-27) (Text 1:12, 25) (Text 6:5-6, 9)
  25. Thanks. I'm a total php n00bie so I was using Google and another php script to try to get it working. That's perfect. I just had to add back the $query = $_GET['q']; because the search results will actually be an index by topic, with each page based on the query in the URL.
×
×
  • 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.