Jump to content

ceci

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Posts posted by ceci

  1. I found this  "https://github.com/mojombo/clippy" Clippy  into our site which uses php.

     

    The example is written in Rails (Ruby). https://github.com/mojombo/clippy#readme

     

    Can anyone help me convert that into php? Here is my attempt but not getting any results.

     

    <?

    if ( ! function_exists('clipit'))

    {

     

        function clipit($var = 'Copy me please')

    {

     

    $clippy_url = '/resources/flash/clippy.swf';

    $clippy = <<< EOD

      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"

                width="110"

                height="14"

                id="clippy" >

        <param name="movie" value="$clippy_url"/>

        <param name="allowScriptAccess" value="always" />

        <param name="quality" value="high" />

        <param name="scale" value="noscale" />

        <param NAME="FlashVars" value="text=$var">

        <param name="bgcolor" value="#FFFFFF">

        <embed src="$clippy_url"

              width="110"

              height="14"

              name="clippy"

              quality="high"

              allowScriptAccess="always"

              type="application/x-shockwave-flash"

              pluginspage="http://www.macromedia.com/go/getflashplayer"

              FlashVars="text=$var"

              bgcolor="#FFFFFF"

        />

        </object>

    EOD;

    return $clippy;

    }

    }

    ?>

     

    Thanks

     

  2. hi.

     

    this is another general question.

     

    I need to know if content has been changed or updated.

     

    Scenario: there is a Submitter and a Reviewer.

    Submitter submits articles for review.

    Reviewer reviews article and suggests changes before being accepted.

    Submitter makes the changes and resubmits back to Reviewer.

     

    I want to show the Reviewer that the suggested changes has been completed by the Submitter. How can I do this? Store the content in two separate tables and count the words on each mysql table?

     

    I really have no idea how I can do this effectively.

     

    thanks.

  3. Hi.

     

    This is general question but what's the best way to capture if someone has viewed a message or an item?

     

    I am working on a project and want to capture if it has been read or not almost like this forum captures how many times it has been viewed.

     

    thanks

     

    C

  4. sorry i was not clear the first time around.

     

    I am looking for the latest item entered from the second table (tableB) using Left Join.

     

    so if tableA has 2 items

    ID  itemType

    1  shirts

    2  pants

     

     

    and tableB has 2 orders for ID 1(shirts); 3 items for ID 2 (pants)

     

    id fk_item_id    Orders

    1  1                  red-shirt

    2  1                  white-shirt        /* last_inster_id  */

    3  2                  small-size

    4  2                  large-size

    5  2                  medium-size    /* last_insert_id for item ID2 */

     

    I am interested in the last item ordered from tableB.  HOw do I get that?

     

    In other words I want to do this but in one shot:

     

    // First Query

    $qryResultA = mysql_query("SELECT id, item_id FROM tableA");

    While($row = mysql_fetch_array($qryResultA){

          // Second Query to get the last item.

          $getItemsFromTableB = mysql_query("SELECT *, id FROM tableB WHERE fk_item_id = '$row['item_id']' ORDER BY id DESC ")

          $innerRow = mysql_fetch_array($getItemsFromTableB);

    }

     

  5. hi.

     

    i have two tables tableA and tableB in a 1-many relationship.  I need the last_id from tableB.

     

    I tried this but it returns all the items.

    SELECT last_insert_id(item_id) as 'lastID', a.book_id, a.title  FROM tableA a LEFT JOIN tableB b on a.item_id = b.fk_item_id ORDER BY item_id DESC 
    

    And if I use Limit 1, you guest it, it only returns one.

     

    It should return 1 for each item on tableA.

     

    How do I do this? Thank you.

     

    Ceci

  6. I am trying manipulate multiple rows to add/update/delete database.  Right now, the first time it INSERTS all rows correctly. During Update however, it re-enters previous values plus any new rows.  How can I stop this behavior?

     

    SUBMISSION FORM.

    <FORM><? php
    // Make sure the array has items in it. Display it only if there are items. 
    // "$array_items contains items from database. 
    if(count($array_items) != 0) {
    foreach($array_items as $className => $sub_className){ ?>
    <tr>
    <!-- Display  Class -->
    <td rowspan="<?php print $rowspan_no+1; ?>">
    <?php print $className; ?> 
    </td> 
    <!-- Display subclass -->
    <td rowspan="<?php print $rowspan_no+1; ?>">
    <?php print $sub_className; ?> 
    </td>
    
    <?php foreach($item as $item_key => $item_name){ ?>
    <?php $m_rows = mysql_fetch_array($m_qry);?>
    <tr id='r_id<?=++$count?>_box'>
    <!-- Display the Name -->
    <td><?php print $item_name;?> 
    <?php // IMPORTANT*** THE NEXT 3 HIDDEN FIELDS ARE TO BE USED TO ADD OR UPDATE NEW ROWS?>
    
    // This field contains an ID if there was a previous entry. 
    <input name="main_item_id[<?=$count?>]" type="hidden" value="<?=$m_rows['id']?>" > 
    
    // This field contains IDs from Database for all rows for data entry. Thus will always have an ID.  and an X number of items.  
    <input name="secondary_id[<?=$count?>]" type="hidden" value="<?=$secondary_id?>" > 
    <input name="sub_className[<?=$count?>]" type="hidden" id="uniqueid<?=$count?>" value="<?=$sub_item;?>"> 
    </td>
    // user will enter data here
    <td><input type="text" name="duration[<?=$count?>]" value="<?=$m_rows['duration']?>" size="3"></td>
    // user will enter data here
    <td><input type="text" name="effect[<?=$count?>]" value="<?=$m_rows['effect']?>" size="3"></td>
    
    <td> </td> 
    <?php } ?>
    </tr> 
    </form>

     

     

    HERE IS MY INSERT and UPDATE code.  The first time it INSERTS all rows correctly. During Update however, it re-enters previous values plus any new rows.  How can I stop this behavior?

    //  count($secondary_id) represents the number of rows the form has automatically generated. Eg 10 rows. 
    	  for ($i = 1; $i <= count($secondary_id); $i++) 
    	  { 
    	     //  check to see if the id exists.
    			if($secondary_id[$i])  
    			{   
    				 // Presence of 'main_item_id' represents  previous entry. if so, update it.
    					 if(!empty($main_item_id)){
    
    					$qry = "UPDATE table SET  
    					effects='$effects[$i]', 
    					duration='$duration[$i]' WHERE id='$main_item_id[$i]'"; 
    					$result = mysql_query($qry);
    					if ($result)
    					{
    						$count++;
    					} 
                                               echo $count .' items updated.';
                                     // if no 'main_item_id' exists, then insert. 
    // This is giving me duplicates! Meaning, re-enters whatever was previously entered + the new entries.               
    			 }else { // there is no 'main_item_id' so Do INSERT. 
      							 if($duration[$i]){
    							echo 'insert items'; 	
    							$count =0;
    							$insert_qry = "INSERT INTO table(duration, effects) VALUES('$duration[$i]','$effects[$i]')";			 
    								$result = mysql_query($insert_qry); 
    								if ($result)
    								{
    										$count++; 
    								}
                                                                   echo $count .' items inserted.'; 
    							 } 		
    				 }		
    			}
    

     

    Thanks again.

     

    C

  7. I want to be able to quickly do a loop using a simple count like this:

    for($i = 0; $i < count($items); $i++) {
    // do things here. 
    }

     

    I tried using the unset() function but it does not seem to do anything.

    for($j=1; $j <= count($items); $j++){
      if($items[$j]==NULL){
      unset($items[$j]);
    }
    }

     

    There has to be an easy way to do this.

  8. Hi.

     

     

    echo '<pre>'. print_r($items, true).'</pre>'; 

    The statement above returns the following array:

    Array

    (

        [1] => 325

        [2] => 326

        [3] => 327

        [4] =>

        [5] =>

        [6] =>

        [7] =>

        [8] =>

        [9] =>

        [10] =>

        [11] =>

        [12] =>

    )

     

    echo COUNT($items) 

     

    returns: 12

     

    The count should be 3 not 12. How can I exclude the empty array?

     

    thanks

  9. Hi.

    I have two tables. One table with pain_meds and the other with diabetes_meds. I want to dynamically generate a table that displays a row for each Diabetes med for every pain_med.  For example, for the Amaryl diabetes med  there are 5 possible pain_meds (oxycode,Vicodin,ultram,morphine) that it interacts with. The same is true for

    Avandaryl and Byetta.  For a better visual I'll try to attach a screenshot of the desired output.

     

    mysql> select dname from diabetes_med;
    +-------------------------------+
    | dname 			|
    +-------------------------------+
    |Amaryl          		| 
    |Avandaryl 			| 
    |Byetta  			| 
    +-------------------------------+
    2 rows in set (0.00 sec)
    
    mysql> select drug_name from pain_meds;
    +------------------------+----------+
    | drug_name                 |
    +------------------------+----------+
    | oxycode  			     |  
    | Vicodin 			     |  
    | ultram  			     |   
    | morphine 			     |	 
    +------------------------+----------+
    

     

    Here is what I got so far but I can't seem to get it to work.  I hope you can help me out. Thanks in advance.

     

     	 
    $diabetes_med =  mysql_query("select dname from diabetes_med");
    $diabetes_med_results = mysql_query($diabetes_med);
    $diabetesCount = mysql_num_rows($diabetes_med_results);
    while($diabetes_row = mysql_fetch_array($diabetes_med_results)){
               // put items into an array ... maybe this helps....
    	$temp_array[] = $diabetes_row['dname'];
    }		
     // Grab diabetes_meds and display items on first row. 
     foreach($temp_array as $diabetes_drug){
    	   $pain_meds_qry =  mysql_query("select drug_name from pain_meds;");
        // now lets do the pain_meds
          while($painmed_row = mysql_fetch_array($pain_meds_qry)) {  
    		 <table>
             <tr id='record<?=++$increment?>'>  
              <td>  
    // Try printing the drug name on left-most column eg. Amaryl, Avandaryl...etc
    print $diabetes_drug;
    
    </td>
              <td> 
     <input name="painmed[<?=$increment?>]" type="hidden" id="painmed<?=$increment?>" value="<?=$painmed_row['drug_name']?>">   
     <!-- print  pain med eg. oxycode, Vicodin, ultram, morphine -->
     <?=$painmed_row['drug_name'] 				
              </td>
               <td><input type="text" name="effects[<?=$increment?>]" value="" size="3"> 
     </td>
     </tr> 
        </table>
    		 }
    	}
       }    

     

    At best this only generates one table regardless of how many diabetes_med are present. 

     

    [attachment deleted by admin]

  10. Your code will print

    First Row: Beatles, Love Me Do, Hey Jude, Helter Skelter

    Second Row: Rolling Stones, Waiting on a Friend, Angie, Yesterday

    etc.

     

    I don't want that.

     

     

    Looks like instead of  arrays like this

    $Rockbands = array(

    "First Row" => array('Beatles','Love Me Do', 'Hey Jude','Helter Skelter'),

    "Second Row" => array('Rolling Stones','Waiting on a Friend','Angie','Yesterday\'s Papers'),

    "Third Row" => array('Eagles','Life in the Fast Lane','Hotel California','Best of My Love'),

     

    I might have to create separate arrays for each row so I have more control over it.  Right b/c all the arrays belong to the $Rockbands it doesn't seem possible if place an if statement inside of it to only execute the First Row or the Second Row. It prints all the arrays sequentially which is probably how multi-dimentional arrays is supposed to behave.

     

     

     

  11. Well based on the given array, I would like to print only items from that array, say

    foreach($Rockbands as $key => $val){
    if ($key = "First Row"){
       echo $val; //print values for this array only. eg. Beatles, Love Me Do, Hey Jude, Helter Skelter 
       // Do not print anything else. 
    }elseifif ($key = "Second Row"){
       echo $val; //print values for this array only. eg. Rolling Stones, Waiting on a Friend, Angie, Yesterday 
       // Do not print anything else. 
    }
    }
    

     

    Because I am inside the foreach() loop  my problem is that it prints everything in sequence.  At first I thought the if statementwould be able to control this but it does not.

     

    Maybe I was erroneously thinking that I could do something similar to this but inside the foreach() loop: 

    <?php
    $d=date("D");
    if ($d=="Fri")
      echo "Have a nice weekend!";
    elseif ($d=="Sun")
      echo "Have a nice Sunday!";
    else
      echo "Have a nice day!";
    ?>

     

     

  12. I have the following code.

    $Rockbands = array(
    "First Row" => array('Beatles','Love Me Do', 'Hey Jude','Helter Skelter'),
    "Second Row" => array('Rolling Stones','Waiting on a Friend','Angie','Yesterday\'s Papers'),
    "Third Row" => array('Eagles','Life in the Fast Lane','Hotel California','Best of My Love'),
    

     

    I need to do print each row according to the key using foreach() function. I though the following code would work but it does not.

    foreach($Rockbands as $key => $val){
      // echo $key prints prints First Row, Second Row..etc. 
    IF($key == "First Row"){
         echo 'display First Row array'; 
    }elseif($key == "Second Row")
        echo 'display Second Row array.';
    }else{
       echo 'nothing to display'; 
    }

     

    The code above ignores the if statement and prints:

    display First Row array

    display Second Row array.

    nothing to display

     

    How do I achieve this? thanks

     

    C

     

     

  13. Thanks for the link its somewhat helpful.

     

    To make things simpler, say I have two variables.

     

    $var1 = |A|B|C|;

    $var2 = |X|Y|Z|;

     

    how do i generate dynamically table with a top header with A B C and a LEFT COLUMN with X Y Z?

    I am hoping that once this is figured out, things will start to make sense at least on my end.

     

    Right now I am just stumped  as to how to achieve this... I hope someone has an example I can take a look at.

     

    Thanks again.

     

    C

  14. Hi all.

     

    I have a mysql table with two main columns ColumnX and ColumnY each containing data in '|' delimited format.

    Eg. Column X = |A|B|C|D|E| and Column Y = |a|b|c|d|e|

     

    Using this data column X and Column Y I need to Dynamically construct a table like the one below. The end-user will be able to

    enter a value for each corresponding X,Y value. eg. good bad. See attached file for screenshot.

     

    <table  border="2">
    <tr>
    <td> </td>
    <td>A</td> 
    <td>B</td> 
    <td>C</td>
    <td>D</td>
    <td>E</td>
    <td>F</td>
    <td>G</td>
    </tr>
    <tr>
    <td>a</td> 
    <td>good</td> 
    <td>good</td> 
    <td>good</td>
    <td>bad</td>
    <td>good</td>
    <td>good</td>
    <td>good</td> 
    </tr>
    <tr>
    <td>b</td> 
    <td> </td> 
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td> 
    <td> </td>
    </tr>
    <tr>
    <td>c</td> 
    <td> </td> 
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td> 
    <td> </td>
    </tr>
    <tr>
    <td>d</td> 
    <td> </td> 
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td> 
    <td> </td>
    </tr>
    <td>e</td> 
    <td> </td> 
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td> 
    <td> </td>
    </tr>
    <td>f</td> 
    <td> </td> 
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td> 
    <td> </td>
    </tr>
    <td>g</td> 
    <td> </td> 
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td> 
    <td> </td>
    </tr>
    </table> 
    

    Take a look at this image to give you a better idea of what I need to accomplish.

    http://audiologyonline.com/resources/article/hatchertable.png

     

    What would be the best way to accomplish this?

     

    Thank you so much.

     

    Ceci

     

    [attachment deleted by admin]

  15. Thank you! That fixed that problem.

     

    My other issue I noticed is on the update.  Every time I update I get an extra "|" added at the beginning. For instance, this is my new string stored on the MySQL database after 3 updates.

     

    |||new item|item 2|item3

     

    My other question is, how can I ensure that the items stored are always very tight(no whitespaces between the items) like this:

     

    DESIRED: 

    |item 1|item 2|item 3|item 4|

     

    NOT DESIRED: (notice spaces) 

    |item 1 |item 2 | item 3|item 4|

     

    Thanks again for saving my life.

     

    Ceci

  16. I tried your code and this is what I get:

    |item 1|||||||||||||||||||||||||||||

     

    print_r($fruits) returns this

     [fruts] => Array
            (
                [1] => item 1
                [2] => 
                [3] => 
                [4] => 
                [5] => 
                [6] => 
                [7] => 
                [8] => 
                [9] => 
                [10] => 
                [11] => 
                [12] => 
                [13] => 
                [14] => 
                [15] => 
                [16] => 
                [17] => 
                [18] => 
                [19] => 
                [20] => 
                [21] => 
                [22] => 
                [23] => 
                [24] => 
                [25] => 
                [26] => 
                [27] => 
                [28] => 
                [29] => 
                [30] => 
            )
    

     

    I know the empty arrays are causing the problem. I thought the is_array() function would take care of that. No?

     

    thank you for your help.

     

    Ceci

  17. I have a form that passes the following array 'fruits'. The ARRAY can contain up to 30 items ( or 30 different fields ).

    It gets store in the following format: |oranges | apples | pears |... into MySQL.

     

    Before saving to MySQL, I do following:

    if(is_array($fruits)){
    $fruitarray = "|" . implode("|",$fruits));
    }

     

    Now if I

    print_r($_POST); 

    I see the following:

     

    [fruits] => Array
            (
                [1] => |oranges 
                [2] => apples 
                [3] => pears
                [4] => 
                [5] => 
                [6] => 
                [7] => 
                [8] => 
                [9] => 
                [10] => 
                [11] => 
                [12] => 
                [13] => 
                [14] => 
                [15] => 
                [16] => 
                [17] => 
                [18] => 
                [19] => 
                [20] => 
                [21] => 
                [22] => 
                [23] => 
                [24] => 
                [25] => 
                [26] => 
                [27] => 
                [28] => 
                [29] => 
                [30] => 
            )
    

     

    Here it the problem. On the database, I get extra "|"s at the end. 

    |oranges | apples | pears |||||||||||||||||||||||| How can I get rid of these extra pipes

     

    Is there a some kind of unset($fruits) or something to ignore empty arrays?

     

    Thank you for in advance.

     

    ceci

  18. Hi.

    We are in the process of UPGRADING PHP 5.1.6 to PHP 5.2.4.

     

    After upgrade was complete I started to get this error: "Notice: Undefined index: ".

     

    The code below used to work on PHP 5.1.6 but it no longer works after the upgrade.

     
    include("include/session.php");
    
    if ($_SESSION['program'] == "bo") {  
            
            $sportType = "Boxing";
        
       }

     

    Returns: Notice: Undefined index: It behaves as if $_SESSION['program'] is not defined.

     

    I could hide the error by using this "Error_reporting(E_ALL^E_NOTICE)" but I don't want to since it will only hide the problem and it takes forever to load the page.

     

    What can I do? thanks for  your help.

     

    C

     

     

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