Jump to content

Orasion

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Orasion's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That is unbelievably easy solution after a whole week with no answer :'( :'( I guess it's showing how I am still inexperience (read : n00b) in PHP. Thank you so much, AMcHarg.
  2. Hi all, I want to merge array values which I got from a loop for($i=0; $i<count($_SESSION['code']); $i++){ for($j=0; $j<count($_SESSION['color'][$i]); $j++){ echo $_SESSION['code'][$i]."_".$_SESSION['color'][$i][$j]."_".$_SESSION['order'][$i][$j]."_".$_SESSION['totalcost'][$i][$j]."&"; $order[] = $_SESSION['code'][$i]."_".$_SESSION['color'][$i][$j]."_".$_SESSION['order'][$i][$j]."_".$_SESSION['totalcost'][$i][$j]."&"; } } as you can see, the loop will output an array $order[]. Now I want to list the $order[] values as a single variable say $total; So if $order have 3 output like this : $order[0] = "echo0&"; $order[1] = "echo1&"; $order[2] = "echo2&"; I want to merge them all into $mergeorder and I expect the value will be like this : $mergeorder = "echo0&echo1&echo2&"; I know this is easy if $order is a fixed array but in this case $order have dinamic value from the loop. Help me with this case, Ive been thinking this a whole week P.S : fyi, what I plan to do with $mergeorder is pass it to database. Thank you in advance
  3. I change my code to this one if(strlen($_POST['categoryOther'] = 0)){ $category = $_POST['category']; } else { $category = $_POST['categoryOther']; } ..and success to submit my select category option. BUT, cannot submit input from categoryOther. I'll think another way to submit one of them. thanks for your suggestion, PFMaBiSmAd. EDIT : silly me, it is as simple as this if($_POST['category'] == "other"){ $category = $_POST['categoryOther']; } else { $category = $_POST['category']; } Now, both works.
  4. So, it's me again. Hope you dont mind I try to fetch data from mysql and list it to select option like this <td>Category</td> <td>: <select name="category"> <?php $query = "SELECT DISTINCT category FROM dress"; $sql = mysql_query($query); while($result = mysql_fetch_array($sql)){ echo "<option value='".$result['category']."'>".$result['category']."</option>"; } ?> <option value="other">New Category --></option> </select><input type="text" name="categoryOther"></td> </tr> ...and success. BUT, when I try to echo submitted value it return nothing this is the code to process above form if(isset($_POST['categoryOther'])){ $category = $_POST['categoryOther']; } else { $category = $_POST['category']; } if(isset($_POST['subcategoryOther'])){ $subcategory = $_POST['subcategoryOther']; } else { $subcategory = $_POST['subcategory']; } echo "category : ".$category."<br>"; What did I do wrong here?
  5. WORKED!!! Thanks for your suggestion and Note, I will remember it.
  6. I change my function like you suggest function returnArray(){ $foo = array(); for($i=1; $i<=3; $i++){ return $foo[] = $i; } return $foo; } when I print_r it, it just give me output -> "1" just like before :confused:
  7. Hi all, can you give me suggestion how to return value from function like this function returnArray(){ for($i=1; $i<=3; $i++){ return $i; //how to return this as array?? } } when I code "echo" inside the function then call the function it give me output => 123 but when I code "return" inside the function, it will give output => 1 Can you suggest me how to output it as array?
  8. okay. I'll try that. Thx for your answer
  9. Hi all. I try to adding checkbox when I call my function, my Class code is class SQLconn{ function fetchData($table_name, $argument, $linebreak, $end_linebreak){ $result = mysql_query("select * from $table_name where status='$argument'"); while($row=mysql_fetch_row($result)){ echo $linebreak.$row[1]."<input type='checkbox' name='option' id='checkbox' value=$row[0] />".$end_linebreak; //$row[0] is 'job_id' from database } } } and my view code is like this <?php $connect = new SQLconn(config()); $connect->connectDB(); $connect->fetchData("todo", "Undone", "<li>", "</li>"); //this is where the problem is $connect->closeConn(); ?> With that code I succesfully achieve my goal to add checkbox with right 'job_id' value but this is a workaround and not good because if I code it this way my function will be broken if use it somewhere else. My question is, how can I fix my code so I can add checkbox to view page but I can keep my function clean? Really need opinion about this??
  10. okay, honestly Im doing it in codeigniter but I think its just the same. In controller I write this $data = array( 'total' => (total-$this->input->post('total')), ); $this->db->where('id', $this->input->post('id')); //$this->input->post('id')=1 $this->db->update('cycle', $data); And that should output sql query like this (CMIIW) update cycle set total=total-1 where id=1 As for the result, before the subtraction the data is "9" but after the subtraction I have "-1" So, what did I do wrong?
  11. Hi all, Im currently trying to code a subtraction from database as in example I have database field "Total" with some integer. I want to substract the value with my input from post. Err, If you dont quite get what Im trying, I try to do this update cycle set total=total-1 where id=1; but with php How could I achieve it? :confused: thx in advance
  12. Hi again all. I have an annoying bug and cant seem to solve it for past 5 days. So, here I am, asking all of you for a help I want to fetch 3rd uri segment and use it as username then show his/her profile from. In my controller, I do this $usercheck = str_replace($this->data['revsearch'], $this->data['revreplace'], $this->uri->segment(3)); $this->data['usercheck'] = str_replace($this->data['revsearch'], $this->data['revreplace'], $this->uri->segment(3)); $sql = "select email from users where username = $usercheck ;"; $email = mysql_query($sql); $this->data['email'] = mysql_query($sql); $user = $this->ion_auth->get_user_by_email($email); note : I make $email for production purpose (real code) and make $this->data['email'] for debug purpose This is my view code <div id="myprofile"> <h2>Personal Information</h2> <p><?php echo $usercheck ?></p> <p><?php echo $email ?></p> <p>Name : <?php echo $user->first_name; ?> <?php echo $user->last_name; ?></p> <p>Email : <?php echo $user->email; ?></p> </div><!-- myprofile end --> <div id="push"></div> </div><!-- wrapper end --> And it return this Personal Information administrator Name : Ndaru Aji Email : orasionseis@gmail.com As you can see, $usercheck return my 3rd URI segment but my $email did not return any result, so the next commands return the result that I did not want. Can you give me a hint to solve this ? :confused: thanks in advance
  13. thanks mike, maybe I should read user guide before posting here btw, I follow your suggestion code but have no output with that, I think its still error but then I follow the 2nd example in this page http://codeigniter.com/user_guide/database/results.html and finally showing result that I want
  14. I'm a bit confused here, does the full code look like this <?php if(!empty($comment->result_array())) { ?> <?php foreach($comment->result_array() as $comment) {?> <p><?php echo $comment['text']; ?></p> <p><i><?php echo $comment['author']; ?></i></p> <?php } ?> <?php } else {?> <?php echo "No result"; ?> <?php } ?> cos its error and output nothing. Or did i do wrong?
  15. Hi again all, once again I need your help. I try to fetch data from my database which doesnt have any result yet. I want it to echo "No result" if there is no data from database. My code is <?php foreach($comment->result_array() as $comment) {?> <p><?php echo $comment['text']; ?></p> <p><i><?php echo $comment['author']; ?></i></p> <?php } ?> I tried to insert <?php if(!empty($comment)) { //above code } else { echo "No result"; } ?> but no output have been printed. Can you give me a hint to echo empty array like this one? Thanks
×
×
  • 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.