Jump to content

therealwesfoster

Members
  • Posts

    345
  • Joined

  • Last visited

Posts posted by therealwesfoster

  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. 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

  3. select q.*, a.* from questions as q left join answers as a on (a.answer_questionID = q.question_id)

     

    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 :)

  4. 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!

  5. 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?

  6. 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!

  7. here's what'd i do though.

     

    1) explode() the query string into individual words.

    2) remove common words like ("the," "what," "when," "is," "a," etc...) from your array using preg_match or eregi

    3) build a query that will check through your table for questions that contain each word: LIKE '% $word %'

    4) ta-da - show the results to the user.

     

    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

  8. 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?

  9. 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

  10. Lets say I want a series of number on a webpage that will update LIVE without refreshing the page? I would need ajax. Now what would be the most server friendly way to get variables from the DB every 5 seconds? Any tips, documents, ideas you can share?

     

    This will involve php, so this may be the right forum ;)

     

    Wes

  11. Or you could do this:

     

    RewriteCond %{REQUEST_FILENAME} !-f

     

    The above rewritecondition basically checks to see whether the url being requested is a physical file or not (style.css). If it is a physical file, it will not apply the rule. If not, it will.

     

    Worked like a charm! Thanks to both of you

  12. The final thing that worked was this:

     

    // First check if the name exists
    $sql ="SELECT * FROM `restaurants` WHERE `name`='{$mysql_name}' AND `address` ='{$mysql_address}'";
    $result = mysql_query($sql) or die(mysql_error());
    
    if (mysql_num_rows($result) > 0){
      
       $row = mysql_fetch_array($result);
       $ID = $row['ID'];
       
        // This means the name exists.. UPDATE inspections table
        $sql = "INSERT INTO `inspections` (ID, inDate, inType, notes, critical, cviolations, noncritical)  VALUES (";
        $sql .= "'$ID', '$mysql_inDate', '$mysql_inType', '$mysql_notes', '$mysql_critical', '$mysql_cviolations', '$mysql_noncritical')";
        
        
    mysql_query($sql);
        
    }
    else{
        // The name doesn't exists, add all the info
          $sql = "INSERT INTO `restaurants` (name, address)  VALUES (";
          $sql .= " '$mysql_name', '$mysql_address')";
    mysql_query($sql);
             $ID = mysql_insert_id();
             
        $sql = "INSERT INTO `inspections` (ID, inDate, inType, notes, critical, cviolations, noncritical)  VALUES (";
        $sql .= " '$ID', '$mysql_inDate', '$mysql_inType', '$mysql_notes', '$mysql_critical', '$mysql_cviolations', '$mysql_noncritical')";
    mysql_query($sql);
    }
        
        
        

     

    Glad I could help :)

  13. if($_GET['action'] == $r){

     

    $r is an array, so $_GET['action'] would not equal that.

     

    Why not do this:

    <?php
    switch($_GET['action']){
        case 'forum': $title = 'Forum';
        break;
    
        case 'tos': $title = 'Terms of Service';
        break;
    
        default: $title = 'Home'
        break;
    }
    ?>

     

     

    OR

     

     

    <?php
    $names = array(
        'tos' => 'Terms of Service',
        'forum' => 'Forum'
    );
    if (in_array($_GET['action'],$names)){
        $title = $names[$_GET['action']];
    }
    else $title = 'Home';
    ?>

×
×
  • 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.