
V
Members-
Posts
307 -
Joined
-
Last visited
Never
Everything posted by V
-
Zanus that's the best solution! Thanks I tried so many other things. I tried putting the $delete_selected var in the sql but it doesn't work. $delete_selected = $connection->real_escape_string($_POST['check_box']); $sql = "DELETE FROM categories WHERE cat_id IN ('$delete_selected')"; I'm using mysqli object oriented so I get errors errors when using mysql_real_escape_string in the query :-\
-
I'm trying to delete items from a table by selecting them via checkboxes. I managed to post all the ids of the checkboxes I filled in the url like this, check_box=154,153,152 etc... and turned that into an array Array ( [0] => 154 [1] => 153 [2] => 152 ) Array using $delete_selected = $connection->real_escape_string($_POST['check_box']); $check_box_array = explode(",", $delete_selected); Now I can't figure out how to put that into $sql = "DELETE FROM categories WHERE cat_id = '$delete_selected'"; it only deletes one. Any ideas?
-
With just CSS I don't think you can achieve that dynamically. You can however paste together all the images in photoshop and just add dynamic post excerpts. Using php and js I would first create an upload page, to upload my images to a "homepage_images" folder and create thumnails of those images to a thumbnails folder and as well insert their path into a DB table. Then you can have for instance a column that's 300px wide, retrieve thumbnail image paths from the db table and generate thumbnails 150x150px and float them left or right in that column. But then you have the wider thumbnails. For those I would use getimagesize() when uploading images to detect if the width of some are particularity wider and their height smaller (wide images usually measure that) and set their thumbnail width to 300px. Also one 300px wide thumbnail should substitute for two 150px thumbnails.. so you'll need to detect if you have a wide thumbnail and set the MYSQL limit -2. Then just add more columns with different properties. That would be my approach, hope it makes some sense..
-
I'm using Jquery to make an editing system. For example I have a list of category names. Each one has an "edit" link next to it. Sports.................edit Technology.........edit Health.................edit When I click edit, the category name is sent to an input (which replaces the plain text) and the edit button switches to "save". Now I can edit the category name. Sports.................edit __________________ | | |Technology | save |_________________ | Health.................edit The problem is.. if I click edit on more than one categories, multiple inputs appear. When I'm editing 1 category I want to disable the edit link for all the others. Is there any way to that in my code? <a href="#" class="edit" id="1">Edit</a> <div class="cat_name1">Sports</div> <input type="text" class="cat_input1"/> <a href="#" class="edit" id="2">Edit</a> <div class="cat_name2">Technology</div> <input type="text" class="cat_input2"/> <a href="#" class="edit" id="3">Edit</a> <div class="cat_name3">Health</div> <input type="text" class="cat_input3"/> (The js is longer but I only added the part I think matters) <script type="text/javascript"> $('.edit').click(function() { var cat_id = $(this).attr("id"); //get unique category ID from .edit div, to edit categories individually var cat_name = $('.cat_name'+cat_id+'').html(); //get html from .cat_name div where cat_id = id retrieved from .edit div $('.cat_input'+cat_id+'').val(cat_name); //add html from cat_name div to input value where cat_id = id retrieved from .edit div }); </script> I tried some if statements (not worthy of posting.. ) with $(.edit).hide(); but nothing happens. I'm just trying to detect .edit divs with different id's than the one I clicked on and disable them but not sure how to achieve that with js..
-
Great! Thanks thorpe! Jquery is starting to make sense
-
You could use CSS and js to get a liquid layout with images. A while back I stumbled across a jquery tutorial that might help you. Check it out http://www.sohtanaka.com/web-design/smart-columns-w-css-jquery/ Nice website btw!
-
I'm using the jquery html() function to add some text into a textarea but it doesn't work with inputs. The working js is, $('.edit').click(function() { var unique_id = $(this).attr("id"); //get unique ID from .edit link var some_text = $('.some_text'+unique_id+'').html(); //get html from class with id=unique_id $('.some_input'+unique_id+'').html(some_text); //add html to textarea with id=unique_id }); And the HTML.. I'm using unique numbers for each group to edit them individually. <a href="#" class="edit" id="1">Edit</a> <div class="some_text1">Content here</div> <textarea class="some_input1"></textarea> <a href="#" class="edit" id="2">Edit</a> <div class="some_text2">Content here</div> <textarea class="some_input2"></textarea> <a href="#" class="edit" id="3">Edit</a> <div class="some_text3">Content here</div> <textarea class="some_input3"></textarea> Everything above works fine with textarea but when I change it to "input type="text" no html is added into the input. For example, <input type="text" class="some_input3" /> Is there any way of passing html() to inputs?
-
I'm not exactly sure what you're trying to achieve. Why are you using a row of <center></center><br> to push the table way down? If you remove all those everything looks fine.
-
I wouldn't inquire for help if I knew... I found a totally different alternative however.
-
I'm struggling to figure this out.. So I looped through a query to get category names from my DB. By each category I have an "edit" link. When I click that, a form input should appear by the category name which I'll use to edit and update it. It looks like this.. Technology..............edit/cancel Health..................... edit/cancel Films........................edit/cancel The js works but when I click "edit", form inputs appear by all the category names instead just the one I clicked on. The code is.. ...DB connect <style> .edit {display:none} </style> ...while loop ..variables <div class="item" id="<?php echo cat_id; ?>"> <?php echo $cat_name; ?> <form name="edit" action="save_category.php" method="post" id="<?php echo $cat_id; ?>"> <input type="hidden" name="cat_id" value="<?php echo $cat_id; ?>" /> <input type="text" name="edit_cat_name" value="<?php echo $cat_name; ?>" /> <input type="submit" name="submit_cat" value="Submit!" /> </form> <div class="edit_button">Edit</div> | <div class="cancel_button">Cancel</div> </div> I wrapped each category name and input in an "item" div and gave each div a unique id via php (with $cat_id). Also, each form as a unique id value (again with $cat_id). I figured if I can determine if the item id = to the form id I can somehow accomplish what I need.. I'm not exactly sure how tho.. :-\ The js is <script type="text/javascript"> $(document).ready(function(){ $('.edit_button').click(function() { var itemID = $('.item').attr("id"); var editID = $('.edit').attr("id"); $('.edit').css({"display":"inline"}); }) $('.cancel_button').click(function() { $('.edit').css({"display":"none"}); }); }); </script> The js successfully picks up the "item" and "edit" ids. Is there a way I can use them to call ".item {display:inline}" only where itemID = editID?
-
Sorry, I originally posted part of this in MYSQL Help, but I was advised to post it here. I'm hoping someone can help me out. I have 2 tables. "categories" and "subcats" (sub categories). I used a JOIN query for both.. SELECT categories.*, subcats.* FROM categories JOIN subcats on (categories.cat_id = subcats.cat_id) ORDER BY cat_name Then I used a while loop to echo all the categories from the "categories" table and their respective sub-categories from the "subcats" table. $sql = "SELECT categories.*, subcats.* FROM categories JOIN subcats on (categories.cat_id = subcats.cat_id) ORDER BY cat_name"; $cats_result = $connection->query($sql) or die(mysqli_error($connection)); while ($row = $cats_result->fetch_assoc()) { $cat_id = $row['cat_id']; $cat_name = $row['cat_name']; $subcat_name = $row['subcat_name']; //should output all categories once and nest their subcategories echo "<strong>".$cat_name."</strong>"; echo "<br />"; echo $subcat_name; echo "<br />"; } No MYSQL errors but unfortunately I get this output.. Technology Computers Technology Gadgets Technology Robots Health Fitness Health Diet What sort of code can use in the loop to echo categories just once instead of multiple times for each topic?
-
Ok, that makes sense! I'll re-post in the correct section. Thanks!
-
Thanks Alex! I was under teh impression that join means when you query 2 tables at once. I used the query you provided but I get the exact output like my query without join.
-
I'm having some trouble echoing a join query. I'm querying two tables: categories and subcats. First I used 2 loops to query all the categories and their respective subcategories (subcats). It works fine, look.. $sql = "SELECT * FROM categories ORDER BY cat_name"; //categories $cats_result = $connection->query($sql) or die(mysqli_error($connection)); while ($row = $cats_result->fetch_assoc()) { $cat_id = $row['cat_id']; $cat_name = $row['cat_name']; echo "<strong>".$cat_name."</strong><br />"; $sql = "SELECT * FROM subcats WHERE cat_id = '$cat_id'"; //subcategories $subcat_result = $connection->query($sql) or die(mysqli_error($connection)); while ($row = $subcat_result->fetch_assoc()) { $subcat_name = $row['subcat_name']; echo $subcat_name; echo "<br />"; }//end subcats while loop }//end category while loop The output is.. Technology Computers Gadgets Robots Health Fitness Diet Now I'm trying to make everything more compact by joining the two tables in one query. $sql = "SELECT categories.*, subcats.* FROM categories, subcats WHERE categories.cat_id = subcats.cat_id ORDER BY cat_name"; $cats_result = $connection->query($sql) or die(mysqli_error($connection)); while ($row = $cats_result->fetch_assoc()) { $cat_id = $row['cat_id']; $cat_name = $row['cat_name']; $subcat_name = $row['subcat_name']; //should output all categories once and nest their subcategories echo "<strong>".$cat_name."</strong>"; echo "<br />"; echo $subcat_name; echo "<br />"; } The output I get is.. Technology Computers Technology Gadgets Technology Robots Health Fitness Health Diet Will I always get this with joins or am I doing something terribly wrong?
-
Sorry, I really appreciate your help, I know about the functions you suggested but I don't understand how to use them in this type of situation. If I first unset $sort, I get immediate undefined variable errors. Then when I click the first sorting option I won't have an array for implode because I'll have just 1 sort in the url. I tried using the two but I get "forbidden" and undefined errors.
-
Hello jesirose, thanks for the reply! Can you please share an example? I'm not sure how to do that.
-
I'm trying to make a "sort by" script to sort posts. I'm hoping someone can help me figure out a small glitch. For some reason I'm getting multiple variables in the url as if the page doesn't reload. :-\ The code is $uri = $_SERVER['REQUEST_URI']; //gets url of current page <li><a href="<?php echo $uri; ?>&sort=New">Most Recent</a></li> <li><a href="<?php echo $uri; ?>&sort=Popular">Popular</a></li> <li><a href="<?php echo $uri; ?>&sort=Discussed">Discussed</a></li> if for example I choose to sort by "Popular" the url output will be http://localhost/mysite/single_cat.php?cat=57&sort=Popular but then when I click let's say "Discussed" a new sort variable is added with the existing one. http://localhost/mysite/single_cat.php?cat=57&sort=Popular&sort=Discussed and below I'm querying posts based on the sort variable.. for example.. if ($sort == "Popular") { //db connection $sql = "SELECT * FROM posts WHERE cat_id = '$cat' AND views >= 2 ORDER BY views DESC, post_date DESC"; //while loop, etc }//end else if I'm not sure what I did wrong.. How do I get just one "?sort=" url variable?
-
I'm not seeing that. Perhaps you already fixed it.
-
rascle, thanks for the suggestion! I was considering that as well, hopefully it will be secure. @msaz87, good point. @smonkcaptain,thanks for sharing the code. The header location seems like a good technique. Maybe I can also further protect the admin pages with another password in addition to the user password.
-
Brilliant! Thanks wildteen88! It's work perfectly now
-
After reading some Jquery documentation I tried to implement something for my site. If a link's "id" and "name" have equal values the background color of the link's class should change to green otherwise red. <script type="text/javascript"> $(function() { var ID = $(".color_test").attr("id"); var name = $(".color_test").attr("name"); if (ID==name) { $('.color_test').css({"background":"green"}); } if (ID!==name) { $('.color_test').css({"background":"red"}); } }); </script> The HTML is dynamic but I made a simple example <a href class="color_test" id="1" name="1">Should be green</a> <a href class="color_test" id="3" name="4">Should be red</a> <a href class="color_test" id="8" name="8">Should be green</a> and the css .color_test { display:block; padding:10px; } What happens is.. if "id" and "name" in the first link are equal, all the links become green even if some don't have equal values. :-\ And so if the first link doesn't have equal values they all become red. It seems that it's just picking up the data from the first link rather than each one individually. Can someone please help me out with this?
-
Hey all, I will really appreciate any sort of advice! I'm making a site that will have users. I created some setting pages for administrating the site, like adding new entries, updating, deleting.. and I'm also making a page where users with "writer" privileges can just post entries. I'm not sure what's the standard way to protect those pages or use permissions. What sort of solutions do you use for something like this using php and mysql?
-
jcbones thanks so much for the reply! I did some reading about DISTINCT and used it but I get the same effect.
-
Hello. This tutorial should answer your question http://www.echoecho.com/csslists.htm