Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
nbv4
Aug 21, 2002

by Duchess Gummybuns

Lumpy posted:

code:
<div style="width:100px;border solid 1px #666;">
<?php
foreach($salesThing as $thing){
 echo '<div style="height:10px;width:'. $salesThing->percentTowardsGoal . 'px;background-color:#0f0;">&nbsp;</div>';
}
?>
</div>
Just make DIVs and width them based on the data. You can even use a fancy pants CSS background image for striping and whatnot.

Since we're on the topic, I really wish there was a method built into HTML/CSS that sets the widths and things automatically based on a "scale" value. For instance:

code:
while($rows = mysql_fetch_array($result))
{
    $return .= "<tr>
                    <td style=\"text-align:right;width:10em\">{$rows['title']}</td>
                    <td style=\"width:{$row['value']};background-color: pink\">{$row['value']}</td>
               </tr>\n\n";
}
...wound automatically scale each cell in the second row. As it is now, I'll have to go through each row in the SQL result, find the highest value, then on the second time around, divide each value by the largest value to get percentage.

nbv4 fucked around with this message at 09:14 on Mar 22, 2008

Adbot
ADBOT LOVES YOU

nbv4
Aug 21, 2002

by Duchess Gummybuns
is there a more elegant way to do this?:

code:
$variable = $field . "_sel";
$$variable = "checked";

nbv4
Aug 21, 2002

by Duchess Gummybuns
Say, since we're on the subject of escaping, I noticed a little while ago that whenever data comes in through a <textarea>, the string is already escaped. If I run it through mysql_real_escape_string, double escaping will occur. I don't know if it's the browser thats doing this, or if it some kind of magic quotes thing... After I finally realized this, I just stopped escaping all my textarea data. Is this a bad decision?

nbv4
Aug 21, 2002

by Duchess Gummybuns
I have this one class which is getting so huge, it's almost 2000 lines. I want to split it up into smaller text files to make editing easier, but I'm having trouble doing so. Apparently you can't just do:

php:
<?

class foo extends lol
{
     include "text_file_with_methods.php";

     function blah()
     {
       ...
?>
nor can you have a class extending from multiple classes. What can I do here?

nbv4
Aug 21, 2002

by Duchess Gummybuns

Inquisitus posted:

Either try and split the class up logically into smaller classes, or leave it as it is if you can't.

I could do that fairly easily because this huge class is essentially two classes in one anyways, but the only problem is that this classes constructor runs like 20 SQL queries which provide information for pretty much every function in that class. If I split it into two or three classes, I'll have to run those constructors another time or maybe even twice more. I'd really hate to do that for just the convenience of having seperate text files...

nbv4
Aug 21, 2002

by Duchess Gummybuns

duz posted:

You can have constructors run the parent's constructors or you can have your queries just use the last used connection.
I'm not worried about that, I'm worried about actually running the queries twice, one for each object. I'm kind of a performance stickler like that. Is there anyway to easily copy a bunch of member variables from one object to another? I admit I'm not really an OOP expert.

nbv4
Aug 21, 2002

by Duchess Gummybuns
Does anyone here have have experience using jpGraph? I'm having trouble with a graph of mine. It seems whenever you try to display the values of an accumulated bar graph rotated at 90 degrees, the labels get printed a few pixels higher than they are supposed to be.

here is an example: http://xs226.xs.to/xs226/08156/list_graph473.png

Here is the code for that particular graph:

code:
// Create a bar pot
	$bplot1 = new BarPlot($data1);
	$bplot1->SetFillColor($bar_color);
	$bplot1->SetValuePos("center");
	$bplot1->value-> Show();
	$bplot1->SetLegend($time_title2);
	
	###############################################
	
	// Create another bar pot
	$bplot2 = new BarPlot($data2);
	$bplot2->SetFillColor($bar_color2);
	$bplot2->SetValuePos("center");
	$bplot2->value-> Show();
	$bplot2->SetLegend($time_title1);
	
	###############################################
	
	$bplot  = new AccBarPlot (array($bplot1 ,$bplot2));
	$bplot->SetAbsWidth(10);
	$bplot->value-> Show();
        $bplot->value->SetMargin(10); 
		
###############################################################

$graph = new Graph($width,$height,'auto');
$graph->SetScale("textlin", 0, $maximum + (0.08 * $maximum));
$graph->yaxis->HideTicks(true,true);
$graph->xaxis->HideTicks(true,true);
$graph->xgrid->SetWeight(0); 
$graph->ygrid->SetWeight(0);
$graph->yaxis->Hide();

$top = 30;
$bottom = 30;
$left = 180;
$right = 30;

$graph->Set90AndMargin($left,$right,$top,$bottom);
$graph->SetShadow();
$graph->xaxis->SetTickLabels($title);
$graph->xaxis->SetLabelAlign('right','center','right');
$graph->yaxis->SetLabelAlign('center','bottom');
$graph->title->Set("$time_title by $type_title");
$graph->Add($bplot);
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->SetPos(0.7,0.90,'center','center'); 
$graph->Stroke();
If I comment out the line that rotates the graph 90 degrees, it displays fine. Anyone know if theres a way to fix this, or is it just a bug?

nbv4
Aug 21, 2002

by Duchess Gummybuns

Kaluza-Klein posted:


I have a __constructor() function that loads the Code Igniter stuff. That uri_to_assoc() function expects an object as the 2nd param ($default). My problem is that apparently you cannot set objects like that at the start of the class. It throws a fit at the first line inside the class public $default->display_type = 'all';. If I just set $display_type and $display_order it is happy, but then I have to put them into an object inside read_uri() (I guess).

I imagine there is a good reason I cannot set an object like that at the start? How should I do it instead? Makes me wonder if I can set an array. . .

I don't know if this is related, but you can't call functions from within a class variable declaration. For instance:

php:
<?

class poop extends woop
{
   var variable1 = "4389348";
   var variable2 = "fdjf545478";
   var variable3 = trim("fdsuiofd ui fui fds ");

function poop()
{
    print "poo lol";
}
?>
Will give you an error because you called trim(). I have no idea why this is the case, but you just can't do that :shobon:

quote:

edit: I realize now why having an object declared like that is a bad idea. You could declare a variable $what and then also have a function called $what and that would not be good. You can declare arrays, but only if you use the syntax $bla = array ('huh'), doing $bla[] = 'huh' doesn't work.

When you do $blah[] = "something", the "=" operator kind of works like the ".=" operator. Your basically saying "add this value to the array", When the array has not been set, an error occurs.

nbv4
Aug 21, 2002

by Duchess Gummybuns

drcru posted:

Didn't know where to put this question but since I'm writing in PHP...

Should I stick to using a timestamp like this YYYY-MM-DD or use the Unix timestamp?

Is it okay to use both (eg. one for one system and one for another)?

What I do is use YYYY-MM-DD when putting dates into the database, and when i get dates from the database, I immediately convert to unix timestamp for php manipulation.

I've found that entering a unix timestamp into the database directly, via the UNIX_TIMESTAMP() mysql function (or whatever it's called) would sometimes add or a few hours because of timezones, so it would end up incrementing the day. Theres probably a good solution to that problem, but gently caress it, I just use YYYY-MM-DD so I know it's the right date.

nbv4
Aug 21, 2002

by Duchess Gummybuns

Bonus posted:

What's a good PHP library for sending out emails? Just one at a time from a form, so no need for mass mailing.

mail()? doesnt get much simpler than that

nbv4
Aug 21, 2002

by Duchess Gummybuns
I have a PHP array with each item being an airport identifier. "KBOS", "KTEB", "KMIA", "MMIO", etc. These are wordwide airports, not just US airports. I want to get the longitude/latitude coordinates of each item. It's a long shot, but is there a tool that already does such a thing? I can probably swing together a function that crawls some other page for the info, but I don't want to waste my time if something already exists.

Once I get the longitude/latitude coordinates, I want to map them all on a map with lines connecting some of them. Whats a good tool for doing this? Would the Google Maps API be the only way to achieve this? I'd rather have it be a static image that can be saved.

nbv4
Aug 21, 2002

by Duchess Gummybuns

bt_escm posted:

I found this http://www.webservicex.com/airport.asmx and I was able to get a couple of coordinates for a few airports.

I think google maps would be ideal for this.

Thats not quite as comprehensive as I'd like. Anyways, I found airnav.com, which is 100% comprehensive for american airports, which is about as good and I'm going to find I'm afraid.

Now, I'm wondering, whats the best way to go about mining the data from the page? I'm looking around the web, but I'm not finding much on how to actually build a web crawler... Anyone know of any good resources/tools for doing something like this?

nbv4
Aug 21, 2002

by Duchess Gummybuns

Evil Angry Cat posted:

To be honest you're best off using Google Maps. If you notice that searching "KBOS" or "LAX" or "LGW" in Google Maps brings up the airport in question it's jut matter of using the API to get the latitude and longitude (or whatever information you're looking for). Much simpler than parsing a page of tables (which the airnav.com page is) to extract data.

The reason I wanted to use airnav is because the information is 100% reliable. Relying on Google hits just doesn't seem very robust to me. But anyways, for the hell of it I looked into using the google API, and so far the results I've gotten have been pretty good, so gently caress it, I'll just use google. I have one problem though: Here is the PHP function that I wrote that gets the coordinates and then puts them into the database:

code:
function crawl_google($airport)
	{
		$page = file_get_contents(
			"http://maps.google.com/maps/geo?q={$airport}&output=xml&key=ABQIAAAAtDznsRv92g_KZ0HK9XszwoT5A");
		
		$xml = simplexml_load_string($page);
		
		$location = $xml->Response->Placemark->address;		
		$coordinates = $xml->Response->Placemark->Point->coordinates;
		
		$sql = "INSERT INTO airports (`coordinates`, `location`, `identifier`) VALUES('$coordinates', '$location', '$airport')";
		
		print "$sql<br>\n";
		
		mysql_query($sql);
	
		return $location;
	}
There is a 3 or 4 second delay for the link to return the XML, which adds to to a lot when you have 500 airports to look up. When I load the page that ends up running this function, the page will just hang until it's 100% done, then display all the contents. What kind of voodoo am I going to have to perform to have it print out the stuff progressively, so the user doesn't think the site is down or something?

nbv4 fucked around with this message at 03:35 on May 26, 2008

nbv4
Aug 21, 2002

by Duchess Gummybuns
I want to add a feature on my site that outputs that data into a PDF file, so when the user print, it looks consistent and paged correctly. Anyone know of a good library or something that will do this?

nbv4
Aug 21, 2002

by Duchess Gummybuns
I'm trying to crawl a webpage using file_get_contents(), but it is giving me a 403 error. If I copy the exact same URL that the function is betting to a webbrowser, the page loads fine, but in PHP I get this error:

Warning: file_get_contents(http://gc.kls2.com/airport/HECA) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /var/www/logbook/classes/map_class.php on line 252

I assume the site owner has some anti-spam thing in place which is why I'm blocked. Is there any way around this? This particular function is only going to be ran once or twice a month, so its not like I'm going to be overloading the site's bandwidth...

nbv4 fucked around with this message at 06:38 on Jul 16, 2008

nbv4
Aug 21, 2002

by Duchess Gummybuns

jasonbar posted:

This worked for me - please only use it for good.

sweeeet, that worked. I won't be bad I promise. Bandwidth usage from this script will probably amount to a few hundred KB's per month.

nbv4
Aug 21, 2002

by Duchess Gummybuns
How do you add a indexed value to an array via indirection?

I have this:

code:
foreach(array(cat1, cat2, cat3), as $category)
{
   [...]

    $$category['xc_dual'] = $temp[0];

}

var_dump($cat1);

The cat1, cat2, etc. arrays are already created and have values. I need to add temp[0] to the end (or beginning, or wherever) and it must be INDEXED. With the above code all that comes out is the original array with no 'xc_dual'.

Whats odd is that I can change that line to:

code:
$$category[] = $temp[0];
and it works perfectly fine, but then it's indexed to "0". This is hosed up as hell.

nbv4
Aug 21, 2002

by Duchess Gummybuns
Oh I see, order of operations. I'm surprised it didnt bring up an error or something... Anyways, I guess a double array is my only option:

$times[$category]['xc_dual'] = $temp[0];

nbv4
Aug 21, 2002

by Duchess Gummybuns
I have a huge array that is filled with strings in the form of "ABC-DEF", "ABC-XYZ", "XYZ-ABC", etc.

I want to not only remove duplicates (which is very easy), but also remove any "reverse" duplicates. For instance, only one of "XYZ-ABC" and "ABC-XYZ" should exist. Each three letter "word" represents a start point and an end point in a line. I only need each line once, not its "backcourse". This seems like a very simple problem, but I can't think of a simple solution that doesn't involve tons of lines of code and large memory useage.

nbv4
Aug 21, 2002

by Duchess Gummybuns

KuruMonkey posted:

Wherever and however you are checking for a dupe, construct the inverse and check for "dupe OR inverse"

I'm not really "checking" for dupes, I'm just doing:

php:
<?
$line_array = array_values(array_unique($line_array));        
?>
Basically "removing the dupe" just means removing it from the array. The only way I can think of is to determine what the inverse of the current string is:

php:
<?
implode("-", array_reverse(explode("-", $line_string))))?>
then searching through the array, looking to see if that string is present. If it is, then remove it from the array. The only problem is the array search function is very memory intensive, especially when you're searching a 5000 item array 5000 times.

nbv4
Aug 21, 2002

by Duchess Gummybuns
I have a class that handles printing the DOCTYPE and headers, as well as the footer on each page. At the top of the class declaration, I have all these things defined like so:

php:
<?
class page {

    var $page;
    var $title;
    var $year;
    var $copyright;
    var $auth;
    var $style;
    var $auth_level;
    var $get_sec;
    var $get_sec_q;
        
    var $page_title;
    
    var $doctype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
        
    $meta_header = <<<EOF

        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                <head profile="http://www.w3.org/2005/10/profile">
                    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
                    <meta name="DESCRIPTION" content="stupid description goes here." />
                    <meta name="KEYWORDS" content="keywordz" />
EOF;
            
    var $advert = "";    
?>
Its giving me an error on the line where I define the meta header. Apparently the "EOF" thing is not allowed in the class declaration top part. What other options do I have here that don't include going through each line to escape the quotation marks? The meta header is going to be expanded to about three times the size and I just think it's dumb to have to escape quotation marks like that.

the php website suggests "nowdoc", but I'm using PHP 5.2.X, and those are only allowed in 5.3 and greater. :(

Adbot
ADBOT LOVES YOU

nbv4
Aug 21, 2002

by Duchess Gummybuns
I am having a hard time figuring out character encodings. I have a function that crawls a webpage that happens to be encoded in ISO-8859-1. Some text is lifted off that site and then ran through utf_encode() and then stored in a database. When I view the contents of that field in phpMyAdmin, it looks like this: "México", with a "A" with a squiggly line above it and a copyright logo instead of an "e" with an accent mark as how it looks on the original ISO-8859-1 page. The phpMyAdmin page is encoded in UTF-8, so I don't know what is happening. Is this caused by utf_encode() not working? What could be causing this?

The "collation" of the databse is "latin1_swedish_ci", could that be the problem? I think I remember messing with encoding a few months ago, and changing the collation didn't change anything. When I drawl the info from the database it works fine, with the accent mark displaying correctly, which gets me because the page I use to display the data is set to UTF-8 as well...

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply