Jump to content

gadgetster

Members
  • Posts

    16
  • Joined

  • Last visited

Everything posted by gadgetster

  1. Clearly you didn't read my original post. I don't need a ready chat that I have to pay for license. That is why I started my own code and trying to learn too.
  2. It doesn move it down to where I want it but won't open back. I wrote the code myself but I am not good at jquery
  3. The open sources I found don't really do exactly what I am looking for and I wouldn't be able to use them for my business
  4. I managed to create the chat windows open uniquely depending on whatever user is clicked but I cannot send messages on any chat window except the first one. I am trying to achieve this: Is there any tutorial on how to achieve exactly that ^ ? Right now the windows minimize but don't open back if I "un-minimize" it. The slide in/out only works for the first chat windows, the rest open weird fold-out from the top. Here is what I have so far: <script> //CHAT SYSTEM function chatWith(id, status, username){ $("#chats").append('<div class="chat_window" id="chat_'+id+'"><div class="chat_top"><span class="chat_username">'+status+username+'</span><span class="chat_x"><a href="javascript:void(0)" onclick="minChat('+id+')">-</a> <a href="javascript:void(0)" onclick="closeChat('+id+')">X</a> </span> </div> <div class="chat_content"></div> <form method="post" name="chat" action=""> <textarea class="chat_text" maxlength="200" name="chat_text" id="chat_text_'+id+'" placeholder="Start typing..."></textarea> </form> </div></dv>'); $("#chat_"+id).slideToggle("fast"); } function minChat(id){ $("#chat_"+id).animate({'margin-bottom':'-18em'}); } function closeChat(id){ $("#chat_"+id).slideToggle("fast"); } //send messages var user_id = '<?php echo $session_user_id;?>'; var auto_refresh = setInterval(function () { var b = $("#chat_"+user_id+":last").attr("id"); $.getJSON("chat.php?user_id="+user_id,function(data){ $.each(data.posts, function(i,data) { if(b != data.id) { var div_data="<span id='"+data.id+"'>"+data.user_id+": "+data.msg+"</span>"; $(div_data).appendTo("#chat_"+user_id); } }); }); }, 2000); $(document).ready(function(){ $(document).keypress(function(e) { if(e.which == 13) { var boxval = $(".chat_text").val(); var user_id = '<?php echo $session_user_id;?>'; var dataString = 'user_id='+ user_id + '&msg=' + boxval; if(boxval.length > 0) { $.ajax({ type: "POST", url: "chat.php", data: dataString, cache: false, success: function(html){ $(".chat_content").append(html); $(".chat_text").val(''); $(".chat_text").focus(); $(".chat_content").animate({scrollTop: $(".chat_text").offset().top}, 500); } }); } return false; } }); }); </script> this is my chat.php if($_POST){ $user_id = $_POST['user_id']; $msg = $_POST['msg']; mysql_query("INSERT INTO chat(user_id, msg) VALUES ('$user_id', '$msg')"); $chat_results = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE user_id='".$user_id."' LIMIT 1")); echo '<span style="font-size:0.9em;font-weight:bold;">'.$chat_results['username'].'</span>: <span style="font-size:0.9em;">'.$msg.'</span><br>'; } if($_GET['user_id']){ $user_id=$_GET['user_id']; $row=mysql_fetch_array(mysql_query("SELECT * FROM chat order by id desc limit 1")); $user_idx = $row['user_id']; $id = $row['id']; $msg = $row['msg']; if($user_idx != $user_id){ echo '{"posts": [{ "id":"'.$id.'", "user_id":"'.$user_idx.'", "msg":"'.$msg.'" },]}'; } } and the div it all opens on: <div id="chats"> </div> Will really appreciate any help, been breaking my head on this for weeks now!
  5. i want the user to be able to upload multiple images. Is there a way to store the paths of say 3 images under one field in the database? I mean having all of the image paths in the same column like so Images | date images/file1.jpg, images/file2.jpg, images/file3.jpg | Thursday... <ul id="image_upload"> <input type="file" name="image[]"><a href="#" id="add_more">Add more</a> <br> <script> $(document).ready(function(){ $('#add_more').click(function(){ var current_count = $('input[type="file"]').length; var next_count = current_count + 1; $('#image_upload').append('<br><input type="file" name="image[' + next_count + ']"><br>'); }); }); </script> </ul> <br><br> then i check the files with php and attempt to insert to the database if (!empty($_FILES['image'])){ for ($i = 0; isset($_FILES['image']['name'][$i]); $i++) { $allowed = array('jpg', 'jpeg', 'png', 'bmp', 'tiff', 'gif'); $fileName = $_FILES['image']['name'][$i]; $fileSize = $_FILES['image']['size'][$i]; $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); if (!in_array($fileExt, $allowed)) { $errors[] = 'Incorrect file type. Only allowed: ' . implode(', ', $allowed) . ''; } if ($fileSize > 2097152) { $errors[] = "$fileName exceeds the maximum file size of 2 MB"; } } for ($i = 0; isset($_FILES['image']['name'][$i]); $i++) { $fileBase = basename($_FILES['image']['name'][$i]); $fileName = pathinfo($fileBase, PATHINFO_FILENAME); $fileExt = pathinfo($fileBase, PATHINFO_EXTENSION); $fileTmp = $_FILES['image']['tmp_name'][$i]; $fileDst = 'images/images/'.basename($_FILES['image']['name'][$i]); for ($j = 0; file_exists($fileDst); $j++) { $fileDst = "images/images/$fileName-$j.$fileExt"; } if (move_uploaded_file($fileTmp, $fileDst)) { $output[$fileBase] = "Stored $fileBase OK"; } } } this code only uploads the first image to the temp folder and only one path into the database
  6. I will switch to date instead of id when i have more posts and i am done testing.. right now i am trying many things so the date gets messed up from time to time. when you say {"latest":123,"html":"whatever it returns now"}, how exactly should i do it? and the id is from $_GET['id'] so it takes it from the url
  7. I want to display 5 items and when the user clicks the 'load more' button, 5 more items will be pulled out from the database. I have my items being retrieved like so: $res = mysql_query("SELECT * FROM `posts` ORDER BY `id` DESC LIMIT 5") or die(mysql_error()); if(mysql_num_rows($res) > 0){ while($row = mysql_fetch_assoc($res)){ $id = $row['id']; $user_id = $row['user_id']; then i have the ajax code and the button: <script type="text/javascript"> $(document).ready(function(){ $(".load_more").click(function (){ $('.load_more').html('<img src="images/ajax-loader.gif" />'); $.ajax({ url: "loadmore.php?lastid=" + ("<?php echo $id; ?>"), success: function(html){ if(html){ $(".main_page").append(html); $('.load_more').html('Load More'); }else{ $('.load_more').replaceWith('<center>No more posts to show.</center>'); } } }); }); }); </script> <button class="load_more">Load More</button> And finally the loadmore.php file that is being called when the button is clicked: $res17 = mysql_query("SELECT * FROM `posts` WHERE id < '".addslashes($_GET['lastid'])."' LIMIT 0, 25 LIMIT 10"); while($row17 = mysql_fetch_assoc($res17)){ $id = $row17['id']; $user_id = $row17['user_id']; how do i call the correct id? i know that url: "loadmore.php?lastid=" + ("<?php echo $id; ?>"), is probably wrong but not sure how to fix it
  8. somehow with your comment, i managed to find the mistake i made. when submitting the ad, i wasn't telling it to add the image to the database thanks for your help!
  9. im trying to upload a cover image for a posting and it seems to go through but on the database i see one line that shows the path with all other rows empty and another column with all the rows filled out except the image one I have a function that adds the image when called function add_cover($id, $file_temp, $file_extn){ $file_path = 'images/cover/' . substr(md5(time()), 0, 10) . '.' . $file_extn; move_uploaded_file($file_temp, $file_path); mysql_query("UPDATE `classifieds` SET `cover` = '" . mysql_real_escape_string($file_path) . "' WHERE `id` = " . (int)$id); } and the the actual php page if (isset($_FILES['cover']) === true){ $allowed = array('jpg', 'jpeg', 'gif', 'png'); $file_name = $_FILES['cover']['name']; $file_size = getimagesize($_FILES['cover']['name']); $file_extn = strtolower(end(explode('.', $file_name))); $file_temp = $_FILES['cover']['tmp_name']; if(in_array($file_extn, $allowed) === true){ add_cover($_SESSION['id'], $file_temp, $file_extn); }else{ $errors[] = 'Incorrect file type. Only allowed: ' . implode(', ', $allowed) . ''; } } it won't work. i know it's probably the something to do with the way i am trying to get $_SESSION['id'] to match the ad id but i don't know how else to call that ad... any help is appreciated! ps. this is what happens when i use mysql_query("INSERT INTO `classifieds` (`cover`) VALUES ('$file_path')"); instead of the add_cover function:
  10. well, i need a classified ads code and I have minor knowledge in PHP and no time to learn all the database stuff so I figured I'll ask here. But wow this is a one stuck up forum. Hopefully someone can be more helpful than these two robots above
  11. ok, i fixed that and i get the following error: syntax error, unexpected 'list' (T_LIST), expecting identifier (T_STRING) in C:\wamp\www\test\models\category.php on line 43 here is my models/category.php code: <?php class Category { function __construct() { // for this tutorial there will be nothing inside this method // in the real app you could possibly add some initialization } function add($name) { $this->filter($name); $q="INSERT INTO categories (name) VALUES (\"$name\")"; mysql_query($q) or die(mysql_error()); } function edit($name, $id) { $this->filter($name); // add some basic security if(!is_numeric($id)) exit; $q="UPDATE categories SET name=\"$name\" WHERE id='$id'"; mysql_query($q); } // category name allows only alphanumeric private function filter($name) { $name=preg_replace("/\W/","",$name); return $name; } function delete($id) { if(!is_numeric($id)) exit; $q="DELETE FROM categories WHERE id='$id'"; mysql_query($q); } // method to list the categories for admin edit/delete function list() { $q="SELECT * FROM categories ORDER BY name"; $result=mysql_query($q); $cats=array(); while($cat=mysql_fetch_array($result)) $cats[]=$cat; return $cats; } // method to return categories along with number of ads in them function list_count() { $q="SELECT COUNT(tA.id) as classifieds, tC.name as name, tC.id as id FROM categories tC LEFT JOIN classifieds tA ON tA.category_id=tC.id ORDER BY tC.name"; $result=mysql_query($q); $cats=array(); while($cat=mysql_fetch_array($result)) $cats[]=$cat; return $cats; } // method to return full category data for a single category function select($id) { if(!is_numeric($id)) exit; $q="SELECT * FROM categories WHERE id='$id'"; $category=mysql_fetch_array(mysql_query($q)); return $category; } } ?>
  12. i posted it in my first post, i copied every code from: http://blog.calendarscripts.info/phpmysql-tutorial-classifieds-software-in-1-hour/ it is the exact same and i do not know why the error appears
  13. it tells me there is an error in line 2 of category.php, there is supposedly an extra ' ( ', but when i check that line it is just a class function and nothing seems to be wrong with it ps. maybe there is a better php classified ads tutorial around?
  14. I followed this tutorial: http://blog.calendarscripts.info/phpmysql-tutorial-classifieds-software-in-1-hour/ and i keep getting an error. i am simply trying to get a classified ads service going i attached the php files and folders any help is appreciated! test.zip
×
×
  • 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.