Jump to content

php2014

Members
  • Posts

    13
  • Joined

  • Last visited

php2014's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm really , really trying hard to make it work with your example but it just does not work. This is the first part: And this is select-request.php : All I want is that I can select this first dropdown and fetch the data from that dropdownlist from mysql and then pass it through to the second list. Data that needs to be passed through to the second dropdown is the cloud_id and category_id. I am really at a dead end here. I don't want to ask to much but maybe you can try to make what I want or something alike and explain what is happening? What I have now is various examples, what I appreciate BIG time, but both don't work and I do not know why or how I could combine it. Thank you very much.
  2. Hi Barand, I used your code as follows : $(document).ready(function() { $(".country").change(function() { var id=$(this).val(); var datastring = '{"id":$(this).val()}'; alert(datastring); //<-- what does this show $.ajax ({ type: "POST", url: "edit_form.php", data: dataString, cache: false, success: function(html) { $(".city").html(html); } }); }); }); However I receive the following message : Am I doing something wrong here?
  3. Ok. Well as you can see I use an array too with the selector part at the beginning. However, I dont get it to work in my code from the first post tk passthrough more then 1 variable from mysql. I also don't see this from the tutorial. What am I doing wrong ? Problem is I saw a lot of examples but I just dont get it to work for my own purposes. Thanks!
  4. Hi, thanks. Looks good. But, how can I translate it to my own code? I need to have mysql in it, the first dropdown filled from mysql and the second also filled from mysql but then based on the first dropdown. Maybe you can give me some pointers :-). The problem is I have seen quite some topics about it but for myself I don't get it to work.
  5. Hi all, I'm trying to code a dependable dropdownlist with php/mysql/ajax. Goal is to select one thing in the first dropdown and depending on that option (and without reloading the page) enabling the second and add the options to the second, dependant on the first. This is the index : <?php require_once($_SERVER['DOCUMENT_ROOT'].'/dbconnect.php'); ?> <script type="text/javascript" src="http://ajax.googleapis.com/ ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".country").change(function() { var id=$(this).val(); var dataString = 'id='+id; $.ajax ({ type: "POST", url: "edit_form.php", data: dataString, cache: false, success: function(html) { $(".city").html(html); } }); }); }); </script> <?php $id_test=$_POST['selector']; $N = count($id_test); for($i=0; $i < $N; $i++) { $result = mysqli_query($conn, "SELECT * FROM cloud where id='$id_test[$i]'"); while($row = mysqli_fetch_array($result)) { $id_bird = $row['id']; ?> <div style="margin:80px"> <label>Country :</label> <select name="country" class="country"> <option selected="selected">--Select Country--</option> <?php $sql=mysqli_query($conn, "SELECT category.id AS cat_id, category.name, category.type, cloud.id FROM cloud,category,link_category_cloud WHERE link_category_cloud.cloud_id = cloud.id AND link_category_cloud.category_id = category.id AND cloud.id='$id_test[$i]'"); while($row=mysqli_fetch_array($sql)) { $id_test=$row['cat_id']; $data=$row['name']; echo '<option value="'.$id_test.'">'.$data.'</option>'; } ?> </select> <br/> <br/> <label>City :</label> <select name="city" class="city"> <option selected="selected">--Select City--</option> </select> </div> <?php } } ?> And this is the edit_form.php part : <?php require_once($_SERVER['DOCUMENT_ROOT'].'/dbconnect.php'); $cat_id = $_GET['cat_id']; $cloud_id = $_GET['id']; if($_POST['id_test']) { $id_test=$_POST['id_test']; $data=$_POST['data']; $sql=mysqli_query($conn, "SELECT * FROM link_category_cloud WHERE category_id={$cat_id}"); $data=$row['cloud_id']; $id_test=$_POST['id_test']; echo '<option value="'.$id_test.'">'.$id_test.' '.$data.'</option>'; //} } ?> Now, it does not work. I'm not only tring to pass through ID to 'edit_form.php', but also $data and $id_test. Any idea how I can do this? Thank you very much, all help is so appreciated!!
  6. I know that I asked for an example and for sure I am going to use it. But most important in my eyes is to have a working code first, which I can tweak later. The $id after $insert_id is the ID of the home-table. I was able to fix it just now. What I did : $insert_id = $id; $result = mysqli_query($conn, "UPDATE home SET name='$name', active='$active' where id='$id'")or die(mysqli_error($conn)); $result = mysqli_query($conn, "DELETE FROM link_cloud_home WHERE home_id='$id'")or die(mysqli_error($conn)); if(isset($_POST['selector_cloud'])){ $id2 = $_POST['selector_cloud']; $N = count($id2); for($i=0; $i < $N; $i++) { $result = mysqli_query($conn, "SELECT * FROM cloud where id='$id2[$i]'"); while($row = mysqli_fetch_array($result)) { echo "<br>"; echo $insert_id; echo "<br>"; echo $row['id']; $sql = "INSERT INTO link_cloud_home (home_id, cloud_id) VALUES ('{$insert_id}', '{$row['id']}');"; $retval = mysqli_query($conn, $sql); if(! $retval ) { die('Could not enter data: ' . mysqli_error($conn)); } } } } $result = mysqli_query($conn, "DELETE FROM link_category_p_home WHERE home_id='$id'")or die(mysqli_error($conn)); if(isset($_POST['selector_cat_p'])){ $id3 = $_POST['selector_cat_p']; $N = count($id3); for($i=0; $i < $N; $i++) { $result = mysqli_query($conn, "SELECT * FROM category_p where id='$id3[$i]'"); while($row = mysqli_fetch_array($result)) { echo "<br>"; echo $insert_id; echo "<br>"; echo $row['id']; $sql = "INSERT INTO link_category_p_home (home_id, category_p_id) VALUES ('{$insert_id}', '{$row['id']}');"; $retval = mysqli_query($conn, $sql); if(! $retval ) { die('Could not enter data: ' . mysqli_error($conn)); } } } } Do you think this is a good fix? It seems to work now...
  7. Many thanks, but I must say that's not what I had in mind. I appreciate the code very much, but I do not understand it completely. I think as I am still learning it's just a bridge 'too far'. The code I have right now for the form, which leads to the page on my first post, is as following : <div class="box"> <br> <br> <div class="container"> <a href="home.php" class="btn btn-inverse">return</a> <form class="form-horizontal" action="home_edit_save.php" method="post"> <br /> <?php $id=$_POST['selector']; $N = count($id); for($i=0; $i < $N; $i++) { $result = mysqli_query($conn, "SELECT * FROM home where id='$id[$i]'"); while($row = mysqli_fetch_array($result)) { ?> <div class="thumbnail"> <br /> <div class="control-group"> <label class="control-label">ID</label> <div class="controls"> <p style="vertical-align:middle"><?php echo $row['id'] ?></p> </div> </div> <div class="control-group"> <label class="control-label" for="inputEmail">home</label> <div class="controls"> <input name="id" type="hidden" value="<?php echo $row['id'] ?>" /> <input name="name" type="text" value="<?php echo $row['name'] ?>" /> </div> </div> <div class="control-group"> <label class="control-label" for="inputEmail">Category P</label> <div class="controls"> <table cellpadding="0" cellspacing="0" border="0"> <?php $query1=mysqli_query($conn,"SELECT cat_p.id AS cat_p_id, cat_p.cbr_name, cat_p.type, IF(link.category_p_id IS NULL, 0, 1) AS checked FROM category_p AS cat_p LEFT JOIN link_category_p_home AS link ON cat_p.id = link.category_p_id AND link.home_id = '$id[$i]'"); while($row=mysqli_fetch_array($query1)){ $category_p_id=$row['cat_p_id']; ?> <tr> <td width="20" style="padding-bottom: 4px"><input name="selector_cat_p[]" type="checkbox" value="<?php echo $category_p_id; ?>" <?php if ($row['checked']==1) {?> checked <?php } ?>></td> <td width="100" style="padding-top:3px; padding-bottom: 1px"><?php echo $row['type'] ?></td> <td width="265" style="padding-top:3px; padding-bottom: 1px"><?php echo $row['c_name'] ?></td> </tr> <?php } ?> </table> </div> </div> </div> <?php } } ?> <br> <input name="" class="btn btn-success" type="submit" value="Update"> </form> </div> </div> Since I really want to understand what I am doing and I cannot figure out your code yet, maybe you can help me by fixing my first error? Because then I got it to work. That's the most important. Afterwards I can go and tweak the code more and more to your idea. Maybe you can help me for now how I can make sure I do not use $id as a variable and as an array? Again, thank you very much in advance!
  8. Lol OK! That's a good tip. Maybe got some starters or an example I can work with? Appreciate all your help.
  9. Ah ok I see. So I need to rename $ id in part 1 on line 5 and in part 2 then it should work right. Going to test it tomorrow! Do you think the rest of the code looks ok or could it be coded better? I know it works apart from this problem but I aint sure its logical as I am still learning
  10. Many thanks for all your help!! I was able to fix the above and now I can update whilst using checkboxes. Unfortunately I'm having the following problem with this: // PART 1 $insert_id = $id; $result = mysqli_query($conn, "UPDATE home SET name='$name', active='$active' where id='$id'")or die(mysqli_error($conn)); $result = mysqli_query($conn, "DELETE FROM link_cloud_home WHERE home_id='$id'")or die(mysqli_error($conn)); if(isset($_POST['selector_cloud'])){ $id = $_POST['selector_cloud']; $N = count($id); for($i=0; $i < $N; $i++) { $result = mysqli_query($conn, "SELECT * FROM cloud where id='$id[$i]'"); while($row = mysqli_fetch_array($result)) { echo "<br>"; echo $insert_id; echo "<br>"; echo $row['id']; $sql = "INSERT INTO link_cloud_home (home_id, cloud_id) VALUES ('{$insert_id}', '{$row['id']}');"; $retval = mysqli_query($conn, $sql); if(! $retval ) { die('Could not enter data: ' . mysqli_error($conn)); } } } } // PART 2 $result = mysqli_query($conn, "DELETE FROM link_category_p_home WHERE home_id='$id'")or die(mysqli_error($conn)); if(isset($_POST['selector_cat_p'])){ $id = $_POST['selector_cat_p']; $N = count($id); for($i=0; $i < $N; $i++) { $result = mysqli_query($conn, "SELECT * FROM category_p where id='$id[$i]'"); while($row = mysqli_fetch_array($result)) { echo "<br>"; echo $insert_id; echo "<br>"; echo $row['id']; $sql = "INSERT INTO link_category_p_home (home_id, category_p_id) VALUES ('{$insert_id}', '{$row['id']}');"; $retval = mysqli_query($conn, $sql); if(! $retval ) { die('Could not enter data: ' . mysqli_error($conn)); } } } } The previous code works when I use one of the parts, so for example PART 1 or PART 2. But when I use them together, I receive the following error: Line 44 is as follows: Am I missing something here? Why does it work with one of those 2 parts and why doesn't it work for those 2 parts combined? Any idea? Thanks!
  11. @Ch0cu3r With your code I receive a list of ALL category's, selected from all home_id's which have a category connected to them. @Barand Unfortunately I receive an error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\admin\edit.php on line 119 The code on this line is: while($row=mysqli_fetch_array($query1)){ What am I doing wrong? Many thanks for your help until now, much appreciated!
  12. Hi all, I am fighting with the following issue and was hoping you can give me some insights, as I am totally stuck. What's going on? I have 3 tables, created as follows: table category_p column id column name column type table home column id table link_category_p_home column category_p_id column home_id These tables are linked with eachother, where link_category_p_home is the many-to-many relation table. Now, I want to display for a selected home ID all connected category_p_id's as a checked checkbox. All category_p_id's which are not findable in the link_category_p_home table have to be displayed too, but remain unchecked. I am really trying everything but I just can't figure it out. For most of you it's probably easy stuff but for me it's just like aaahhh. Anyway, here is the code: <table cellpadding="0" cellspacing="0" border="0"> <?php //$query1=mysqli_query($conn, "select * from categorie_p")or die(mysqli_error($conn)); $query1=mysqli_query($conn,"SELECT c.id AS cat_id, c.namr, h.id AS home_id, IF(l.category_p_id IS NULL, 0, 1) AS checked FROM category_p AS c LEFT JOIN link_category_p_home AS l ON c.id = l.category_p_id AND l.home_id = 1234 LEFT JOIN home AS h ON l.home_id = h.id "); while($row=mysqli_fetch_array($query1)){ $categorie_p_id=$row['cat_id']; ?> <tr> <td width="20" style="padding-bottom: 4px"><input name="selector[]" type="checkbox" value="<?php echo $categorie_p_id; ?>" checked></td> <td width="100" style="padding-top:3px; padding-bottom: 1px"><?php echo $row['type'] ?></td> <td width="265" style="padding-top:3px; padding-bottom: 1px"><?php echo $row['cbr_naam'] ?></td> </tr> <?php } ?> </table> Unfortunately this does not work. Let's say there are 10 categories and 1 home ID has 3 categories of it. Then I want to display all categories, but only those 3 checked. Rest remains unchecked. Any help would be appreciated very much!! Words on why my code does not work or why yours does is welcome too .
  13. Hello all, I'm working on a project where I have 3 tables : - test - category - link_category_test In test I have columns id, name. In category I have the columns id, name. In link_test_category I have columns test_id, category_id. When I add an item to table test I can select which categories it will belong too. It can be multiple categories. The connection between those 2 tables is stored in link_test_category. That I get to work. But now I want to be able to edit the categories connected with an item, with checkboxes. This means I'll have a list of all categories and for the categories which are connected with the item, the checkboxes are checked. The rest is unchecked. As soon as I check them they should be added to the many to many relationship table link_test_category, if they are unchecked and before where checked I want them deleted. I have the following code for creating a new item :
×
×
  • 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.