Jump to content

tazeha

Members
  • Posts

    34
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://www.pluginha.com/

tazeha's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I use java script code to disable click on link in php but not working onclick="return false" I use tow way for add java script code to php link but both not working.. First way: $data .= '<td bgcolor="FFFFCC">'."<a href='http://priceha.ir/' onclick=\"return false\">.$row2->model.</a>".'</td>'; The second way: $data .= '<td bgcolor="FFFFCC">'."<a href='http://priceha.ir/' onclick='return false'>.$row2->model.</a>".'</td>';
  2. Hello with curl every 1 min go to the web and get the coin price and then store in the database. Now in my code compare latest tow records from table db ... if new price higher of old price echo price with color green.. and if less echo with red color and if equal echo with black color. <table border="1" width="50%"> <tr> <td>Date</td> <td>Amont</td> </tr> <?php $params =null; //or any params $mrkfPDO = new PDO('mysql:host=localhost;dbname=usd', 'root', '', array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) ); $mrkfStatement = $mrkfPDO->prepare("select * from uds order by id desc limit 2 ");$mrkfStatement->execute($params);$pays = $mrkfStatement->fetchAll(PDO::FETCH_ASSOC);$color = 'black';$resultcount = count($pays);if ($resultcount == 2) { if ($pays[1]['price'] > $pays[0]['price']) $colour = 'red'; if ($pays[1]['price'] < $pays[0]['price']) $colour = 'green'; }if ($resultcount > 0) { echo "<tr><td><span style='color: $color'>" .$pays [$resultcount-1]['price'] . "</span></td></tr>"; } ?> But I don't know why when echo higher price dos not change color to green.. and always is black
  3. My problem fix.. I should use $i=1 instead $i=0 because --- ['Amount'] < $pays[($i-1)
  4. Hello when I run my code give error Undefined offset: -1 in 3 line : if($pays[$i]['Amount'] < $pays[($i-1)]['Amount']) elseif($pays[$i]['Amount'] > $pays[($i-1)]['Amount']) .$pays[$i]['price']. <?php $params =null; //or any params $mrkfPDO = new PDO('mysql:host=localhost;dbname=YOUR_DB_NAME', 'DB_USER', 'DB_PASS', array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) ); $mrkfStatement = $mrkfPDO->prepare("SELECT Date, Amount FROM payments limit 0,100"); $mrkfStatement->execute($params); $pays = $mrkfStatement->fetchAll(PDO::FETCH_ASSOC); for($i=0; $i<=count($pays); $i++) { $color = 'black'; if($pays[$i]['Amount'] < $pays[($i-1)]['Amount']) $color="red"; elseif($pays[$i]['Amount'] > $pays[($i-1)]['Amount']) $color = 'green'; else $color = 'black'; echo "<tr> <td>" . $pays[$i]['Date'] . "</td> <td> <span style='color: $color'>" .$pays[$i]['Amount']. "</span> </td> </tr>"; } ?>
  5. I write this but diplay undefined $(document).ready(function(){ $.getJSON('js.json', function(data) { $.each(data.mesghal, function() { $("ul").append("<li>Price:" + this['p'] +"</li><li>Date:" + this['p'] +"</li>"); }); }); }); results: Price:undefined Date:undefined Price:undefined
  6. hello json data is array I want display mesghal values p,d,.... { "ati1": { "p": "8,935,000", "d": 0, "dp": 0, "dt": "", "h": "8,935,000", "l": "8,780,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ati2": { "p": "8,665,000", "d": 0, "dp": 0, "dt": "", "h": "8,860,000", "l": "8,665,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ati3": { "p": "8,720,000", "d": 0, "dp": 0, "dt": "", "h": "8,905,000", "l": "8,720,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ati4": { "p": "8,840,000", "d": 0, "dp": 0, "dt": "", "h": "9,020,000", "l": "8,825,000", "t": "۲۵ تیر", "t-g": "16 July" }, "ons": { "p": "1,135.30", "d": "10.70", "dp": 0.94, "dt": "low", "h": "1,146.50", "l": "1,135.30", "t": "۱۸:۳۰", "t-g": "18:30" }, "mesghal": { "p": "3,889,000", "d": 0, "dp": 0, "dt": "", "h": "3,934,000", "l": "3,883,000", "t": "۲۵ تیر", "t-g": "16 July" }} <script type='text/javascript'> $(document).ready(function(){ $.getJSON('saipa.php', function(data) { console.log(data); $.each(data, function(key, val) { $('ul').append('<li id="shoker">' + val.p + ' ' + val.h + ' ' + val.t + ' ' + val.l + '</li>'); }); }); }); </script> but can't display pleas help
  7. Hello In mysql is 50 row, example: id = 1,2,3,4,5,... I want echo only row 5 until 20 how can I? my code foreach ( $result as $row ) { $data .='<tr>'; $data .= '<td>'.$row->Shakhes.'</td>'; $data .='<td>'.$row ->Value.'</td>'; $data .='<td>'.$row ->TopValue.'</td>'; $data .= '<td>'.$row->DownValue.'</td>'; $data .= '<td>'.$row->Difference.'</td>'; $data .='</tr>'.PHP_EOL; }
  8. I find problem. INSERT INTO `Dadoo`(name,liveprice,`change`,lowest,topest) ... change is escape but give this error after fixing top error. Column count doesn't match value count at row 1 (this mean I have multie columns .. )
  9. Hello I write code to save foreach data to the database. foreach data is arrays . For this reason firs convert array to string and then save to the database but display following error on firefox. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'change,lowest,topest) VALUES ('[{"Name":"سu06a9ه بهاu' at line 1 my code $con = @mysql_connect ("localhost","root", ""); mysql_select_db("coin", $con); if (!$con) { die(mysql_error()); }else {foreach($table_rows as $tr) { // foreach row $row = $tr->childNodes; if($row->item(0)->tagName != 'tblhead') { // avoid headers $data[] = array( 'Name' =>trim($row->item(0)->nodeValue), 'LivePrice' => trim($row->item(2)->nodeValue), 'Change'=> trim($row->item(4)->nodeValue), 'Lowest'=> trim($row->item(6)->nodeValue), 'Topest'=> trim($row->item(8)->nodeValue), ///'Time'=> trim($row->item(10)->nodeValue), ); }} $newstring = json_encode($data); $date=array();mysql_select_db ( "coin", $con );"CREATE TABLE `Dadoo`(id INT NOT NULL AUTO INCREMENT,name VARCHAR(255),liveprice VARCHAR(255),change VARCHAR(255),lowest VARCHAR(255),topest VARCHAR(255),PRIMARY KEY(id)) ENGINE=MyISAM" or die(mysql_error());$debugquery = mysql_query("INSERT INTO `Dadoo`(name,liveprice,change,lowest,topest) VALUES ('$newstring')"); if (!$debugquery) { die(mysql_error()); }}mysql_close(); How fix it.
  10. But I'm very trying to work with this in the More sites witch write about curl
  11. Thanks. Can you write fix code with multi_get_content?
  12. I write following code to get Multiple page of the this site: www.mobile.ir This website have mobile price category .. this category have 42 navigation page. I write following code with curl_multi_init and xpath to get data from Multiple page from category. $ch1= curl_init ("http://www.mobile.ir/phones/prices.aspx");$ch2 = curl_init ("http://www.mobile.ir/phones/prices.aspx?sort=date&dir=desc&brandid=0&terms=&duration=14&pagesize=50&price_from=-1&price_to=-1&provinceid=0&shopid=0&page=2");curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch1,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');curl_setopt($ch1, CURLOPT_HEADER, 0);curl_setopt($ch1, CURLOPT_ENCODING, 'UTF-8');curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch2,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');curl_setopt($ch2, CURLOPT_HEADER, 0);curl_setopt($ch2, CURLOPT_ENCODING, 'UTF-8');$mh = curl_multi_init();//add the two handlescurl_multi_add_handle($mh,$ch1);curl_multi_add_handle($mh,$ch2);$active = null;//execute the handlesdo {$mrc = curl_multi_exec($mh, $active);} while ($mrc == CURLM_CALL_MULTI_PERFORM);while ($active && $mrc == CURLM_OK) {if (curl_multi_select($mh) != -1) {do {$mrc = curl_multi_exec($mh, $active);} while ($mrc == CURLM_CALL_MULTI_PERFORM);}}$dom = new DOMDocument('1.0', 'utf-8');libxml_use_internal_errors(true);$dom->loadHTML($mrc);libxml_clear_errors();$xpath = new DOMXpath($dom);$data = array();$table_rows = $xpath->query('//table[@id="price_table"]/tbody/tr'); // target the row (the browser rendered <tbody>, but actually it really doesnt have one)if($table_rows->length <= 0) { // exit if not foundecho 'no table rows found';exit;}$s = "stxECna";foreach($table_rows as $tr) { // foreach row$row = $tr->childNodes;if($row->item(0)->tagName != '<tr class="carHeader"> <td>نام کارخانه </td> <td>نام خودرو </td> <td>قیمت نمایندگی (ریال) </td> <td>قیمت بازار (ریال) </td> </tr>') { // avoid headers$data[] = array('Name' => trim($row->item(2)->nodeValue),'Price' => trim($row->item(4)->nodeValue),);}}echo '<pre>';print_r($data); But don't display data ... when I use curl_init() to get data from one page without problem working and displaying data (name and price) but when use curl_multi_init dont display I really need..
  13. Hello I write the code to get and scrap data form website . That website have a navigation page (1,2,3,4,5) I want auto get data form one page to end page of website.mean(starting scrap from 1 page and then auto get data from two page ,...) . following is piece of my code witch I write. require_once "xpath.php";set_time_limit(0);$starUrl= "http://www.digionline.ir/Allprovince/viewcat/%D9%82%DB%8C%D9%85%D8%AA-%D8%AE%D8%B1%DB%8C%D8%AF-%D9%81%D8%B1%D9%88%D8%B4-%D9%85%D8%B4%D8%AE%D8%B5%D8%A7%D8%AA-%D9%84%D9%BE-%D8%AA%D8%A7%D9%BE---Laptop--/cat=10101";function sracperdigi($url){$baseUrl ="http://www.digionline.ir";$array = array();$xpath = new XPATH($url);//pluginha.com$produsttitleQuery = $xpath->query("//span[@class='product-page-detail-wrapper- text']/text()");$produstpriceQuery = $xpath->query("/html/body/div[5]/div/div/div[3]/div[2]/ul/li/span[1]/span[2]/text()");//$produstlinkQuery = $xpath->query("/html/body/div[5]/div/div/div[3]/div[2]/div[2]/span/a");for ($x = 0; $x <40; $x++){$string = $array[$x]['title'] = $produsttitleQuery->item($x)->nodeValue ."*";$string = $array[$x]['price'] = $produstpriceQuery->item($x)->nodeValue ."*";// $string = $array [$x]['link'] =$baseUrl.$produstlinkQuery->item($x)->nodeValue."*";}}
×
×
  • Create New...