-
Posts
5,510 -
Joined
-
Days Won
185
Everything posted by mac_gyver
-
what have you tried? just posting your query again shows nothing. you either need to make sure you are suppling a value for every column in the table (your existing query method) or you must list the columns you are supplying values for (the suggested query method.) since we don't know what the original columns were, what column(s) you added, where in the existing column order you added it(them), or even which of the values shown are for the added column(s), we cannot help you with this straight-forward task. this is something that you need to do. something tells me that you added column(s) to the table but didn't add any corresponding values to the query. that's only about 1/10 the amount of work needed to add a field of data. btw - the link in the first post in this thread that you copy/pasted from the other forum you posted this in is broken since only the visible text was copy/pasted.
-
Sort results based on two columns in specific order
mac_gyver replied to n1concepts's topic in MySQL Help
ORDER BY lb DESC, oz DESC LIMIT 4 -
Minimum characters in search setting, and pagination.
mac_gyver replied to strago's topic in PHP Coding Help
your code is all over the place with copy/pasted logic that isn't doing anything toward your goal. i cleaned it up for you and arranged it in a logical/necessary order. forming your multi keyword search is still up to you, but you do it ONCE in the logic where indicated - <?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) // fake a where_condition for testing - i.e. works when one keyword is entered if($search != ''){ $where_condition = "title like '%$search%'"; } else { $where_condition = '1=1'; } // all the following code is basic pagination logic and it doesn't need any logic added to it to search for multiple keywords $table_name = 'your_table'; $rows_per_page = 20; // 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> "; } } ?> -
Minimum characters in search setting, and pagination.
mac_gyver replied to strago's topic in PHP Coding Help
you were explicitly told that you need to build a correctly formatted WHERE condition in a variable so that you can use it in both queries (you could actually use a portion of quickoldcar's code to do that.) both queries must match the same rows for this to work. until you can produce the correct queries from your search input value, you won't be able to get your code to work. programming involves breaking down a task into the steps needed to complete that task. just work on producing the correct WHERE condition in a variable and you must do this in your code before you make or run either one of the queries. -
when you don't list the column names in the INSERT query, you must supply a value for every column in the table and they must be in the same order that the columns are defined in the table. it is always best to list the column names - INSERT INTO your_table (list of columns) VALUES (list of values) you only need to list the column names you are inserting values for (non-listed columns get their default values/auto increment value) and only the order of the listed columns and listed data must match each other (you don't need to know what the actual order is in the table definition.) for a complex query (with more than a few columns/values) it is easier to see what the query is by using the sprintf() to build the query in a php variable - $query = sprintf("INSERT INTO your_table (col1,col2,col3,...) VALUES ('%s',%d,'%s', ...)", $some_string_value, $some_integer_value, $someother_string_value); you can then echo the $query variable to see exactly what the query statement is.
-
it causes the username column to be treated as a number and any username that doesn't start with a numerical character will be a zero value and will be matched.
-
by subtracting a zero, the value is converted to a number.
-
by default, the mysql trim() function only removes spaces. you would need to supply the optional remstr parameter to get it to trim anything else.
-
your SELECT query for building the form is not using the same database as your query in the form processing code.
-
when you were importing the data, did you trim the values, because the last field in each line probably has a new-line character on it.
-
How to increase a variable name by 1 on each loop?
mac_gyver replied to tech0925's topic in PHP Coding Help
should produce your existing output (you had an extra , at the end of your existing output that was not valid) - addresses = [ <?php echo '"'; echo implode('","',$addressList); echo '"'; ?> ]; -
i'll bet if you show where this data is actually coming from (query/xml...) and what your code is now, someone could show you a solution that would work for the actual data.
-
you should actually be using a virtual host setup on your localhost system so that there isn't any difference in the path (you can find how to do this common task by using google.)
-
How to increase a variable name by 1 on each loop?
mac_gyver replied to tech0925's topic in PHP Coding Help
the direct answer to your question is that you DON'T use an incrementing series of variable names. you use an array where the index is what increments. -
so, then my question becomes - how do you know what group the current visitor is in? you would need to use that information in the query, wouldn't you? your query contains NOTHING that ties it to the current visitor, therefore it cannot work and needs to contain something that contains the group membership of the current visitor.
-
Minimum characters in search setting, and pagination.
mac_gyver replied to strago's topic in PHP Coding Help
slightly off topic, but you need to limit the $page value so that it is between 1 and $total_pages (inclusive) so that someone cannot produce query errors by feeding in a zero or a negative number or feeding in a value greater than the number of pages and wasting time running a query that won't return any rows. the code to produce $total_pages needs to come before the code producing $page and then you need to add a little logic to limit the value in $page. -
you need to use htmlentities() on any "content" that you output that may contain characters that have meaning in the html/javascript context they are being output in.
-
did you BOTHER to try it on your localhost server?
-
$_SERVER['DOCUMENT_ROOT'] is the file system (disk) path to your document root folder. it is NOT used in html links/href statements on a web page. you must use a URL in links/href statements. you can use a domain relative URL - href="/css/style.css" (the leading slash refers to the root of the domain of the current page.) or you can use an absolute URL - href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/css/style.css"
-
Minimum characters in search setting, and pagination.
mac_gyver replied to strago's topic in PHP Coding Help
you need to build the sql WHERE whatever conditions you have in a php variable so that you can use that WHERE condition in both queries. right now $keywords is an array, it's not a complete and valid sql conditional statement. if you want to find row(s) with ANY of the keywords in the title, you need to form a query using OR logic. if you want to find row(s) with ALL the keywords in the title, you need to form a query using AND logic. for example, if you enter two keywords in the search and want to match either keyword, your queries would need to look like - SELECT COUNT(*) FROM your_table WHERE title LIKE '%keyword1%' OR title LIKE '%keyword2%' SELECT * FROM your_table WHERE title LIKE '%keyword1%' OR title LIKE '%keyword2%' ORDER BY title ASC LIMIT $start_from, $rows_per_page correctly building the WHERE condition (in bold) is what your immediate task should be. -
how do you know who the current visitor is in your code? you would need to use that information in the query, wouldn't you?
-
that datepicker always required an id=' ... ' to work.
-
you have too much code, to write, test, reenter, change, add items to, reuse for different things... by defining an array to hold your data, you can write/test generic code that you can reuse for different things simply by changing the data definition - <?php $options[1] = "Amulet"; $options[2] = "Head Gear"; $options[3] = "Epaulets"; $options[4] = "Shield"; $options[5] = "Chest Gear"; $options[6] = "Weapon"; $options[7] = "Ring"; $options[8] = "Boots"; $options[9] = "Gloves"; $options[10] = "Backpack"; ?> <select size="1" name="slot"> <option value="">Pick One</option> <?php $item_slot = 2; // test value foreach($options as $value=>$legend){ $selected = $item_slot == $value ? " selected='selected'": ''; echo "<option value='$value'$selected>$legend</option>\n"; } ?> </select>
-
PDO prepare: binding a parameter after SELECT
mac_gyver replied to junkomatic's topic in PHP Coding Help
you are not passing the $db instance of the pdo class into the function (like you are doing in the other functions that work), so of course there will be a not an object error. -
Which PHP functions are necessary for TYPO3 6?
mac_gyver replied to jackhard's topic in Applications
the code is using shell_exec to run the aspell spell checker and for a scheduler.