Jump to content

therealwesfoster

Members
  • Posts

    345
  • Joined

  • Last visited

Contact Methods

  • Website URL
    https://www.wesfed.com

Profile Information

  • Gender
    Male
  • Location
    USA

therealwesfoster's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. First, you would need to send data to your website with either AJAX or a simple form. For this example, I'm using a form: <form action="" method="post"> Select your item: <input type="radio" name="item" value="1" /> Hammer <br /> <input type="radio" name="item" value="2" /> Arm <br/> <input type="submit" value="Submit" /> </form> All I did was create the radio buttons for each of the items in your database. I used the item's ID as the radio button's value, but you can use whatever you want. Next, I've altered your PHP code to this: <?PHP $server = 'localhost'; $user = 'root'; $password = ''; $mydb = 'Tools'; $table_name = 'Inventory'; if ( $_POST['Submit'] ) { /// Check if the form was submitted $item_id = mysql_real_escape_string($_POST['item']); /// Get the item's ID from the POST (form) $SQLcmd = "select * from $table_name WHERE item_id='{$item_id}' "; /// Add the "WHERE" clause $connect = mysql_connect($server, $user, $password); if (!$connect) { die ("Cannot connect to the $server using $user"); } else { mysql_select_db($mydb, $connect); $result = mysql_query($SQLcmd, $connect) or die(mysql_error()); print '<table border = 1>'; print '<tr><td>Item Name</td><td>Number Sold</td><td>Profit</td></tr>'; while($row = mysql_fetch_array($result)){ print '<tr>'; print "<td> {$row['Name']} </td>"; print "<td> {$row['Sold']} </td>"; $Profits = ($row['Price'] - $row['Cost']) * $row['Sold'] ; print "<td> $Profits </td>"; print '</tr>'; } print '</table>'; } mysql_close($connect); } /// END POST "IF" ?> I added comments to the lines that I altered. Simply put, I: 1. Check if a POST was sent (from the form) 2. Grabbed the $_POST['item'] value (which is the item's id) and filtered it using mysql_real_escape_string() 3. Altered your MySQL query to only grab records where the item_id is equal to what was sent in the form. You might need to change the name of your column name in the WHERE clause, but overall, that's how you get what you want. I hope I understood you correctly Wes
  2. Please change my username: FROM: Wesf90 TO: therealwesfoster Thanks!
  3. I removed the RewriteBase and added the path (/) in front of the rewrite's url, but got the same results. So that rules out a rewritebase problem I also turned on "Options +followsymlinks", but still got the same results as before. Thanks for the reply. Any other ideas? FOR CLARIFICATION: 1. DOESN'T WORK RewriteRule ^([a-z0-9\-]+)\/directory\/?$ view-directory/?directory=$1 [L,NC] 2. DOES WORK RewriteRule ^([a-z0-9\-]+)\/directory\/?$ http://www.site-name.com/view-directory/?directory=$1 [L,NC] Since #2 works, we know that the WP rewrites DO WORK. The problem lies between #1 and the WP rewrites. Not sure where. When I use #1 and it leads me to WP's 404 page. On the 404 page I print_r() the _GET variables and it was empty, so there are no _GET variables being passed which is definitely causing the problem. I tried adding the "QSA" flag to the end of #1, as well as removing the "L" flag, but neither worked. Wes
  4. This is my current account. I'm only responding so I can receive notifications
  5. Thanks! I have tried a join and then print_r() the results, but it looks like it's only grabbing the question row and 1 answer row. I need it to return 1 questions row and (possibly) 5 answer rows all in the same array. Is there something I'm missing? Thanks again for all of the responses
  6. Here's what I'm needing to do. I have 2 tables: "questions" and "answers". Each question can have a variable amount of answers to choose from, so they are in separate tables ("answers" connects to "questions" via answer_questionID). I'm wanting to list each question with their answers below. Below is the current code: $sql = mysql_query("SELECT * FROM questions"); while ($row = mysql_fetch_array($sql)){ // Get the answers $sql2 = mysql_query("SELECT * FROM answers WHERE answer_questionID='{$row['question_id']}'"); while ($row2 = mysql_fetch_array($sql2)){ // Show the items } // Show the questions } Can I use a JOIN or SUBSELECT to put this into a single query? If not, any tips for optimization? Thanks!
  7. RewriteCond %{HTTP_HOST} ^ds-cheats\.DOMAIN\.com [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*?) ds-cheats/$1 [L] It just shows a blank page when it should be showing (like before) a wordpress blog. The code above DOES NOT WORK, but the code below does.. what's the difference? RewriteCond %{HTTP_HOST} ^cheats-for-psp\.DOMAIN\.com [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*?) cheats-for-psp/$1 [L] I'm thinking it has to do with the dash (-).. but not sure. Any ideas?
  8. In the WHERE add: AND (Users.Yahoo!='' AND Users.MSN!='') Wes
  9. Thanks bro, but is there any other method? The query is huge and is built in parts all throughout the script, so UNION (basically running another query) would be last resort for me
  10. I have a list of 15 articles. 5 of the articles are sticky (meaning they are always at the top). I'm only wanting to show 2 sticky articles (random out of the 5), and then display 8 non-sticky articles below (making a total of 10 articles on the page). Is there a way to go about doing this with just 1 sql query? For example: (NOTE: art_sticky is either 1 or 0, so ordering that column descending will always place them at the top.) SELECT * FROM articles ORDER BY art_sticky DESC LIMIT 2, art_postdate DESC LIMIT 8 See how I have two limits? Is there some way I can make that work? Thanks!
  11. That's definitely a start (and the reason I originally posted this in the php section...). But that would also bring up questions like "how bad do you hate dogs?" and "dogs or cats?". So there are still a few more functions that need to take place, and this is the tricky part
  12. Thanks for the reply LIKE would be good, but how would I implement that? Replace the spaces with %? That wouldn't work too well. What's you idea?
  13. What is an efficient way to check a database for similar entries? For example: One user posts "what is your favorite kind of dog?". So when user #2 comes along and posts "what is your most favorite breed of dog?", how can I alert user #2 of the similar entry already posted? Digg has this feature as well when digging something. What's the most efficient way of doing this?
  14. What's wrong with this code? # ADD WWW. RewriteCond %{REQUEST_URI} !^/robots\.txt$ RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L,QSA] I keep getting the "never ending loop" error
×
×
  • 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.