Jump to content

acefirefighter

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Posts posted by acefirefighter

  1. I was looking for my two day old post with no replies and I found yours so here is my 2 cents.

     

    I am not 100% sure and I may be way off base but it seems to work in my head and my syntax for preg_match may not be right on either. I don't use reg-ex that often.

     

    <?php
    
    $feed = simplexml_load_file('http://video.news.com.au/feed.atom');
    $pattern = '/href="(.)*"/';
    $link = preg_match($pattern, $feed->entry->link);
    
    echo $link;
    
    ?>
    

  2. I am really not sure if this is a problem with me (probably is), php or mysql.

     

    I have a calendar that I am adding events to. If I want to edit only the date I can but only once after I make this update I am out. If I attempt to update the time or event title the database is never updated and I am no longer able to update the date.

    here is the controller for the save.

    <?php 
    function eventsave() {
    	$details = $_POST;
    	$this->load->model('eventsmodel');
    
    	$this->eventsmodel->eventsave($details,'', TRUE);
    
    	redirect('/admin/events', 'location');
    
    }
    ?>
    

    I have turned off the redirect to see if I was getting any errors and they seem to be non existent.

     

    Here is the model that is used to create a new entry and update a record.

    <?php
    function eventsave($event) {
    
    		$startdate = explode('-', $event['startdate']);
    
    		$start = mktime($event['starthour'], $event['startmin'], 0, $startdate['0'], $startdate['1'], $startdate['2']);
    		$end = mktime($event['endhour'], $event['endmin'], 0, $startdate['0'], $startdate['1'], $startdate['2']);
    		$name = $event['name'];
    
    
    		if (isset($event['id'])) { // if is true then this is an update not a new event
    			$data = array(
    				'name' => $name,
                  	 	'start' => $start,
                  	 	'end' => $end
                            );
    			$this->db->where('id', $id);
    			$this->db->update('events', $data); 
    		}else{
    			$this->db->set('name', $name);
    			$this->db->set('start', $start);
    			$this->db->set('end', $end);
    			$this->db->insert('events');
    		}
    
    }
    ?>
    

     

     

    I am using code igniter if that helps and the information being submitted by the form looks good.

     

    This is the submitted update array and the new event array is just missing the "id"

    Array
    (
        [name] => test
        [startdate] => 05-14-2011
        [starthour] => 1
        [startmin] => 0
        [endhour] => 1
        [endmin] => 0
        [id] => 54
        [saveevent] => save
    )
    
    

     

    Any suggestions would be appreciated. Thank you.

     

  3. It's actually not your second HEREDOC; that is the problem, it is your first. The first one has an extra space after the ending semicolon. and that is why you are getting the error.  Remember NOTHING can go on the same line as the closing HEREDOC or it is considered to be part of the same statement.

     

     

  4. You could do something like this:

    <?php
    $tmp = array('tech'=>$tech,'crew'=>$crew,'number'=>$number);
    foreach ($tmp as $f=>$v) {
        if ($v == '') {
           $tmp[$f] = 'Not Assigned';
        }
    }
    ?>

    When you want to use the value, you would need to get the value from the array.

     

    Ken

     

    I like that. It is way better than what I came up with. Nice one.

  5. Something like this maybe? not sure if it is necessarily more efficient. Just run something like this in a while loop right after you pull the values from the database they will still be in an array.

    <?php
    $array = array(
        'first' => 'John',
        'middle' => '',
        'last' => ''
    	);
    
    	// this cycle echoes all associative array
    	// key where value equals "apple"
    	$i = 0;
    	foreach ($array as $row) {
    		// Fixed Problem with array position.
    		if($i == false) {
    			reset($array);
    			$i ++;
    		}
    		// check for empty array values, echo and change value to not assigned
    	    if (empty($row))  {
    	    	$key = key($array);
    	        echo $key.' is empty<br />';
    	        $array[$key] = "Not Assigned";
    	    }
    	    next($array);
    	    
    	}
    	foreach ($array as $row) {
    
    		echo $row .' ';
    	}
    ?>
    

     

  6. Ya you can, Try this. I haven't tested but I think it will get you what you are looking for.

     

    <?php
    $i = 0;
    while($row = mysql_fetch_array($sql)){ 
                 $tr = ($i % 2) ? '<tr>' : '';
                 $trclose = ($i % 2) ? '</tr>' : '';
                 $id = $row["id"];
    		 $product_name = $row["product_name"];
    		 $price = $row["price"];
    		 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
    		 $dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2">
            '.$tr.'
              <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td>
              <td width="83%" valign="top">' . $product_name . '<br />
                $' . $price . '<br />
                <a href="product.php?id=' . $id . '">View Product Details</a></td>
            '.$trclose.'
          </table>'.
    	$i++;
        }
    ?>
    

  7. This isn't really a php question but more for JavaScript especially if you aren't wanting the page to reload all of the time. I use what is called jQuery and I have a few pages for you to look at and maybe you can sort out what you want to do.

     

    http://api.jquery.com/click/

     

    http://api.jquery.com/show/

     

    http://api.jquery.com/hide/

     

    If you aren't wanting to use a database and aren't wanting to use files you can place all of your information that you want hidden in a div and "hide" it until a user "clicks" on the image and that would trigger the "show" if you were wanting to run from files I would look into jquery's post function but then you are getting into using an xml or json return which might just be overkill unless you have a ton of data.

     

    Look at the code on this page too. It is for a tabbed menu but the same concepts can be utilized and the code is easy to sort out.

     

    http://yensdesign.com/2008/12/create-a-smooth-tabbed-menu-in-jquery/

     

    and here is one that explains what is happening in the jquery a little better and talks about jquery post

     

    http://www.jasonbrennan.com/jquery/jquery-ajax-or-is-it-jquery-json/

     

    Sorry about the rambling. I hope this gets you started. I may be a little slow to respond but I will get back to you.

  8. Try this I added array_pop() it should remove the last element of the array. but I am guessing that submit_query is the last element in the $_POST array.

     

    <?php 
    
    $criteria = array();
    if(!empty($_POST)) {
            array_pop($_POST);
      	foreach ($_POST as $_POST) { 
    	if (!empty($_POST)) {
    	array_push($criteria, $_POST);
    	}
    }
    
    $userserch = implode('</strong> > <strong>', array_map('htmlentities', $criteria));
    }
    
    
    ?>
    
    

  9. You could use a foreach loop and empty() to check and see if each element in your $_POST array is empty and if it is don't use it. Maybe even use array_push() to apply the results that aren't empty to a new array and implode that new array with the html you are wanting to use. Something like what is below. I haven't tested it but I think it should work.

    <?php 
    
    $criteria = array();
    if(!empty($_POST)) {
      	foreach ($_POST as $_POST) { 
    	if (!empty($_POST)) {
    	array_push($criteria, $_POST);
    	}
    }
    
    $userserch = implode('</strong> > <strong>', array_map('htmlentities', $criteria));
    }
    
    
    ?>
    

     

  10. Something like one of these should work for you. They will alert as soon as the page loads. If you didn't want the $php_value in an input tag for validation reasons you could always place it in a div with display:hidden;. This isn't strictly "javascript" since you can see I loaded jQuery I am using the syntax for that. I like the second option a lot more than the first just because I am not having to send the JS to the view with a variable.

    <?php // Option One
    $php_value = 'username';
    
    $script = <<<EOT
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    alert('$php_value');
    });
    </script>
    EOT;
    
    ?>
    <html>
    <head>
    <?php echo $script; ?>
    </head>
    <body>
    </body
    </html>
    
    
    <?php // Option Two
    $php_value = 'username';
    ?>
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    var alert_value = $("#username").attr('name');
    alert(alert_value);
    });
    
    </script>
    </head>
    <body>
    <input type="hidden" id="username" name="<?php echo $php_value;?>" />
    

  11. all records are displayed but image item value (pic) are not display......

    thanks

     

    It may be because your file path isn't right ex...

    if your images are stored at http://www.yourSite.com/_images/

    and the page you are on is http://www.yourSite.com/california/shopping/

     

    then your script is looking for the images in http://www.yourSite.com/california/shopping/_images/

     

    Im not sure if that is the case but I would bet on it. your going to have to define more of your path to the image.

     

    I pull everything through the my base index.php file so I don't usually have to deal with this. Anyone feel free to chime in if I am wrong.

  12. I am really not sure what it is your going for but I think I interpreted enough to get you this.

    <body>
    <p><?php
    while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) {
    echo $row_Recordset1['prod_image'] . '<br />'; 
        
    $image_filename = trim("_images/". $row_Recordset1['prod_image'].".jpg");
        echo '<img src="'.$image_filename.'" alt="imagelogo" name="image1" width="223" height="73" id="image1" style="background-color: #FFCCCC" />';
        echo '<br /><br /><br />';
    }
    </p>
    </body>

     

  13. I think this might work for you. It may take a little bit to integrate into you existing html but you will get it.

     

    If my code doesn't work don't shoot me. The basic idea is to put all of your error messages into a single array and then loop through that array and echo them all at the top of the new page.

    <?php
    		  //success
    		  //change password in db
    		  $errors = array();
    		  $querychange = mysql_query("UPDATE users SET password='$newpassword' WHERE username='$username'");
    		  
    		  session_destroy();
    		  
    		  array_push($errors,'Password Has Been Changed Successfully !'); //move these 
    		  
    		}
    		else{
    		    array_push($errors,'new password doesnt match!'); //move these
    
    	}
    }
    else {
          
               array_push($errors,'old password doesnt match!'); //move these
               
               
               /*
                *  might want to remove this and redirect the user backto the form
                *  instead of killing the page.
                */
    	   die('old password doesnt match'); 
    	}
    }
     else
     {
    
    echo "";
    include 'changepassword_form.html';
    exit();
     }
    }
    else{
        echo 'you must be logged ';
    
    }
    ?>
    
    <html>
    
    <body>
    <?php (isset($errors) ??>
    <div style="width:100%;bgcolor:red;">
    <?php
    $i = 1;
    foreach ($errors as $error){
    echo $i . ' ' . $error . '<br />';
    $i++;
    });?> 
    </div>
    <div>
    <!-- all of your HTML here -->
    </div>
    </body>
    </html>

     

  14. Ok, I think I understand what your going for.

     

    I think you want to keep a record of all changes, right?

     

    I have had this idea bouncing around in my head for a while it might not be what you are looking for and may prove to be a little complex but since you have no replies yet here you go.

     

    You could add another field to the Incidents table called "impacted_products" and I would use the implode() and explode() functions to store the information in there.

     

    To save you would do something like this...

    <?php 
    $time = time();
    $impacted = array('12','4','34','25'); // the impacted product id's
    
    
    
    /*
    * Current output for $impacted is 
    * Array ( [0] => 12 [1] => 4 [2] => 34 [3] => 25 ) 
    */
    // We are adding the time here too.
    $impactString = implode(',', $impacted) . ':' . $time .';';
    
    
    /*
    * Current output for $impactString is 
    * 12,4,34,25:1297461648;
    * 
    * This is what I would save to the new table column
    */
    
    $queryResult = //some query to retrieve what is currenty in the table cell for the current incident
    
    if($queryResult != null) {
        $impactString = $queryResult . $impactString;
    }
    
    $saveQuery = //Query to save $impactString to the database
    
    

     

    If you were retriveing this from the database to edit it you would do something like.

    <?php 
    $query = // query to retrive the impacted_products cell
    
    $queryResult = '12,4,45,98,056,43,27,8,34,25:1297461648;'.
    			'12,4,34,25,45,7,23,877:1297461642;'.
    			'12,4,34,25:1297461348;'.
    			'52,4,34,25,1245,2,7,9:397461645;'.
    			'12,5,34,25:1297461348;';
    
    
    
    $impactHistoryStrings = array_filter(explode(';', $queryResult));
    
    /*
    * Current output for $impactHistoryStrings is 
    * Array
    *(
    *    [0] => 12,4,45,98,056,43,27,8,34,25:1297461648
    *    [1] => 12,4,34,25,45,7,23,877:1297461642
    *    [2] => 12,4,34,25:1297461348
    *    [3] => 52,4,34,25,1245,2,7,9:397461645
    *    [4] => 12,5,34,25:1297461348
    *)
    * 
    */
    
    $impactHistoryArrays = array();
    foreach ($impactHistoryStrings as $times) {
    $test = explode(':',$times);
    array_push($impactHistoryArrays, $test);
    }
    /*
    * current output of $impacthistoryarrays is
    * Array
    *(
    *   [0] => Array
    *       (
    *           [0] => 12,4,45,98,056,43,27,8,34,25
    *           [1] => 1297461648
    *       )
    *
    *   [1] => Array
    *       (
    *           [0] => 12,4,34,25,45,7,23,877
    *           [1] => 1297461642
    *       )
    *
    *   [2] => Array
    *       (
    *           [0] => 12,4,34,25
    *           [1] => 1297461348
    *       )
    * 
    *   [3] => Array
    *       (
    *           [0] => 52,4,34,25,1245,2,7,9
    *           [1] => 397461645
    *       )
    *
    *   [4] => Array
    *       (
    *           [0] => 12,5,34,25
    *           [1] => 1297461348
    *       )
    *
    *)
    */
    
    

     

    You would run explode() on impacts one more time and then run a DB query to do you Joins. and then from here you could use the data to fill your form to get it ready for the new edits or fill in a table to show a history of changes.

     

    This was an idea I have had for a while but haven't gotten to try it. You hadn't gotten any responses yet so I thought I would shoot this out there.

     

    Good luck.

  15. On line 162 it looks like there might be two tabs after the EOF; This line can't have anything else on it and there always has to be line after it so it can't be the last line in your php file.

     

    I would remove the two tabs and add an extra emply line after line 162. Try that and get back to us.

                       </tr>
    		</table>
    EOF;
    
    } // end function contract
    

     

     

     

  16. Your question is very vague. If you are looking for someone to type this for you it has already been done a thousand times a thousand different ways using many different languages. (P.S. Google is your friend)....

     

    No matter how you do this whether you use php or javascript you are going to be saving the color information to a cookie or to the session you will then retrieve this information to display across the site. Both languages are perfectly capable of doing what you need. You could actually use the database too so that you could make this change even more persistent, but after a few searches you should be able to find some information.

     

    I am sure there are many people here who would be more than happy to help you with "YOUR" code so if you have any questions about your code feel free to post them and you will get help much faster.

  17. This is actually a wordpress issue. All of the Urls in wordpress are "Hard coded" in the database. Wordpress isn't really friendly when it comes to switching servers. Every time you save an edit in a wordpress document a new URL is saved in the database to a record with those changes. You could be easily looking at making a few thousand changes in the database. A google search will get you starting in the right direction. I believe there are some changes you can make to your .htaccess file that could do some temporary redirects for you till you make the database changes.

     

     

    Good Luck

  18. It took me a little while to type this and you have a couple of answers already but I will post it anyway. I haven't tested it but it should get you going in the right direction.

    <?php 
    
    $alphabet = null;
    while($row1 = mysql_fetch_array($locals)) {
    
    if($alphabet != substs($row1['RSTOWN'],0,1)) {
    	echo strtoupper(substr($row1['RSTOWN'],0,1)); // add your html formatting too.
    	$alphabet = substr($row1['RSTOWN'],0,1);
    }
    echo '<li class="forward">
    		<a href="townpubs.php?RSTOWN='.$row1['RSTOWN'].'" rel="external">'
    		.$row1['RSTOWN'].
    		'<small class="listcounter">'.$row1['PubCount'].'</small>
    		</a>
    	  </li>'; 
    }

     

  19. 1.  Is there any reason to call those methods from the constructor rather than letting them be called on demand?

    2.  It seems like your "get" methods do a lot of work - I would expect a get method just to return the value with minimal work.  You could do this by remembering if you've calculated the result yet.

    3.  What if I want to use your class to parse another URI, rather than the one in $_SERVER?

     

    There's no need for a destructor, as your class has no external resources.  All the variables will be garbage collected by PHP.

     

    1. No there really isn't it was more just me testing things out.

    2. I think I see what your saying here. All of my "get" methods should really do is just return the value from the server and not, for example, separate the query string and place in in an associative array? This should happen elsewhere? Thanks for the tip that is a good one.

    3. I thought about this but I wasn't too sure how to implement it. I had found a php function called "parse_url" and was thinking that I could create a method that would take input from a variable and if there were none it would default back to $_server and return a parsed url.

     

    I couldn't figure out how to use the destructor in this case. Just because you have tool doesn't mean you have to use it. (PS. Don't tell my wife I said that.)

     

    Hey, thanks for your help. That is exactly the sort of thing I was looking for. I think I am the only PHPer in my town and this forum has been an awesome resource.

     

    Anyone else want to rip that apart for me I would apprciate it.

     

    Thank you.

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