PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи

Страниц (1): [1]

> Найдено сообщений: 8
Cruzex Отправлено: 16 Июля, 2011 - 19:34:06 • Тема: Изменение шаблона • Форум: CMS и фреймворки

Ответов: 0
Просмотров: 827
Здравствуйте,
Подскажите, у меня есть движок, в котором все выводится через echo, и так же есть 2 разных шаблона, я бы хотел сделать дизайн чузер. Каким методом это проще и удобнее сделать? tpl, smarty? И приведите пожалуйста пример как сделать, просто понятия не имею, как это делается.
Cruzex Отправлено: 11 Мая, 2011 - 21:34:08 • Тема: Чат • Форум: JavaScript & VBScript

Ответов: 1
Просмотров: 1883
Если кто-то может помочь - возможна оплата.
ICQ:524676
Cruzex Отправлено: 11 Мая, 2011 - 17:06:55 • Тема: Чат • Форум: JavaScript & VBScript

Ответов: 1
Просмотров: 1883
Здравствуйте, у меня есть чат на сайте (xml + php + java), я хочу ограничить кол-во сообщений выводимых в чат. К примеру 15, но честно говоря не понимаю как это сделать, подскажите пожалуйста.
java:
CODE (javascript):
скопировать код в буфер обмена
  1.  
  2. <script language="JavaScript" type="text/javascript">
  3.                         var sendReq = getXmlHttpRequestObject();
  4.                         var receiveReq = getXmlHttpRequestObject();
  5.                         var lastMessage = 0;
  6.                         var mTimer;
  7.                         //Function for initializating the page.
  8.                         function startChat() {
  9.                                 //Set the focus to the Message Box.
  10.                                 document.getElementById('txt_message').focus();
  11.                                 //Start Recieving Messages.
  12.                                 getChatText();
  13.                         }              
  14.                         //Gets the browser specific XmlHttpRequest Object
  15.                         function getXmlHttpRequestObject() {
  16.                                 if (window.XMLHttpRequest) {
  17.                                         return new XMLHttpRequest();
  18.                                 } else if(window.ActiveXObject) {
  19.                                         return new ActiveXObject("Microsoft.XMLHTTP");
  20.                                 } else {
  21.                                         document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Consider upgrading your browser.';
  22.                                 }
  23.                         }
  24.                        
  25.                         //Gets the current messages from the server
  26.                         function getChatText() {
  27.                                 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
  28.                                         receiveReq.open("GET", 'getChat.php?chat=<?=$id?>&last=' + lastMessage, true);
  29.                                         receiveReq.onreadystatechange = handleReceiveChat;
  30.                                         receiveReq.send(null);
  31.                                 }                      
  32.                         }
  33.                         //Add a message to the chat server.
  34.                         function sendChatText() {
  35.                                 if(document.getElementById('txt_message').value == '') {
  36.                                         alert("You have not entered a message");
  37.                                         return;
  38.                                 }
  39.                                 if (sendReq.readyState == 4 || sendReq.readyState == 0) {
  40.                                         sendReq.open("POST", 'getChat.php?chat=<?=$id?>&last=' + lastMessage, true);
  41.                                         sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  42.                                         sendReq.onreadystatechange = handleSendChat;
  43.                                         var param = 'message=' + document.getElementById('txt_message').value;
  44.                                         param += '&name=' + document.getElementById('who').value;
  45.                                         param += '&gameid=' + document.getElementById('gameid').value;
  46.                                         sendReq.send(param);
  47.                                         document.getElementById('txt_message').value = '';
  48.                                 }                                                      
  49.                         }
  50.                         //When our message has been sent, update our page.
  51.                         function handleSendChat() {
  52.                                 //Clear out the existing timer so we don't have
  53.                                 //multiple timer instances running.
  54.                                 clearInterval(mTimer);
  55.                                 getChatText();
  56.                         }
  57.                         //Function for handling the return of chat text
  58.                         function handleReceiveChat() {
  59.                                 if (receiveReq.readyState == 4) {
  60.                                         var chat_div = document.getElementById('div_chat');
  61.                                         var xmldoc = receiveReq.responseXML;
  62.                                         var message_nodes = xmldoc.getElementsByTagName("message");
  63.                                         var n_messages = message_nodes.length
  64.                                         for (i = 0; i < n_messages; i++) {
  65.                                                 var user_node = message_nodes[i].getElementsByTagName("user");
  66.                                                 var text_node = message_nodes[i].getElementsByTagName("text");
  67.                                                 var time_node = message_nodes[i].getElementsByTagName("time");
  68.                                                 var chat_node = message_nodes[i].getElementsByTagName("chatid");
  69.                                                 chat_div.innerHTML += '<font color="yellow">' + user_node[0].firstChild.nodeValue + '</font>&nbsp;';
  70.                                                 chat_div.innerHTML += '<font class="chat_time">' + time_node[0].firstChild.nodeValue + '</font><br />';
  71.                                                 chat_div.innerHTML += text_node[0].firstChild.nodeValue + '<br />';
  72.                                                 chat_div.scrollTop = chat_div.scrollHeight;
  73.                                                 lastMessage = (message_nodes[i].getAttribute('id'));
  74.                                         }
  75.                                         mTimer = setTimeout('getChatText();',2000); //Refresh our chat in 2 seconds
  76.                                 }
  77.                         }
  78.                         //This functions handles when the user presses enter.  Instead of submitting the form, we
  79.                         //send a new message to the server and return false.
  80.                         function blockSubmit() {
  81.                                 sendChatText();
  82.                                 return false;
  83.                         }
  84.                         //This cleans out the database so we can start a new chat session.
  85.                         function resetChat() {
  86.                                 if (sendReq.readyState == 4 || sendReq.readyState == 0) {
  87.                                         sendReq.open("POST", 'getChat.php?chat=<?php=$id ?>&last=' + lastMessage, true);
  88.                                         sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  89.                                         sendReq.onreadystatechange = handleResetChat;
  90.                                         var param = 'action=reset';
  91.                                         sendReq.send(param);
  92.                                         document.getElementById('txt_message').value = '';
  93.                                 }                                                      
  94.                         }
  95.                         //This function handles the response after the page has been refreshed.
  96.                         function handleResetChat() {
  97.                                 document.getElementById('div_chat').innerHTML = '';
  98.                                 getChatText();
  99.                         }      
  100.                 </script>


php:

PHP:
скопировать код в буфер обмена
  1. <div id="chatbox">             
  2.                  <div id="div_chat"></div>
  3.                   <form id="frmmain" name="frmmain" onsubmit="return blockSubmit();">
  4.                          <input type="hidden" name="btn_get_chat" id="btn_get_chat" value="Refresh Chat" onclick="javascript:getChatText();" />
  5.                          <input type="hidden" name="btn_reset_chat" id="btn_reset_chat" value="Reset Chat" onclick="javascript:resetChat();" /><?if($vbulletin->userinfo['userid']!=0)
  6. {
  7. $checkban = mysql_query("SELECT * FROM cs_bio WHERE username = '$me'");
  8. while($chatban = mysql_fetch_array($checkban)) {
  9. $canchat = $chatban['chat'];
  10. if($canchat != 1)
  11. {      
  12. echo "<input type=\"text\" id=\"txt_message\" size=\"65\" name=\"txt_message\" value=\"You Have Been Banned From Using The Chat Box\"/>";              
  13. }      
  14. else
  15. {
  16. ?>
  17.                         <input type="text" id="txt_message" name="txt_message" size="65"/>
  18.                         <input type="hidden" id="who" name="name" value="<?=$me?>" />
  19.                         <input type="hidden" id="gameid" name="gameid" value="<?=$id?>" />                     
  20.                         <input type="button" name="btn_send_chat" id="btn_send_chat" value="Send" onclick="javascript:sendChatText();" />
  21.                 </form>
  22. <?
  23.   }
  24.  }
  25. }
  26. else
  27. {
  28. echo "<input type=\"text\" id=\"txt_message\" name=\"txt_message\" value=\"You Must Be Logged In To Send Messages\"/>";        
  29. }
  30. ?>             
  31.                 </div>


Ну и сам getchat.php:
PHP:
скопировать код в буфер обмена
  1.  
  2. <?PHP
  3. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  4. header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
  5. header("Cache-Control: no-cache, must-revalidate" );
  6. header("Pragma: no-cache" );
  7. header("Content-Type: text/xml; charset=utf-8");
  8.  
  9.  
  10. require "database.php";
  11.  
  12. //Check to see if a message was sent.
  13. if(isset($_POST['message']) && $_POST['message'] != '') {
  14.         $sql = "INSERT INTO cs_messages(chat_id, user_id, user_name, message, post_time) VALUES ('" . db_input($_POST['gameid']) . "'
  15.         , '".$vbulletin->userinfo['userid']."', '" . db_input($_POST['name']) .
  16.                         "', '" . db_input($_POST['message']) . "', NOW())";
  17.         db_query($sql);
  18. }
  19. //Check to see if a reset request was sent.
  20. if(isset($_POST['action']) && $_POST['action'] == 'reset') {$sql = "DELETE FROM cs_messages WHERE chat_id = " . db_input($_GET['chat']);
  21.         db_query($sql);
  22. }
  23.  
  24. //Create the XML response.
  25. $xml = '<?xml version="1.0" ?><root>';
  26. //Check to ensure the user is in a chat room.
  27. if(!isset($_GET['chat'])) {
  28.         $xml .='Your are not currently in a chat session.  <a href="">Enter a chat session here</a>';
  29.         $xml .= '<message id="0">';
  30.         $xml .= '<user>Admin</user>';
  31.         $xml .= '<text>Your are not currently in a chat session.  <a href="">Enter a chat session here</a></text>';
  32.         $xml .= '<time>' . date('h:i') . '</time>';
  33.         $xml .= '</message>';
  34. } else {
  35.         $last = (isset($_GET['last']) && $_GET['last'] != '') ? $_GET['last'] : 0;
  36.         $sql = "SELECT message_id, user_name, message, date_format(post_time, '%h:%i') as post_time FROM cs_messages WHERE chat_id = ".db_input($_GET['chat'])." AND message_id > ".$last."";
  37.         $message_query = db_query($sql);
  38.         //Loop through each message and create an XML message node for each.
  39.         while($message_array = db_fetch_array($message_query)) {
  40.                 $xml .= '<message id="' . $message_array['message_id'] . '">';
  41.                 $xml .= '<user>' . htmlspecialchars($message_array['user_name']) . '</user>';
  42.                 $xml .= '<text>' . stripslashes($message_array['message']) . '</text>';
  43.                 $xml .= '<time>' . $message_array['post_time'] . '</time>';
  44.                 $xml .= '<gameid>' . $message_array['chat_id'] . '</gameid>';
  45.                 $xml .= '</message>';
  46.         }
  47. }
  48. $xml .= '</root>';
  49. echo $xml;
  50.  
  51. ?>
Cruzex Отправлено: 03 Мая, 2011 - 20:56:25 • Тема: Выборка • Форум: SQL и Архитектура БД

Ответов: 10
Просмотров: 95
Цитата:
PHP:
скопировать код в буфер обмена
  1.  $mapsrandom = mysql_query("SELECT * FROM cs_maps ORDER BY id DESC LIMIT 1");
  2. while($mapsrandom = mysql_fetch_array($mapsrandom)) {
  3. $mapsrandomidlast = $mapsrandom['id'];
  4. }
  5. //$mapsrandomidlast=столько, сколько нужно выбрать записей
  6. $result=mysql_query("SELECT * FROM `cs_maps` ORDER BY RAND() LIMIT $mapsrandomidlast");
  7. $rgResult=mysql_fetch_array($result);

Выдает Resource id #55 , даже если лимит 3 поставить

Так что с этим? Примерно 10-100 записей
Cruzex Отправлено: 03 Мая, 2011 - 20:29:07 • Тема: Выборка • Форум: SQL и Архитектура БД

Ответов: 10
Просмотров: 95
Записей будет не много, но я не имею понятия сколько и я не смогу изменять код в php. Мне нужно что-то оптимальное
Cruzex Отправлено: 03 Мая, 2011 - 20:07:13 • Тема: Выборка • Форум: SQL и Архитектура БД

Ответов: 10
Просмотров: 95
PHP:
скопировать код в буфер обмена
  1.  $mapsrandom = mysql_query("SELECT * FROM cs_maps ORDER BY id DESC LIMIT 1");
  2. while($mapsrandom = mysql_fetch_array($mapsrandom)) {
  3. $mapsrandomidlast = $mapsrandom['id'];
  4. }
  5. //$mapsrandomidlast=столько, сколько нужно выбрать записей
  6. $result=mysql_query("SELECT * FROM `cs_maps` ORDER BY RAND() LIMIT $mapsrandomidlast");
  7. $rgResult=mysql_fetch_array($result);

Выдает Resource id #55 , даже если лимит 3 поставить
Cruzex Отправлено: 03 Мая, 2011 - 19:23:07 • Тема: Выборка • Форум: SQL и Архитектура БД

Ответов: 10
Просмотров: 95
Выборка существующих id? А как это сделать? Я не понимаю, как скрипт, который будет выдавать рандомную цифру, определит, что не существует какого-то айди, который удален? Можно какой-нибудь пример привести пожалуйста?
Cruzex Отправлено: 03 Мая, 2011 - 19:12:12 • Тема: Выборка • Форум: SQL и Архитектура БД

Ответов: 10
Просмотров: 95
Здравствуйте,
Требуется сделать рандомный выбор существующих id на php из базы. Я не знаю сколько id будет всего. Я предполагал сделать так:
1) селект из базы последнего записанного айди
2) выбор php (рандомом) цифри из всех существующих айди.
Но вопрос, у нас, к примеру, есть айди 1,2,3,4,5, айди 4 удалили, и как теперь надо php поступать. Какой скрипт дописать?

Страниц (1): [1]
Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB