Jump to content

tomtimms

Members
  • Posts

    114
  • Joined

  • Last visited

    Never

Posts posted by tomtimms

  1. So I got it to work, however I am using a button to save and each time I save it keeps adding what I want to the end, I just need one instance of it.

     

    So code $('#billing_address_setting').attr('href', $('#billing_address_setting').attr('href') + 'site_id' + data); create http://www.mysite.com?a=100 and each time I click save it keeps adding 100, so it now looks like www.mysite.com?a=100100100 etc.  How can I make it just post 1 time?

  2. I am trying to replace a [href] attributes with php code in a jquery return.  Here is what I have so far.

     

    $('#account_setting').attr('href', '<?PHP url_for('Account/Settings/site_id/'+data) ?>';

     

    I am not sure what I have wrong, as it gives me "missing )" error code.

  3. You need to use your while loop on the entire hidden tag.  Then I assume you just lump all of them into an array and do a foreach on your Update query.

     

    <?php 
    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
        foreach($shipid AS $id){
      $updateSQL = sprintf("UPDATE ships SET HealthA=%s WHERE ShipID=%s",
                           GetSQLValueString($_POST['healtha'], "int"),
                           GetSQLValueString($_POST['shipid'], "text")); //add your ship id somewhere after this or on this line?
      }
      }
                           ?>
    
    <input name="healtha" type="hidden" id="healtha" value="<?php echo $row_Ships['HealthA'] + 1; ?>" />
    
    <?php  
    while($row = mysql_fetch_assoc($Ships))
    {
    ?>
    <input name="shipid" type="hidden" id="shipid" value="<?PHP echo $row['ShipID']; ?>" />
    <?PHP
    }
    
    
    ?>

  4. You would need to put each input element into an array.  So ..

     

    <?php include("opendatabase.php"); ?>
    
    <FORM Method = "POST" action ="insert_spreads.php">
    
    <?php
    $weekID = $_POST[Week];
    echo "<h2>Enter Spreads for Week $weekID</h2>";
    print ("<br /><br />");
    
    $result = mysql_query("
    SELECT S.game_id, TH.team_name AS HomeTeam, TA.team_name AS AwayTeam
    FROM schedule AS S 
    JOIN teams AS TH ON S.H_team = TH.team_id
    JOIN teams AS TA ON S.A_team = TA.team_id
    WHERE S.week_id = '$weekID'
    ORDER BY S.game_id;");
    
    
    $i = 0; //Counter
    
    while ($row = mysql_fetch_array($result)) {
    printf('<input type="text" size="4" name="w%dg%dAspread[' . $i . ']">', $weekID, $row['game_id']);
    printf(" %s vs. %s  ", $row['AwayTeam'], $row['HomeTeam']);
    printf('<input type="text" size="4" name="w%dg%dHspread[' . $i . ']">', $weekID, $row['game_id']);
    print("<br /><br />");
    
    $i++;
    } 
    mysql_close($con);
    ?>
    <br /><br /> 
    
    <input type="Submit" value="Submit Spreads">
    </FORM>	

     

    Then you would need to do a foreach in your form processing file.

  5. I am trying to do a like clause on a joined table, below is my query.

     

    SELECT SQL_CALC_FOUND_ROWS source, id, gross, id32 FROM ( ( SELECT a.source, a.id, a.gross, b.id32  FROM table1 a LEFT JOIN table2 b ON (a.source = b.id32 AND a.id = b.id32) WHERE a.date BETWEEN '2011-01-01' AND '2011-01-05' AND b.id32 LIKE '%201%' GROUP BY a.source,a.id )) AS tmp GROUP BY source,id
    

     

    The query doesn't give an error, however it just takes over 100 seconds to process.  Anyone know what I could do to optimize this? 

  6. Well then there are a few ways to do it.

     

    <?php
    
    function db_connect() {
       $result = new mysqli('localhost', 'root', 'password', 'books');
       if (!$result) {
    
    
    
    
    
       die(mysqli_error($result));
          return false;
       }
       $result->autocommit(TRUE);
       return $result;
    }
    function get_book_details($isbn) {
      // query database for all details for a particular book
      if ((!$isbn) || ($isbn=='')) {
    
    
    
    
    
      die(mysqli_error($isbn));
         return false;
      }
      $conn = db_connect();
      $query = "select * from books where isbn='".$isbn."'";
      $result = $conn->query($query);
      if (!$result) {
    
    
    
    
    
      die(mysqli_error($result));
         return false;
      }
      $result = $result->fetch_assoc();
      return $result;
    }
    $book = get_book_details($isbn);
    
    //Not sure if I understood this right, however lets say Title is a field in your table.  You can get an array of all the titles
    //from your query doing something like this.
    
    $book_title = array();
    while($rows = mysql_fetch_array($book)) {
        
    $book_title[] = $rows['title'];
    $book_auther[] = $rows['authoer'];
    }
    
    //you can loop out each field you want.
    foreach ($book_title AS $title){
    
    echo $title;
    
    //Or another way is to just do it inside your while loop.
    
    while($rows = mysql_fetch_array($book)) {
        
      echo $rows['title'];
    echo "<br/>";
    echo $rows['authoer'];
    }
    
    }
    
    
    
    
    
    
    ?>
    

  7. <?php
    
    function db_connect() {
       $result = new mysqli('localhost', 'root', 'password', 'books');
       if (!$result) {
    
    
    
       die(mysqli_error($result));
          return false;
       }
       $result->autocommit(TRUE);
       return $result;
    }
    function get_book_details($isbn) {
      // query database for all details for a particular book
      if ((!$isbn) || ($isbn=='')) {
    
    
    
      die(mysqli_error($isbn));
         return false;
      }
      $conn = db_connect();
      $query = "select * from books where isbn='".$isbn."'";
      $result = $conn->query($query);
      if (!$result) {
    
    
    
      die(mysqli_error($result));
         return false;
      }
      $result = $result->fetch_assoc();
      return $result;
    }
    $book = get_book_details($isbn);
    
    //Not sure if I understood this right, however lets say Title is a field in your table.  You can get an array of all the titles
    //from your query doing something like this.
    
    $book_title = array();
    while($rows = mysql_fetch_array($book)) {
        
        $book_item[] = $book['title'];
    }
    
    print_r($book_title);
    
    
    
    ?>

  8. Need to find out why your query isn't working, after this line

     

    $result=mysql_query($sql);

     

    use mysql_error(); and your query error will display on the page.  From there we can see what the problem is....

     

    Also try and use if(isset($_POST['Userid']){$myusername=$_POST['Userid'];} else {$myusername = "Not Set";} and echo out $myusername to see if you are even getting the passed variable in the URL.

  9. Ok I have 3 tables I need to union.  I am having trouble on the third table.  I am getting data within a date range and displaying them by the hour.  My third table is a calendar table that just has the time range: 00:00:00 to 23:00:00.  I want to take the data in table 1 and table 2 and sum them together using a UNION and group them together by the date(HOUR).  I then want to take my calendar table to fill in the hours that were not found in table 1 and table 2.

     

    Table 1 has the following.

    Date : ID : Money

    2010-05-01 01:00:00  | 5 | 23.23

    2010-05-01 02:00:00  | 15 | 32.34

    2010-05-01 03:00:00  | 5 | 53.55

    2010-05-01 04:00:00  | 10 | 11.45

    2010-05-01 05:00:00  | 10 | 63.74

     

    Table 2 has the following

     

    Date : ID : Money

    2010-06-01 01:00:00  | 5 | 53.23

    2010-06-01 12:00:00  | 15 | 63.34

    2010-06-01 15:00:00  | 5 | 111.55

    2010-06-01 16:00:00  | 10 | 23.45

    2010-06-01 17:00:00  | 10 | 66.74

     

    Table 3 (Calendar table)

    Date:  ID: Money

    00:00:00 | 0 | 0

    01:00:00 | 0 | 0

    02:00:00 | 0 | 0

    etc

    etc

     

    My query so far

     

    SELECT date, SUM(money) FROM table_1 WHERE date BETWEEN (Date 1) AND (DATE2) GROUP BY ID UNION SELECT date, SUM(money) FROM table_1 WHERE date BETWEEN (Date 1) AND (DATE2) GROUP BY ID.

     

    How can I add the third table in to find the hours that were not found in this query?  Thanks to anyone who can help out.

  10. I need to select columns from 2 tables however not user a join.  It doesn't seem to want to work, is my second select correct where I have the 2 columns equaling each other?

     

    SELECT a.date AS date, a.source AS source, SUM(a.total) AS total, (SELECT SUM(b.search) FROM table2 b WHERE a.date = b.date AND a.source = b.source) AS search FROM table1 a WHERE a.date BETWEEN '2010-08-01' AND '2010-08-31' GROUP BY date, source

  11. Well you can always use the count function if your looking to get just the first column.  Are you trying to count how many times a certain result is returned or is it just every result you want counted to see how many times it was found?

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