Jump to content

lasha

Members
  • Posts

    45
  • Joined

  • Last visited

Everything posted by lasha

  1. OKay thanks you answer dome my job perfectly.... right after if (isset($_POST['category'])) { i made delete query $sql2 = "DELETE FROM info_cats WHERE info_id = '$caturi'"; mysql_query($sql2); and its works... thank you very much ))!!!!!!
  2. Okey is't my code. and see attachment... there is categories, when i select categories it inserts good but may be there is already category selected in same id its editing... i want not to have dublicates... Thanks <?php if (isset($name) && isset($sur) && isset($id)) { $result = mysql_query ("UPDATE info SET name='$name', sur='$sur' WHERE id='$id'"); if ($result == 'true') { $caturi = $id; } else {echo "<p>Not Updated! :|</p>";} } else { echo "<p>Enter info completely...</p>"; } if (isset($_POST['category'])) { foreach ($_POST['category'] as $cat) { $values[] = sprintf ("(%d, '%s')", intval($cat), mysql_real_escape_string($caturi)); } $sql = "INSERT INTO info_cats (cat_id, info_id) VALUES " . join(',', $values); mysql_query($sql); echo $sql; } ?>
  3. Thanks for reply, okey i understend that but how to make it when i have join(values)?
  4. Hello Please, need some help in "ON DUPLICATE KEY UPDATE" Code below does not do the thing $sql = "INSERT INTO info_cats (cat_id, info_id) VALUES " . join(',', $values) . "ON DUPLICATE KEY UPDATE (cat_id, info_id) =" . join(',', $values); Thanks in advice
  5. Many thanks to you it works perfectly... I just start studiing and even dont know what is best book or video to learn php... I know that this forum is for more educated php programmers, but it was for me a big riddle to write this mini program by someones help... I will be happy if you advice literature for programming... Thank you again lasha P.S. in the end of program was missing variable $checked... $checkboxes .= "<input type='checkbox' name='category[]' value='$id'$checked /> $cat<br />";
  6. Okey i stuck with this: <?php include ("db.php"); if (isset($_GET['id'])) {$id = $_GET['id'];} if (!isset($id)) { $result = mysql_query("SELECT id, name, sur FROM info"); $myrow = mysql_fetch_array($result); do { printf ("<p style='float:left; margin-left:6px;'> <a href='edit.php?id=%s'>%s</a> |</p>",$myrow["id"],$myrow["name"]); } while ($myrow = mysql_fetch_array($result)); } else { $result2 = mysql_query("SELECT * FROM info WHERE id=$id"); $myrow2 = mysql_fetch_array($result2); $sql = "SELECT * FROM category, info, info_cats WHERE info.id = info_cats.info_id AND category.cat_id = info_cats.cat_id AND id='$id'"; $res = mysql_query($sql) or die(mysql_error()); while (list($id, $cat) = mysql_fetch_array($res)) { if (in_array($id, $res)) $checked = ' checked="checked"'; else $checked = ''; $checkboxes .= "<input type='checkbox' name='category[]' value='$id'$checked /> $cat<br />"; } print <<<HERE <form method = 'post' action = 'update.php' > Name: <input type='text' name='name' value="$myrow2[name]" size='50' /><br /> Surname: <input type='text' name='sur' value="$myrow2[sur]" size='50' /><br /> Categories:<br /> $checkboxes <input type='submit' name='btnSubmit' value='Submit' /> </form> HERE; } ?> Output is on picture... Please say to me what part is wrong???
  7. Okay, I give up, maybe i missed something... I just dont understed properly php programming and thats why cant figur code out... Christian said that i must learn JOIN query and i understend this part, but in my code there is no JOIN in use... I posted my code above which is now in use for my "editing"... If you can just say what i must read to do this program like it have to be...? P.S. i'm sorry for my english, may be i just did explain everything wrong way...
  8. Okey i did it and may be wrong becouse there is no more error but now all checkboxes ar checked... I updated like that while (list($id, $cat) = mysql_fetch_row($res)) { $usercats = array($id, $cat); //Is this wrong array? if (in_array($cat, $usercats)) $checked = ' checked="checked"'; else $checked = ''; $checkboxes .= "<input type='checkbox' name='category[]' value='$id'$checked /> $cat<br />"; }
  9. Thanks Lemmin it looks logic ) But it returns error: Warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\Program Files\VertrigoServ\www\test\edit.php on line 86 I tryed but i can't understend why...
  10. Thank you Christian, I read MYSQL Join Statements, understend and now i know how to display data with JOIN, but here is a problem anyway... I dont know how to make checkbox checked (in edit panel, which i described on picture) if there is category record on database for certain info ($id)... If you can help me to figure out what i can do with my code to get this program as was in idea, it will be gread Thank you again for attention
  11. Hello guys I have a small problem and please help to resolve this. I have associated categories in the database. During the edit, i need, that categories which were checked when first somebody added his/her info that categories to be selected... In my attached picture is described what i want to do. Thanks for advice... And here is my code <?php include ("db.php"); if (isset($_GET['id'])) {$id = $_GET['id'];} if (!isset($id)) { $result = mysql_query("SELECT id, name, sur FROM info"); $myrow = mysql_fetch_array($result); do { printf ("<p style='float:left; margin-left:6px;'> <a href='edit.php?id=%s'>%s</a> |</p>",$myrow["id"],$myrow["name"]); } while ($myrow = mysql_fetch_array($result)); } else { $result2 = mysql_query("SELECT * FROM info WHERE id=$id"); $myrow2 = mysql_fetch_array($result2); $sql = "SELECT cat_id, cat_name FROM category"; $res = mysql_query($sql) or die(mysql_error()); $checkboxes = ''; while (list($id, $cat) = mysql_fetch_row($res)) { $checkboxes .= "<input type='checkbox' name='category[]' value='$id' /> $cat<br />"; } print <<<HERE <form method = 'post' action = 'update.php' > Name: <input type='text' name='name' value="$myrow2[name]" size='50' /><br /> Surname: <input type='text' name='sur' value="$myrow2[sur]" size='50' /><br /> Categories:<br /> $checkboxes <input type='submit' name='btnSubmit' value='Submit' /> </form> HERE; } ?>
  12. Alright, thank all of you for help... Psycho, Barand you gave me a lot of knowledge in PHP mySQL programming, of course this was not perfect codes but it was "perfect help"... I know that, this forum is not for to give someone orders, i just wanted help and i get it... You helped not only me, this thread will see many people who needs help in coding... I was looking for help in google but this was everywhere unsolved problem... So thank you again and there is code that i performed with your Indications and this works perfectly (if something is not good written correct me please): P.S. I am not a English speaker, sorry for that... Tables Table category --> user_id | cat_id Table info --> id | name | sur Table info_cats --> info_id | cat_id This is form.php <?php include ("db.php"); $sql = "SELECT cat_id, cat_name FROM category"; $res = mysql_query($sql) or die(mysql_error()); $checkboxes = ''; while (list($id, $cat) = mysql_fetch_row($res)) { $checkboxes .= "<input type='checkbox' name='category[]' value='$id' /> $cat<br />"; } ?> <form method = 'post' action = 'process.php' > Name: <input type='text' name='name' size='50' /><br /> Surname: <input type='text' name='sur' size='50' /><br /> Categories:<br /> <?php echo $checkboxes ?> <input type='submit' name='btnSubmit' value='Submit' /> </form> This is process.php which Produces inserting in DB <?php include ("db.php"); if (isset($name) && isset($sur)) { $result = mysql_query ("INSERT INTO info (name, sur) VALUES ('$name','$sur')"); if ($result == 'true') { $caturi = mysql_insert_id(); } else {echo "<p>Your actions are not completed!</p>";} } else { echo "<p>Enter information completely!</p>"; } if (isset($_POST['category'])) { foreach ($_POST['category'] as $cat) { $values[] = sprintf ("(%d, '%s')", intval($cat), mysql_real_escape_string($caturi)); } $sql = "INSERT INTO info_cats (cat_id, info_id) VALUES " . join(',', $values); mysql_query($sql); } ?> And last one for display from db by categories <?php include ("db.php"); $result = mysql_query(" SELECT info.name, info.sur, category.cat_name FROM info LEFT JOIN info_cats ON info.id = info_cats.info_id LEFT JOIN category ON info_cats.cat_id = category.cat_id WHERE cat_name='category 3'",$db); if (!$result) { echo "<p>The operation unsuccessful ... Please contact the administrator by e-mail: lasha.wm@gmail.com <br> <strong>Error:</strong></p>"; exit(mysql_error()); } if(mysql_num_rows($result) > 0) { $myrow = mysql_fetch_array($result); do { printf ("%s %s | %s<br>\n",$myrow["name"],$myrow["sur"],$myrow["cat_name"]); } while ($myrow = mysql_fetch_array($result)); } else { echo "<p>Information not found...</p>"; exit(); } ?>
  13. :'( 2 days i am trying to make it but always error If it is not problem for you to show me how do it please :-\
  14. Ok i see that i need something like that, but how to store ids of profile and categories in this new table ... ? And even than i need retrieve it from database... can you show me please? user_id | cat_id 1 2 2 1 2 3 3 1 3 2 3 3
  15. Thanks for reply Psycho, I thought make such but I cant write code, i dont know how (( May be have some example?
  16. Hello, I tried to write a script for a long time, but unfortunately failed ... Please Help me, I think it should not be difficult but i can't reach a solution... I have a profile that can belong to several categories ... How can we do so that this selected categories placed in one cell of mySQL db? Please help me in this problem to find a solution... Best wishes, Lasha
  17. Oh thank you very much... it is exactly what i wonder to do :DDD Finally my problem is solved... Not enough words to thank you Best wishes, Lasha
  18. Heeey Thank you for reply... I asked for this in many forum and only you answered i'm very pleased Okey, I'm new with php, i wrote this code and dont know how to realise plz help me with this too... here is a code: <?php if (isset($name) && isset($cat1) && isset($cat2) && isset($cat3) && isset($cat4) && isset($cat5)) { $result = mysql_query ("INSERT INTO info (name,cat) VALUES ('$name','$cat')"); if ($result == 'true') {echo "<p class='close'>information added... <a href=" . "javascript:CloseWindow()" . ">Close This Window</a></p>";} else {echo "<p>added! :|</p>";} } else { echo "<p>Enter more information...</p>"; } ?> i don't know... ma be i am going on wrong way...
  19. Hello, I have problem and i dont know how to solve it... may be you can help me Okey i have form which include one textfield named "name" in which user must enter his/her name and 5 category checkbox cat1, cat2, cat3, cat4, cat5,. now I want, how many categories (checkbox) are selected so many same name records to be inserted in my database... Sorry for my english, i think i explained everithing normally... Thank you... ! With respect, Lasha
×
×
  • 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.