PHP . SU
Программирование на PHP, MySQL и другие веб-технологии
Страниц (16): В начало « ... 8 9 10 11 12 13 14 15 [16]
Найдено сообщений: 232
Ammiak
Отправлено: 11 Мая, 2011 - 07:45:50 • Тема: передача параметров из нескольких форм • Форум: JavaScript & VBScript
Ответов: 4 Просмотров: 1559
всем привет!
есть 2 формы:
CODE (
html ):
скопировать код в буфер обмена
<form id = "form1" method = "post" action = "../php/script1.php" >
<input id = "in1" name = "in1" value = "old_parameter1" / >
<input id = "in2" name = "in2" value = "old_parameter2" / >
<input id = "in3" name = "in3" value = "old_parameter3" / >
<input type = "submit" id = "subm1" / >
</ form >
<form id = "form2" method = "post" action = "../php/script2.php" >
<input id = "in4" name = "in4" value = "new_parameter" / >
<input type = "submit" id = "subm2" / >
</ form >
нужно в script2.php передать параметры из form1. Пробовал аяксом собрать параметры и отправить скрипту:
CODE (
javascript ):
скопировать код в буфер обмена
$( function ( ) {
$( '#subm2' ) .click ( function ( e) {
e.preventDefault ( ) ;
var a= $( '#form1' ) .serialize ( ) ;
$.post ( "../php/script2.php" , a)
} ) ;
} ) ;
но пар-ры не передались, подскажите пожал. как сделать? заранее благодарю
(Добавление)
кто-нибудь?
Ammiak
Отправлено: 04 Мая, 2011 - 11:48:46 • Тема: вывод значений из бд • Форум: SQL и Архитектура БД
Ответов: 3 Просмотров: 27
переделал так, результат тот же (поправьте если что-то не так):
CODE (
javascript ):
скопировать код в буфер обмена
$( ':submit' ) .click ( function ( e) {
e.preventDefault ( ) ;
var obj = $( this ) ;
ajax_sum( obj) ;
} ) ;
function ajax_sum( elem) {
$( ':submit' ) .each ( function ( ) {
var a= $( elem) .prev ( ) .val ( ) ;
$.post ( '../php/script.php' , { good2: sd} , function ( data) {
if ( data.length > 0 ) {
$( '#total' ) .html ( data) .show ( ) ;
}
} )
} ) ;
}
(Добавление)
По-моему, аякс здесь ни при чём, пробовал без него:
CODE (
html ):
скопировать код в буфер обмена
<form method = "post" action = "../php/script.php" >
<input id = "good1" name = "good1" type = "hidden" value = "Товар1" ><a href = "#" > Товар1</ a ></ input >
<input type = "submit" id = "subm1" class = "basket" value = "" title = "Добавить в корзину" / ><br >
<input id = "good2" name = "good2" type = "hidden" value = "Товар2" ><a href = "#" > Товар2</ a ></ input >
<input type = "submit" id = "subm2" class = "basket" value = "" title = "Добавить в корзину" / ><br >
Всё равно в итоге:
Цитата:
[type_good] => Товар1 [price_good] => цена
Ammiak
Отправлено: 04 Мая, 2011 - 09:50:08 • Тема: вывод значений из бд • Форум: SQL и Архитектура БД
Ответов: 3 Просмотров: 27
здравствуйте, помогите разобраться: есть форма заказа:
CODE (
html ):
скопировать код в буфер обмена
<form method = "post" action = "../php/script.php" >
<input id = "good1" name = "good1" type = "hidden" value = "Товар1" ><a href = "#" > Товар1</ a ></ input >
<input type = "submit" id = "subm1" class = "basket" value = "" title = "Добавить в корзину" / ><br >
<input id = "good2" name = "good2" type = "hidden" value = "Товар2" ><a href = "#" > Товар2</ a ></ input >
<input type = "submit" id = "subm2" class = "basket" value = "" title = "Добавить в корзину" / ><br >
<input id = "good3" name = "good3" type = "hidden" value = "Товар3" ><a href = "#" > Товар3</ a ></ input >
<input type = "submit" id = "subm2" class = "basket" value = "" title = "Добавить в корзину" / ><br >
<input id = "good4" name = "good4" type = "hidden" value = "Товар4" ><a href = "#" > Товар4</ a ></ input >
<input type = "submit" id = "subm2" class = "basket" value = "" title = "Добавить в корзину" / ><br >
<input id = "good5" name = "good5" type = "hidden" value = "Товар5" ><a href = "#" > Товар5</ a ></ input >
<input type = "submit" id = "subm2" class = "basket" value = "" title = "Добавить в корзину" / >
<span id = "total" > </ span >
</ form >
затем немного ajax
CODE (
javascript ):
скопировать код в буфер обмена
$( function ( ) {
$( '#total' ) .slideUp ( ) ;
$( ':submit' ) .click ( function ( e) {
e.preventDefault ( ) ;
ajax_sum( ) ;
} ) ;
function ajax_sum( ) {
$( ':submit' ) .each ( function ( ) {
var a= $( this ) .prev ( ) .val ( ) ;
$.post ( '../php/script.php' , { good2: a} , function ( data) {
if ( data.length > 0 ) {
$( '#total' ) .html ( data) .show ( ) ;
}
} )
} ) ;
}
} ) ;
скрипт обработки script.php:
PHP:
скопировать код в буфер обмена
$good = $_POST [ 'good2' ] ;
$query = mysql_query ( "select type_good, price_good from goods where type_good LIKE '%$good %'" ) ;
echo '<table><tr><td>' . $row [ 'type_good' ] . '</td><td>' . $row [ 'price_good' ] . '</td></tr></table>' ;
При нажатии на кнопку "Добавить в корзину" значение инпута, соответствующего этой кнопке отправляется в бд, где есть столбцы type_good (название товара) и price_good (его цена). Если соответствие найдено, в <span id="total"> помещается название товара и цена.
У меня при нажатии на второй сабмит возвращается название и цена первого товара из списка а не второго, да и проверял дамп массива $row, выглядит так:
Цитата:
[type_good] => Товар1 [price_good] => цена
как добиться соответствия? заранее благодарю
Ammiak
Отправлено: 22 Апреля, 2011 - 10:53:00 • Тема: rss и прокси-сервер • Форум: Программирование на PHP
Ответов: 1 Просмотров: 732
Здравствуйте, есть парсер новостей import.php:
PHP:
скопировать код в буфер обмена
// Подключаем класс lastRSS и настройки прокси
include_once "lastRSS.php" ;
include_once "news_curl.php" ;
// новый экземпляр класса
$rss = new lastRSS;
'http://news.sportbox.ru/taxonomy/term/7212/0/feed'
) ;
// выводим все RSS-файлы из списка
foreach ( $rss_import as $url ) {
if ( $chan = $rss -> get ( $url ) ) {
// выводим заголовок и ссылку канала
echo "<h1><a href=$chan[link] >$chan[title] </a></h1>" ;
// выводим описание канала
echo "<p><h2>$chan[description] </h2>" ;
// выводим статьи
foreach ( $chan [ 'items' ] as $item )
{
echo "<span><a href=$item[link] >$item[title] </a></span><br><br>" ;
}
}
else {
echo "Ошибочка! Пустой канал или неправильный формат
файла <br>$url \n <br>" ;
}
}
к нему файл с настройками прокси-сервера news_curl.php:
и класс lastRSS.php:
PHP:
скопировать код в буфер обмена
class lastRSS {
var $default_cp = 'UTF-8' ;
var $CDATA = 'nochange' ;
var $cp = '' ;
var $items_limit = 0 ;
var $stripHTML = False ;
var $date_format = '' ;
var $channeltags = array ( 'title' , 'link' , 'description' , 'language' , 'copyright' , 'managingEditor' , 'webMaster' , 'lastBuildDate' , 'rating' , 'docs' ) ; var $itemtags = array ( 'title' , 'link' , 'description' , 'author' , 'category' , 'comments' , 'enclosure' , 'guid' , 'pubDate' , 'source' ) ; var $imagetags = array ( 'title' , 'url' , 'link' , 'width' , 'height' ) ; var $textinputtags = array ( 'title' , 'description' , 'name' , 'link' ) ;
function Get ( $rss_url ) {
// If CACHE ENABLED
if ( $this -> cache_dir != '' ) {
$cache_file = $this -> cache_dir . '/rsscache_' . md5 ( $rss_url ) ; if ( $timedif < $this -> cache_time ) {
// cached file is fresh enough, return cached array
// set 'cached' to 1 only if cached file is correct
if ( $result ) $result [ 'cached' ] = 1 ;
} else {
// cached file is too old, create new
$result = $this -> Parse ( $rss_url ) ;
if ( $f = @ fopen ( $cache_file , 'w' ) ) { }
if ( $result ) $result [ 'cached' ] = 0 ;
}
}
// If CACHE DISABLED >> load and parse the file directly
else {
$result = $this -> Parse ( $rss_url ) ;
if ( $result ) $result [ 'cached' ] = 0 ;
}
// return result
return $result ;
}
function my_preg_match ( $pattern , $subject ) {
if ( $this -> CDATA == 'content' ) { // Get CDATA content (without CDATA tag)
$out [ 1
] = strtr ( $out [ 1
] , array ( '<![CDATA[' => '' , ']]>' => '' ) ) ; } elseif ( $this -> CDATA == 'strip' ) { // Strip CDATA
$out [ 1
] = strtr ( $out [ 1
] , array ( '<![CDATA[' => '' , ']]>' => '' ) ) ; }
if ( $this -> cp != '' )
//$out[1] = $this->MyConvertEncoding($this->rsscp, $this->cp, $out[1]);
$out [ 1
] = iconv ( $this -> rsscp , $this -> cp . '//TRANSLIT' , $out [ 1
] ) ; // Return result
} else {
return '' ;
}
}
function unhtmlentities ( $string ) {
// Get HTML entities table
// Flip keys<==>values
// Add support for ' entity (missing in HTML_ENTITIES)
$trans_tbl += array ( ''' => "'" ) ; // Replace entities by values
return strtr ( $string , $trans_tbl ) ; }
function Parse ( $rss_url ) {
// Open and load RSS file
if ( $f = @ fopen ( $rss_url , 'r' ) ) { $rss_content = '' ;
$rss_content .= fgets ( $f , 4096
) ; }
$result [ 'encoding' ] = $this -> my_preg_match ( "'encoding=[\'\" ](.*?)[\'\" ]'si" , $rss_content ) ;
// if document codepage is specified, use it
if ( $result [ 'encoding' ] != '' )
{ $this -> rsscp = $result [ 'encoding' ] ; } // This is used in my_preg_match()
else
{ $this -> rsscp = $this -> default_cp ; } // This is used in my_preg_match()
preg_match ( "'<channel.*?>(.*?)</channel>'si" , $rss_content , $out_channel ) ; foreach ( $this -> channeltags as $channeltag )
{
$temp = $this -> my_preg_match ( "'<$channeltag .*?>(.*?)</$channeltag >'si" , $out_channel [ 1] ) ;
if ( $temp != '' ) $result [ $channeltag ] = $temp ; // Set only if not empty
}
if ( $this -> date_format != '' && ( $timestamp = strtotime ( $result [ 'lastBuildDate' ] ) ) !==- 1
) { $result [ 'lastBuildDate' ] = date ( $this -> date_format , $timestamp ) ; }
preg_match ( "'<textinput(|[^>]*[^/])>(.*?)</textinput>'si" , $rss_content , $out_textinfo ) ;
// Look for tag <textinput> with or without any attributes, but skip truncated version <textinput /> (it's not beggining tag)
if ( isset ( $out_textinfo [ 2
] ) ) { foreach ( $this -> textinputtags as $textinputtag ) {
$temp = $this -> my_preg_match ( "'<$textinputtag .*?>(.*?)</$textinputtag >'si" , $out_textinfo [ 2] ) ;
if ( $temp != '' ) $result [ 'textinput_' . $textinputtag ] = $temp ; // Set only if not empty
}
}
preg_match ( "'<image.*?>(.*?)</image>'si" , $rss_content , $out_imageinfo ) ; if ( isset ( $out_imageinfo [ 1
] ) ) { foreach ( $this -> imagetags as $imagetag ) {
$temp = $this -> my_preg_match ( "'<$imagetag .*?>(.*?)</$imagetag >'si" , $out_imageinfo [ 1] ) ;
if ( $temp != '' ) $result [ 'image_' . $imagetag ] = $temp ; // Set only if not empty
}
}
preg_match_all ( "'<item(| .*?)>(.*?)</item>'si" , $rss_content , $items ) ; $rss_items = $items [ 2] ;
$i = 0 ;
$result [ 'items' ] = array ( ) ; foreach ( $rss_items as $rss_item ) {
if ( $i < $this -> items_limit || $this -> items_limit == 0) {
foreach ( $this -> itemtags as $itemtag ) {
$temp = $this -> my_preg_match ( "'<$itemtag .*?>(.*?)</$itemtag >'si" , $rss_item ) ;
if ( $temp != '' ) $result [ 'items' ] [ $i ] [ $itemtag ] = $temp ; // Set only if not empty
}
if ( $this -> stripHTML && $result [ 'items' ] [ $i ] [ 'description' ] )
$result [ 'items' ] [ $i ] [ 'description' ] = strip_tags ( $this -> unhtmlentities ( strip_tags ( $result [ 'items' ] [ $i ] [ 'description' ] ) ) ) ;
if ( $this -> stripHTML && $result [ 'items' ] [ $i ] [ 'title' ] )
$result [ 'items' ] [ $i ] [ 'title' ] = strip_tags ( $this -> unhtmlentities ( strip_tags ( $result [ 'items' ] [ $i ] [ 'title' ] ) ) ) ; if ( $this -> date_format != '' && ( $timestamp = strtotime ( $result [ 'items' ] [ $i ] [ 'pubDate' ] ) ) !==- 1
) {
$result [ 'items' ] [ $i ] [ 'pubDate' ] = date ( $this -> date_format , $timestamp ) ; }
$i ++;
}
}
$result [ 'items_count' ] = $i ;
return $result ;
}
else
{
return False ;
}
}
}
Не работает с использованием прокси-сервера, выдаёт ошибку:
Цитата:
Notice: Undefined property: lastRSS::$cache_dir in E:\my_projects\lastRSS.php on line 58
т.е. ругается на строчку
Цитата:
if ($this->cache_dir != '') {
подскажите пожал. что я здесь неправильно подключил? (без прокси парсер работает нормально)
Ammiak
Отправлено: 18 Апреля, 2011 - 14:44:46 • Тема: функция array_count_values() • Форум: Программирование на PHP
Ответов: 4 Просмотров: 318
Дамп массива выглядит так:
Цитата: Array
(
[Mon] => 4
[Thu] => 2
[Tue] => 3
)
вопрос в следующем: как вывести скажем "Понедельников: 4".
Не так же:
больше пока в голову ничего не приходит...
Ammiak
Отправлено: 18 Апреля, 2011 - 13:10:53 • Тема: функция array_count_values() • Форум: Программирование на PHP
Ответов: 4 Просмотров: 318
здравствуйте, непонятен такой момент при использовании функции array_count_values(). Например обрабатываем такой массив:
почему выводится только: . заранее благодарю
Страниц (16): В начало « ... 8 9 10 11 12 13 14 15 [16]
Powered by ExBB FM 1.0 RC1. InvisionExBB