Jump to content

sunnysideup

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sunnysideup's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The Page source is as follows: <table border="0" width="750" id="table2" cellspacing="0" cellpadding="0"> <tr> <td width="80"><font size="2">Sensex</font></td> <td><font face="Tahoma" size="2"> <span style="color: #009900;<img src= '../images/up.png'>">17694.2</span></li> </font></td> </tr> </table>
  2. No its not outputting any image, and both the images are in "images" folder.
  3. Tried echo "<img src= '../images/down.png'>"; but still cant see the image
  4. I'm having issues echoing image in the below code: <?php echo "<span style=\""; # If we gained print the percentage in GREEN if ($data[1]>0) { echo "color: #009900;"; echo "<img src='images/up.png'>"; } # if we lost RED elseif ($data[1]<0) { echo "color: #DF0D0D;"; echo "<img src='images/down.png'>"; } # No color else { echo "font-weight: normal;"; } echo "\">".$data[0]."</span></li>\n"; ?> Can someone please tell me, where i'm going wrong?
  5. Your code should have logic in it to check for errors, output a user error message when an error occurs, and take an appropriate action when there is an error to prevent follow-on errors by preventing the remainder of the code that depends on a previous step from executing (which is what is causing your foreach() error now.) Most of the php functions return a FALSE value when they fail. You should be checking for when that occurs in your code. pseudo code - if($var = file(.....)){ // code to execute when file() worked without any errors (i.e. process the data) } else { // application error reporting code to execute when file() failed - // output a user error message echo "Sorry, We cannot connect to Data, Please try again Later"; } // remainder of the code on your page having nothing to do with the file() statement Many Thanks for your replies, I have managed to turn off error by inserting " error_reporting(0); " at the start of the script. But cant understand how to put a custom message in case of remote site (Googls docs) not available. My File is as below: <?php $color1 = "#CFDAFF"; $color2 = "#EFF2FF"; $row_count = 0; // get the CSV data as an array from the remote URL error_reporting(0); $lines = file('http://spreadsheets.google.com/pub?key=reeroigtgf5aHN0ERTS3RxA&single=true&gid=2&range=C47%3AG47&output=csv'); // get rid of header row //$headers = array_shift($lines); // Loop through data- therer is only one line hear foreach ($lines as $line) { $ldata = explode(',', trim($line)); // split row to its own array of elements if ($ldata[0] == '') break; // an empty line means we are done, so exit the foreach loop $row_color = ($row_count % 2) ? $color1 : $color2; $row_count++; // now we can just output the information as an HTML list, referencing the appropriate array items // echo '<li>' . $ldata[0] . '<strong>' . $ldata[1] . '</strong>' . $ldata[2] . '</strong>' . $ldata[3] . '</strong>' . '$ldata[4]' . ''; ?>
  6. I have a script which gets content from google spreadsheet, but if for some/any reason google docs is not available the script throws warnings as below: Warning: file() [function.file]: php_network_getaddresses: getaddrinfo failed: No such host is known. in Z:\www\website\scores\indice.php on line 6 Warning: file(http://spreadsheets.google.com/pub?key=reeroigtgf5aHN0ERTS3RxA&single=true&gid=2&range=C47%3AG47&output=csv) [function.file]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in Z:\www\website\scores\indice.php on line 6 Warning: Invalid argument supplied for foreach() in Z:\www\website\scores\indice.php on line 12 I dont want the visitors to see these errors, is there any way i can hide these errors, or maybe an alternate text comes in like "Sorry, We cannot connect to Data, Please try again Later". There is no error in the script, only when there is a loss of remote connection (eg, if i surf with my LAN off), there error/warnings appear. Please help
  7. I have tried to insert "echo "<tr>",print_r($ldata[0],true),"</tr>";// replace this line with your code that uses the contents in $ldata" in every possible place, but still cant seem to have the desired output.
  8. I'm trying the following code, but not getting any output: <?php $file = 'http://spreadsheets.google.com/pub?key=t1lEdkCoz0-FUi9FY1QXyBw&single=true&gid=0&range=B4%3AG25&output=csv'; $handle = fopen($file, "r"); while (($ldata = fgetcsv($handle, 1000)) !== FALSE) { // echo "<pre>",print_r($ldata[0],true),"</pre>";// replace this line with your code that uses the contents in $ldata } fclose($handle); ?> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td></td> <td><?php echo $ldata[0] ?></td> <td><?php echo $ldata[1] ?></td> <td><?php echo $ldata[2] ?></td> <td><?php echo $ldata[3] ?></td> <td><?php echo $ldata[5] ?></td> </tr> </table>
  9. Thank you very much for your reply & help, Sorry, i'm a total noob as far as php is concerned, but always try to learn from gurus like you. I tried your solution. But i'm now getting all the data as an array, and i need them in tables. I'm attaching two images for reference. Can you kindly help in the matter. regards [attachment deleted by admin]
  10. I'm trying to get google spreadsheet data into a webpage by a php script. All works well, till the time there is no comma (,) in the number cells, if the comma is found in the absolute number (eg. 1,234) then the code parses just 1 and then n another array the rest 234. Can anyone please help. My code is as follows: <?php // get the CSV data as an array from the remote URL $lines = file('http://spreadsheets.google.com/pub?key=t1lEdkCoz0-FUi9FY1QXyBw&single=true&gid=0&range=B4%3AG25&output=csv'); // get rid of header row //$headers = array_shift($lines); // Loop through data- therer is only one line hear foreach ($lines as $line) { $ldata = explode(',', trim($line)); // split row to its own array of elements if ($ldata[0] == '') break; // an empty line means we are done, so exit the foreach loop // now we can just output the information as an HTML list, referencing the appropriate array items // echo '<li>' . $ldata[0] . '<strong>' . $ldata[1] . '</strong>' . $ldata[2] . '</strong>' . $ldata[3] . '</strong>' . '$ldata[4]' . ''; ?> <table width="100%" id="table1"> <tr><td width="250"><a href="index.php/<?php echo $ldata[0] ?>.sa"><?php echo $ldata[0] ?></a></td> <td width="75"><?php echo "<span style=\""; # If we gained print the percentage in GREEN if ($ldata[2]>0) { echo "color: #009900;"; } # if we lost RED elseif ($ldata[2]<0) { echo "color: #DF0D0D;"; } # No color else { echo "font-weight: normal;"; } echo "\">".$ldata[1]."</span></li>\n"; ?></font></td> <td width="75"><?php echo "<span style=\""; # If we gained print the percentage in GREEN if ($ldata[2]>0) { echo "color: #009900;"; } # if we lost RED elseif ($ldata[2]<0) { echo "color: #DF0D0D;"; } # No color else { echo "font-weight: normal;"; } echo "\">".$ldata[2]."</span></li>\n"; ?></font></td> <td width="100"><?php echo $ldata[3] ?></td> <td width="100"><?php echo $ldata[4] ?></td> <td width="100"><?php echo $ldata[5] ?></td></tr> </table> <?php } ?> In case anyone needs to look into the raw csv its as follows: Company Name,Last Price,Change%,Volume,Days High / Low,52 Week High / Low ACC LIMITED,972,2.2%,49.6,974 / 952,"1,017 / 572" TATA MOTORS,788.3,1.8%,272.9,789 / 774,842 / 204 DLF LIMITED,333.4,1.7%,622,334 / 329,491 / 195 MARUTI SUZUKI,1399.4,1.7%,47.9,"1,400 / 1,370","1,740 / 752" GRASIM,2860.1,1.5%,143.9,"2,865 / 2,815","2,952 / 1,540" REL. INFRA,1101.7,1.4%,123,"1,104 / 1,083","1,404 / 590" HERO HONDA,2069,1.4%,34.5,"2,074 / 2,033","2,078 / 1,040" RELIANCE COMM,179.25,1.2%,423.6,"2,560 / 2,501",359 / 156 M&M,539.3,0.9%,65.8,541 / 536,598 / 215 TATA POWER,1383,0.9%,10.9,"1,385 / 1,371","1,519 / 810" NTPC,211.4,0.8%,299.5,212 / 210,242 / 180 BHEL,2547,0.7%,44.2,"2,560 / 2,501","2,550 / 1,500" JAIPRAKASH ASSO.,153.55,0.6%,410.2,155 / 153,180 / 62 TATA STEEL,689.5,0.6%,316,693 / 686,737 / 230 HDFC BANK,1942,0.5%,13.4,"1,946 / 1,939","1,986 / 1,045" BHARTI AIRTEL,317.6,0.5%,186,319 / 316,495 / 272 HINDALCO,185.2,0.4%,146.3,186 / 185,188 / 54 RELIANCE IND.,1125.55,0.4%,179.7,"1,171 / 1,123","1,245 / 819" STERLITE IND.,873.05,0.3%,137.6,878 / 867,928 / 370 L&T,1652,0.2%,34.1,"1,660 / 1,648","1,800 / 725" ICICI BANK,999.5,0.2%,129.7,"1,008 / 997","1,010 / 341" ONGC,1082.65,0.1%,92.6,"1,091 / 1,051","1,274 / 840" SBI,2125.5,0.1%,72.9,"2,135 / 2,121","2,500 / 1,100" --,--,--,--,--,-- --,--,--,--,--,-- "Quotes may be delayed up to 20 minutes. Information is provided 'as is' and solely for informational purposes, not for trading purposes or advice. Disclaimer: http://www.google.com/intl/en/help/stock_disclaimer.html" The output looks like in the attached image, i have marked the error in red. Any help would be highly appreciated. regards [attachment deleted by admin]
  11. Dear Redarrow, I'm a complete newbie to php, i do undertsand logic, so if you can please guide me which code to insert where it would help me a lot. regards
  12. Can any guru please take a look and advise. regards
  13. Dear All, I'm trying to parse yahoo quotes using their csv service, everything is runing well, but i cant get to load an image dynamically, my code (without image link) is as follows: <?php $quote = $_GET['company']; $url = "http://in.finance.yahoo.com/d/quotes.csv?s=" . $quote . "&f=sl1d1t1c1ohgvwmj5j6k4k5t7m3m7m8m4m5m6npbaa5a2kj&e=.csv"; //open it for reading $fp = fopen($url , "r"); //if no connection exists display error message if (!fp) { echo "could not connect to the site"; }else { //store the csv file info in the array $data $data = fgetcsv($fp,1000,","); //close the file fclose($fp); ?> <table> <tr><td colspan="2">CHART IMAGE FROM http://ichart.finance.yahoo.com/b?s=GOOG</td></tr> <tr><td>Last Trade</td><td><?php echo $data[1] ?></td></tr> <tr><td>date</td><td><?php echo $data[2] ?></td></tr> <tr><td>time</td><td><?php echo $data[3] ?></td></tr> <tr><td>change</td><td><?php echo $data[4] ?></td></tr> <tr><td>open</td><td><?php echo $data[5] ?></td></tr> <tr><td>high</td><td><?php echo $data[6] ?></td></tr> <tr><td>low</td><td><?php echo $data[7] ?></td></tr> <tr><td>Volume</td><td><?php echo $data[8] ?></td></tr> <tr><td>52 Week Range</td><td><?php echo $data[9] ?></td></tr> <tr><td>Days Range</td><td><?php echo $data[10] ?></td></tr> <tr><td>Change From 52-wk Low</td><td><?php echo $data[11] ?></td></tr> <tr><td>% Chg From 52-wk Low</td><td><?php echo $data[12] ?></td></tr> <tr><td>Change From 52-wk High</td><td><?php echo $data[13] ?></td></tr> <tr><td>% Change From 52-wk High</td><td><?php echo $data[14] ?></td></tr> <tr><td>Ticker Trend</td><td><?php echo $data[15] ?></td></tr> <tr><td>50-day Moving Avg</td><td><?php echo $data[16] ?></td></tr> <tr><td>Change From 50-day Moving Avg</td><td><?php echo $data[17] ?></td></tr> <tr><td>Pct Chg From 50-day Moving Avg</td><td><?php echo $data[18] ?></td></tr> <tr><td>200-day Moving Avg</td><td><?php echo $data[19] ?></td></tr> <tr><td>Change From 200-day Moving Avg</td><td><?php echo $data[20] ?></td></tr> <tr><td>Pct Chg From 200-day Moving Avg</td><td><?php echo $data[21] ?></td></tr> <tr><td>eg..</td><td><?php echo $data[22] ?></td></tr> <tr><td>Previous Close</td><td><?php echo $data[23] ?></td></tr> <tr><td>Bid</td><td><?php echo $data[24] ?></td></tr> <tr><td>Ask</td><td><?php echo $data[25] ?></td></tr> <tr><td>Ask Size</td><td><?php echo $data[26] ?></td></tr> <tr><td>Average Daily Volume</td><td><?php echo $data[27] ?></td></tr> <tr><td>52week High</td><td><?php echo $data[28] ?></td></tr> <tr><td>52 Week Low</td><td><?php echo $data[29] ?></td></tr> </table> <?php } ?> Now i want to include chart image from http://ichart.finance.yahoo.com/b?s=GOOG ??? (Please see line 19 in the above code) Wherin "GOOG" should be loaded from "$quote = $_GET['company'] Can anyone please help. regards
  14. Dear Zanus, I see that yuo have moved the posts to "## Third Party PHP Scripts" thread. I think as this Joomla related query, other users facing this kind of issue in joomla will easily find it in Joomla thread. Just my point of view, but you would know best as you have been moderating this forum regards Sunny
×
×
  • 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.