Jump to content

irkevin

Members
  • Posts

    295
  • Joined

  • Last visited

Posts posted by irkevin

  1. if(isset($_POST['submit'])){
    foreach($_POST['box'] as $key => $boxes){
            $_POST['box'][$key] = $myBox;
    $the_box = implode(', ',$_POST['box']);
    
    $sql = "UPDATE yourtable SET field =  value WHERE id IN ($the_box)";
    $result = mysql_query($sql) or die(mysql_error());
    
    if($result){
                  echo 'Success'
              }			
    }
    }
    

     

    It might be what your looking for. let me know

  2. Hi,

     

    I'm lost, I don't know if this is possible using PHP, guess I will have to ask. Here it goes. Below are some array:

     

    Array
    (
        [0] => 1
        [1] => ps2
        [2] => game
    )
    
    Array
    (
        [0] => 2
    )
    
    Array
    (
        [0] => 3
        [1] => game
    )
    

     

    As you can see, the first array has more data in it, how do I tell PHP to use only the array with more data?

     

    I hope this is possible. Please help guys.

  3. Hi,

     

    I have a problem that's occuring when using cookie in IF statement..

     

    below is the code

     

    	
    if(isset($_COOKIE['login']) && $_COOKIE['login'] == '3'){
    header('location:index.php');
    }

     

    When I run this, I get

     

    The page isn't redirecting properly  
    
    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
        *   This problem can sometimes be caused by disabling or refusing to accept
              cookies.

     

    Any Idea? it the same with all browsers. It's like a loop than never ends.. I don't understand why this is happening. My browser accepts COOKIES.

     

    Can someone Help?

  4. Hello

     

    I'm having a little problem, where I'm selecting categories from mysql, along with it's subcategories. The problem is, whenever there are multliple SUBcat for a category, it keeps repeating the category name.

     

    Here an example of what's happening:

     

    Array
    (
        [0] => stdClass Object
            (
                [cat_name] => computers
                [sub_name] => Mouse
            )
    
        [1] => stdClass Object
            (
                [cat_name] => computers
                [sub_name] => Keyboard
            )
    )
    

     

    I would prefer it to be like so:

     

    Array
    (
        [0] => stdClass Object
            (
                [cat_name] => computers
                [sub_name] => Mouse
                [sub_name] => Keyboard
            )
    )
    

     

    The mysql query is like so

     

    		
    $query = "SELECT category.cat_name,sub_cat.sub_name FROM sub_cat
    	LEFT OUTER JOIN category ON sub_cat.cat_id = category.id";
    

     

    Table category has those fields

     

    CATEGORY

    id

    cat_name

     

    SUB_CAT

    id

    cat_id

    sub_name

     

    Can someone please explain how to achieve this? I'm stuck :S Thank you

  5. @ lemmin : I didn't write the query yet, I just fired up phpMyAdmin, and entered 44.50, but when saved, it become 45 :s :s

     

    @PFMaBiSmAd  : I didn't write any code, but as you said, I entered it directly into the table, and came up with this problem.

     

    Finally

     

    @ jonsjava : setting it to DECIMAL(15,2) did the trick... Thanks a lot man XD

     

    Thanks for your hepl everyone.. topic marked as solved I guess!

  6. Hi

     

    This is quite confusing me.. I've searched here but can't find an answer, please help

     

    I have a table called products.. In which there is a price field. It's set to DECIMAL.

     

    So, when i store money in it.. Say $44.50 , it cut off the .50 . Why is it so? How can I store the cents also?

     

    I heard that using FLOATS isn't the good way to go, but then again, if DECIMAL doesn't display the cents, what should I do?

     

    Any Advice guys or gals?

     

    Thanks

  7. Ah the title says, I want to have a link acting as a submit button.

     

    I made it. Like below:

     

    <script type="text/javascript">
    
    function submitForm(type){
          
       for(i = 0;i < post_form.lenght;i++)
          document.post_form.post[i].value = type;
                
       document.post_form.submit();
    }
    
    <form method="post" action="test.php" name="post_form">
    <input type="checkbox" name="post[]" value="1" /> 1
    <input type="checkbox" name="post[]" value="2" /> 2
    <input type="checkbox" name="post[]" value="3" /> 3
    </form>
    <a href="javascript:submitForm('delete');">Delete</a>
    </script>
    

     

    But, when using a submit button, you specify the <name> attribute to use it with php. Like below

     

    <input type="submit" name="submit" value="submit" />
    
    <?php
    
    if(isset($_POST['submit']){
       code there
    }
    

     

     

    The name submit will be use in php. But when using a link, how do I specify a name to refer it to php?

     

    Can someone please help?

  8. Ah the title says, I want to have a link acting as a submit button.

     

    I made it. Like below:

     

    <script type="text/javascript">
    
    function submitForm(type){
    
    for(i = 0;i < post_form.lenght;i++)
    	document.post_form.post[i].value = type; 
    
    document.post_form.submit();
    }
    
    <form method="post" action="test.php" name="post_form">
    <input type="checkbox" name="post[]" value="1" /> 1
    <input type="checkbox" name="post[]" value="2" /> 2
    <input type="checkbox" name="post[]" value="3" /> 3
    </form>
    <a href="javascript:submitForm('delete');">Delete</a>
    </script>
    

     

    But, when using a submit button, you specify the <name> attribute to use it with php. Like below

     

    <input type="submit" name="submit" value="submit" />

     

    The name submit will be use in php. But when using a link, how do I specify a name to refer it to php?

     

    Can someone please help?

  9. I've been searching for a solution about this but im stuck. Here's is a problem..

     

    I have this code:

    $new_users = User::find_by_date();
    
    echo "<pre>";
    print_r($new_users);
    echo "</pre>";
    
    

     

    The result is :

    Array
    (
        [0] => User Object
            (
                [id] => 
                [firstname] => 
                [lastname] => 
                [username] => jkjkjkjkjkjk
                [password] => 
                [dob] => 
                [email] => 
                [location] => 
                [date_created] => 
            )
    
        [1] => User Object
            (
                [id] => 
                [firstname] => 
                [lastname] => 
                [username] => tester
                [password] => 
                [dob] => 
                [email] => 
                [location] => 
                [date_created] => 
            )
    
    )
    

     

    When i do a foreach to get the data, i do it like this:

    $new_users = User::find_by_date();
    
    
    foreach($new_users as $users){
    echo $users->username.'<br />';
    }
    

     

    It outputs the username like it should. EG:

     

    jkjkjkjkjkjk

    tester

     

    What i really want is to seperate then with comma using the implode function.

     

    I tried this:

     

    foreach($new_users as $users){
    echo implode(", ",$users);
    }
    

     

    But i get

     

     

    Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\mu-anime\var.php on line 8

     

    Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\mu-anime\var.php on line 8

     

     

    I dont know what to do anymore, can someone help me plz?

  10. Thats perfect. Exactly what i needed. Thanks bro

     

    Below is the code. for those who might need it

     

    $make_date = mktime(0,0,0,date("m"),date("d")+5,date("Y"));
    $remove_after = date('Y-m-d',$make_date);
    $today = strftime('%Y-%m-%d');
    
    "SELECT * FROM tableName WHERE date_added >= '$today' AND date_added <= '$remove_after' ORDER BY date_added ASC"
    

  11. Hi,

     

    I'm stuck with this now.

     

    I have a field in my table call date_added

     

    I want to retrieve data from the latest date added and output it for only 5 days on a page.

     

    I can't figure out how to do this.

     

    Can someone please explain how to proceed?

     

    My query look like this:

     

    SELECT * FROM tableName  ORDER BY date_added ASC

     

    But then, i Don't have a clue how to proceed with this date thing :s

  12. Grrrrrrrrr im such a .......... !! Earlier i was doing

     

    
    $list = '';
    
    $list .= 
    
    etc etc
    
    return $list;
    

     

    But then when calling the function, i was just typing generate_menu(0)... it should have been

     

     

    echo generate_menu(0)

     

    Anyways, thanks.. Tcare

  13. Hello everyone,

     

    I have a function that return some links from mysql DB. Below is the actual code

     

    function generate_menu($parent){
    
    	$has_childs = false;
    
    	global $show_menu;
    
    	foreach($show_menu as $key => $value){
    		if($value['parent_id'] == $parent){
    			if($has_childs === false){
    				$has_childs = true;
    			}
    			if($value['parent_id'] == '0'){
    				echo '<div id='.$value['class_id'].$value['class'].'>';
    				echo '<div id='.$value['class_id'].$value['style_id'].'>'.$value['title'].'</div>';
    				echo '<ul id='.$value['class_id'].$value['list_style'].'>';
    			}else{
    				echo '<li><a href="">'.$value['title'].'</a>';
    			}
    			generate_menu($key);
    
    			echo '</li>';
    		}
    	}
    	if($has_childs === true){
    		echo  '</ul>';
    		echo '</div>';
    	}
    
    }
    

     

    As you can see. I'm echoing html inside the function. Is there a way i can return the values instead of echoing it straightly into the function?

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