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
Eararaldor
Jul 30, 2007
Fanboys, ruining gaming since the 1980's
I can't seem to find any tutorials on this, so figured I'd ask here.

Anyway I can filter a table of data by using a drop down in php?

Adbot
ADBOT LOVES YOU

wil
Mar 2, 2009
Eararaldor, I put together a code example for you, and commented it for the most part.


On your front end, (we'll call this index.html)
Include jquery.js and jquery.form.js.

Basically what the jquery.form.js will do is stop the submit event from going to the actual php script, and submit the post data through an AJAX call.

This is where the magic happens.

code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>Drop Down List Filter Demo for the goons at SA</title>	
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	
	<!-- Main stylesheet -->	
	<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" />
	<link rel="stylesheet" type="text/css" media="all" href="css/text.css" />
	<link rel="stylesheet" type="text/css" media="all" href="css/960.css" />
	<style type="text/css" media="all">
		body
		{
			background: #123;
			border-top: 5px solid #000;
			color: #fff;
			font-size: 11px;
			padding: 20px 0 40px;
		}

		a
		{
			color: #fff;
			text-decoration: none;
		}

		a:hover
		{
			text-decoration: underline;
		}

		h1
		{
			font-family: Georgia, serif;
			font-weight: normal;
			text-align: center;
		}

		h2
		{
			padding: 20px 0 0;
			text-align: center;
		}

		p
		{
			border: 1px solid #666;
			overflow: hidden;
			padding: 10px 0;
			text-align: center;
		}

		.container_12
		{
			margin-bottom: 20px;
		}
				
		table{
			border-collapse: collapse;
			width: 100%;
			line-height: 18px;
			border: 1px solid #eaeaea;
		}
		table tr td {
			padding: 8px;
			padding-bottom: 10px;
			padding-top: 12px;
			font-size: 11px;
			border-bottom: 1px solid #eaeaea;
		}
		table td.actions {
			background: #f7f7f7;
			width: 110px;
			border-left: 1px solid #eaeaea;
		}
		td.actions img{
				margin-right: 10px;
				margin-left: 10px;
		}
		table tr.highlight {
			background: #f7f7f7;
}
	</style>

	<script type="text/javascript" src="javascripts/jquery.js"></script>
	<script type="text/javascript" src="javascripts/jquery.form.js"></script>
	    <script type="text/javascript"> 
        // wait for the DOM to be loaded 
		$(document).ready(function() { 
			
			//this will load all of the records from the database intially
			$('#table_listing').load('processForm.php'); 
			
			// bind form using ajaxForm 
			$('#myForm').ajaxForm({ 
				// target identifies the element(s) to update with the server response 
				target: '#table_listing', 
		 
				// success identifies the function to invoke when the server response 
				// has been received; here we apply a fade-in effect to the new content 
				success: function() { 
					$('#table_listing').fadeIn('slow'); 
				} 
			}); 
		});
    </script> 
	
</head>
<body>
<h1>Drop Down List Filter Demo for the goons at SA</h1>
<p>A working example?</p>
	<div class="container_12">
		<form id="myForm" name="myForm" action="processForm.php" method="POST">
				<div class="grid_4">
					<select id="myDropDown" name="myDropDown">
						<option value="none">None</option>
						<option value="Apples">Apples</option>
						<option value="Oranges">Oranges</option>
						<option value="Grapes">Grapes</option>
					</select>
					<input type="submit" value="Filter Records"/>
				</div>
				<div id="table_listing" class="grid_8"></div>
				<div class="clear"></div>
		</form>
	</div>

</body>
</html>
Now, as you can see in this example we are posting our form data to processForm.php

Here is an example processForm.php file I wrote for you.

code:
<?php

/* This is where you would query your database 
   to return the correct data to display in your table
*/
//setup the connection to the database


$conn = mysql_connect("localhost", "sqluser", "sqlpass"); //REPLACE with your credentials
mysql_select_db("yourdbase"); //replace with your database


//this is the field we set on form, and it is being populated by ajax when the form is submit.
$filter = $_POST['myDropDown'];

if(($filter != null) && ($filter != "none")){
	//this is your query, make it as simple or complex as needed. $filter is set from the post data.
	$sql = "SELECT * FROM `fruits` WHERE `fruit_type` = '$filter';"; 
	
	//execute the query, based on the $sql string
	$result = mysql_query($sql) or die(mysql_error());  
	echo('<h3>Filtering by: '.$filter.'</h3>');

} else {
	// this query will return all fruits from your database
	$sql = "SELECT * FROM `fruits`;"; 
	//execute the query, based on the $sql string
	$result = mysql_query($sql) or die(mysql_error());
	echo('<h3>Displaying all fruits.</h3>');
}

//This is the table template that displays the results (initially and when the filter is active)
echo '<table>';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>Name</td>';
echo '<td>Fruit Type</td>';
echo '</tr>';
while ($row = mysql_fetch_assoc($result)) {
	echo '<tr>';
    echo '<td>'. $row['id'] .'</td>';
    echo '<td>'.$row['name'] .'</td>';
    echo '<td>'.$row['fruit_type'].'</td>';
	echo '</tr>';
}
echo '<table>';
?>
Here is the example data base schema if you would like to try to expand on this example

code:
DROP TABLE IF EXISTS `fruits`;
CREATE TABLE IF NOT EXISTS `fruits` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `fruit_type` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `fruits`
--

INSERT INTO `fruits` (`id`, `name`, `fruit_type`) VALUES
(1, 'Red Delicious Apples', 'Apples'),
(2, 'Juicy Orange Oranges', 'Oranges'),
(3, 'Great Green Grapes', 'Grapes');
Of course you will want to modify the fields, etc to match your own needs, but this should be sufficient to get you started.

http://www.littlesparrows.com/sa/dropfilter.rar has the code example, sql dump, and the sample style sheet(using 960.gs css framework)

http://www.littlesparrows.com/sa/dropfilter is the demo url for you to see all of it in action.

I make no guarantees that this is the best (or even secure) way of doing this. I simple just tossed it together for you really fast.

Hope it helps.

wil fucked around with this message at 21:27 on Mar 9, 2009

KarmaticStylee
Apr 21, 2007

Aaaaaughibbrgubugbugrguburgle!
Question:

I am working on a site where I need a user to confirm their information... when they click the confirm button, I want it to send an e-mail to the site owner + post to authorize.net to begin the billing process. What is the best way for these two actions to be initiated from 1 button push? (since obviously the two actions are processed on different pages)

KuruMonkey
Jul 23, 2004

KarmaticStylee posted:

Question:

I am working on a site where I need a user to confirm their information... when they click the confirm button, I want it to send an e-mail to the site owner + post to authorize.net to begin the billing process. What is the best way for these two actions to be initiated from 1 button push? (since obviously the two actions are processed on different pages)

You need to have a single script which handles the form (set the action= on the form with the button to this script).

That script then validates the form input, and if its all ready to go, sends the mail. (mail() function, or however you want). Then it either uses header('Location: ...') to send the user to the authorize.net page, or uses cURL to make the http request. (depends what you're doing with it / whether the user needs to see it).

If there's a problem with the data, the script uses header() to redirect back to the form page, possibly with some error info added to the URI.

In short; php script != page user sees.

KuruMonkey fucked around with this message at 23:01 on Mar 9, 2009

KarmaticStylee
Apr 21, 2007

Aaaaaughibbrgubugbugrguburgle!

KuruMonkey posted:

You need to have a single script which handles the form (set the action= on the form with the button to this script).

That script then validates the form input, and if its all ready to go, sends the mail. (mail() function, or however you want). Then it either uses header('Location: ...') to send the user to the authorize.net page, or uses cURL to make the http request. (depends what you're doing with it / whether the user needs to see it).

If there's a problem with the data, the script uses header() to redirect back to the form page, possibly with some error info added to the URI.

In short; php script != page user sees.

$host = "https://Simplecheckout.authorize.net";
$path = "/payment/CatalogPayment.aspx";

$data = "LinkId=1572e46b-fc81-5e7a-95b7-e3742cdegdbd";
$data = urlencode($data);
header('POST '.$path);
header('Host: '.$path);
header('Content-type: x-ww-form-urlencoded');
header('Content-length: ' .strlen($data));
header($data);


I get a 500 INTERNAL ERROR.. what am i doing wrong

KuruMonkey
Jul 23, 2004
Ermmm, I think this is the problem...

You're sending a POST back to the user's browser, which isn't valid.

header() sets up http RESPONSE headers, POST is an http REQUEST header.

requests go to servers, responses go to user agents (browsers).

Your attempt to send a request to a user agent is resulting in a 500, because sending a request when a header is expected is...an internal server error

You need to use header('Location: ...') that causes the browser to load the given URL

I don't think you can send a POST to the browser hoping it will pipe it through to the given URL for you? I also don't think you can send POST variables through a header() call, you have to use GET.

There may be a more involved solution to your particular requirements, if so I'm not sure what it is.

(someone is going to tell me I'm wrong now...)

KarmaticStylee
Apr 21, 2007

Aaaaaughibbrgubugbugrguburgle!
Well I'm hoping I can just send extra data to authorize since they send order confirmation emails out when a transaction occurs anyway... still, wouldn't mind figuring out how to use headers to post

KuruMonkey
Jul 23, 2004
Try turning your problem on its head...

You could use javascript to trigger the email by using XMLHttpRequest in an onSubmit event; request a PHP script that does the email. (problem being that, as always, javascript can be disabled)

Or...

Rely on the info that comes back from authorize.net to notify the admin, not the form submission. (i.e. notification of success not attempt)

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss
What is the best way to detect if the end-user is using IE within PHP (not the html trick, but just PHP)

I am doing this so far

if (stristr((string)$_SERVER['HTTP_USER_AGENT'],'MSIE')) {...}

LP0 ON FIRE
Jan 25, 2006

beep boop
I've copied and resized a picture before in PHP, but for some reason the image is resizing the correct size but comes out all black.

php:
<?php

define('filename'"testResize/testSource.png");

define('sizeIncreasePercent'5);

// Get new sizes
list($width$height) = getimagesize(filename);
define('newwidth'$width sizeIncreasePercent);
define('newheight'$height sizeIncreasePercent);

// Load
define('thumb'imagecreatetruecolor(newwidthnewheight));
define('source'filename);

// Resize
imagecopyresized(thumbsource0000newwidthnewheight$width$height);

// Output
imagepng(thumb"testResize/test.png");;

?>

gibbed
Apr 10, 2006

What the gently caress? Why are you using define that way? :suicide:

Edit: also your problem is probably the fact that ImageCopyResized wants an image resource not a filename.
Edit 2: drop the ImagePNG and you will probably see lots of warnings/errors.

LP0 ON FIRE
Jan 25, 2006

beep boop

gibbed posted:

What the gently caress? Why are you using define that way? :suicide:

Edit: also your problem is probably the fact that ImageCopyResized wants an image resource not a filename.
Edit 2: drop the ImagePNG and you will probably see lots of warnings/errors.

I'm making constants for security reasons when I add onto the code. What exactly do you mean by image resource? Sorry for the dumb question, I just have no idea what you mean by this.

I don't get any warnings or errors if I drop imagepng.

gibbed
Apr 10, 2006

awdio posted:

I'm making constants for security reasons when I add onto the code. What exactly do you mean by image resource? Sorry for the dumb question, I just have no idea what you mean by this.

I don't get any warnings or errors if I drop imagepng.

ImageCopyResized

Note the second argument. You're passing a string when it wants a resource, you'll want to use ImageCreateFromPNG() or equivilent to load the image you want to resize.

You certainly should have gotten warnings or errors with your code, is your error reporting off?

Where did you get the idea that constants somehow magically affect security?

LP0 ON FIRE
Jan 25, 2006

beep boop

gibbed posted:

ImageCopyResized

Note the second argument. You're passing a string when it wants a resource, you'll want to use ImageCreateFromPNG() or equivilent to load the image you want to resize.

You certainly should have gotten warnings or errors with your code, is your error reporting off?

Where did you get the idea that constants somehow magically affect security?

Excellent! Changing it to this: define('source', imagecreatefrompng(filename)); worked! It's exactly the effect I need. No softness or blurring. I don't have error reporting off.. I don't know why it didn't give me errors. Everything is fine now though, thank you.

The script may be used in a form, and I just think it's good practice for data that isn't going to change throughout the script to use a constant. I don't have exact plans how I'm going to change this code, but I know the constants can remain constants without a problem. I read about the importance of using constants in a form as a security measure here: http://dev.mysql.com/tech-resources/articles/php-security-ch02.pdf

LP0 ON FIRE fucked around with this message at 07:43 on Mar 10, 2009

gibbed
Apr 10, 2006

I have no problem with newwidth/newheight being define()s (though I personally wouldn't do that).

But the image resources (thumb, source) should definitly not be constants.

Zorilla
Mar 23, 2005

GOING APE SPIT
Also, constants are almost always in all-caps.

cannibustacap posted:

What is the best way to detect if the end-user is using IE within PHP (not the html trick, but just PHP)

I am doing this so far

if (stristr((string)$_SERVER['HTTP_USER_AGENT'],'MSIE')) {...}

Sounds about right. This is what Google tells me, and it looks like it's functionally identical:
php:
<?
if (preg_match("/MSIE/i", $_SERVER["HTTP_USER_AGENT"])) {
    // stuff
}?>

Eararaldor
Jul 30, 2007
Fanboys, ruining gaming since the 1980's

wil posted:

Eararaldor, I put together a code example for you, and commented it for the most part.


On your front end, (we'll call this index.html)
Include jquery.js and jquery.form.js.

Basically what the jquery.form.js will do is stop the submit event from going to the actual php script, and submit the post data through an AJAX call.

This is where the magic happens.

code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>Drop Down List Filter Demo for the goons at SA</title>	
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	
	<!-- Main stylesheet -->	
	<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" />
	<link rel="stylesheet" type="text/css" media="all" href="css/text.css" />
	<link rel="stylesheet" type="text/css" media="all" href="css/960.css" />
	<style type="text/css" media="all">
		body
		{
			background: #123;
			border-top: 5px solid #000;
			color: #fff;
			font-size: 11px;
			padding: 20px 0 40px;
		}

		a
		{
			color: #fff;
			text-decoration: none;
		}

		a:hover
		{
			text-decoration: underline;
		}

		h1
		{
			font-family: Georgia, serif;
			font-weight: normal;
			text-align: center;
		}

		h2
		{
			padding: 20px 0 0;
			text-align: center;
		}

		p
		{
			border: 1px solid #666;
			overflow: hidden;
			padding: 10px 0;
			text-align: center;
		}

		.container_12
		{
			margin-bottom: 20px;
		}
				
		table{
			border-collapse: collapse;
			width: 100%;
			line-height: 18px;
			border: 1px solid #eaeaea;
		}
		table tr td {
			padding: 8px;
			padding-bottom: 10px;
			padding-top: 12px;
			font-size: 11px;
			border-bottom: 1px solid #eaeaea;
		}
		table td.actions {
			background: #f7f7f7;
			width: 110px;
			border-left: 1px solid #eaeaea;
		}
		td.actions img{
				margin-right: 10px;
				margin-left: 10px;
		}
		table tr.highlight {
			background: #f7f7f7;
}
	</style>

	<script type="text/javascript" src="javascripts/jquery.js"></script>
	<script type="text/javascript" src="javascripts/jquery.form.js"></script>
	    <script type="text/javascript"> 
        // wait for the DOM to be loaded 
		$(document).ready(function() { 
			
			//this will load all of the records from the database intially
			$('#table_listing').load('processForm.php'); 
			
			// bind form using ajaxForm 
			$('#myForm').ajaxForm({ 
				// target identifies the element(s) to update with the server response 
				target: '#table_listing', 
		 
				// success identifies the function to invoke when the server response 
				// has been received; here we apply a fade-in effect to the new content 
				success: function() { 
					$('#table_listing').fadeIn('slow'); 
				} 
			}); 
		});
    </script> 
	
</head>
<body>
<h1>Drop Down List Filter Demo for the goons at SA</h1>
<p>A working example?</p>
	<div class="container_12">
		<form id="myForm" name="myForm" action="processForm.php" method="POST">
				<div class="grid_4">
					<select id="myDropDown" name="myDropDown">
						<option value="none">None</option>
						<option value="Apples">Apples</option>
						<option value="Oranges">Oranges</option>
						<option value="Grapes">Grapes</option>
					</select>
					<input type="submit" value="Filter Records"/>
				</div>
				<div id="table_listing" class="grid_8"></div>
				<div class="clear"></div>
		</form>
	</div>

</body>
</html>
Now, as you can see in this example we are posting our form data to processForm.php

Here is an example processForm.php file I wrote for you.

code:
<?php

/* This is where you would query your database 
   to return the correct data to display in your table
*/
//setup the connection to the database


$conn = mysql_connect("localhost", "sqluser", "sqlpass"); //REPLACE with your credentials
mysql_select_db("yourdbase"); //replace with your database


//this is the field we set on form, and it is being populated by ajax when the form is submit.
$filter = $_POST['myDropDown'];

if(($filter != null) && ($filter != "none")){
	//this is your query, make it as simple or complex as needed. $filter is set from the post data.
	$sql = "SELECT * FROM `fruits` WHERE `fruit_type` = '$filter';"; 
	
	//execute the query, based on the $sql string
	$result = mysql_query($sql) or die(mysql_error());  
	echo('<h3>Filtering by: '.$filter.'</h3>');

} else {
	// this query will return all fruits from your database
	$sql = "SELECT * FROM `fruits`;"; 
	//execute the query, based on the $sql string
	$result = mysql_query($sql) or die(mysql_error());
	echo('<h3>Displaying all fruits.</h3>');
}

//This is the table template that displays the results (initially and when the filter is active)
echo '<table>';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>Name</td>';
echo '<td>Fruit Type</td>';
echo '</tr>';
while ($row = mysql_fetch_assoc($result)) {
	echo '<tr>';
    echo '<td>'. $row['id'] .'</td>';
    echo '<td>'.$row['name'] .'</td>';
    echo '<td>'.$row['fruit_type'].'</td>';
	echo '</tr>';
}
echo '<table>';
?>
Here is the example data base schema if you would like to try to expand on this example

code:
DROP TABLE IF EXISTS `fruits`;
CREATE TABLE IF NOT EXISTS `fruits` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `fruit_type` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `fruits`
--

INSERT INTO `fruits` (`id`, `name`, `fruit_type`) VALUES
(1, 'Red Delicious Apples', 'Apples'),
(2, 'Juicy Orange Oranges', 'Oranges'),
(3, 'Great Green Grapes', 'Grapes');
Of course you will want to modify the fields, etc to match your own needs, but this should be sufficient to get you started.

http://www.littlesparrows.com/sa/dropfilter.rar has the code example, sql dump, and the sample style sheet(using 960.gs css framework)

http://www.littlesparrows.com/sa/dropfilter is the demo url for you to see all of it in action.

I make no guarantees that this is the best (or even secure) way of doing this. I simple just tossed it together for you really fast.

Hope it helps.

Wow thats more than I actually hoped for. Thanks for your time this will help alot!

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



cannibustacap posted:

What is the best way to detect if the end-user is using IE within PHP (not the html trick, but just PHP)

I am doing this so far

if (stristr((string)$_SERVER['HTTP_USER_AGENT'],'MSIE')) {...}

http://browsers.garykeith.com/downloads.asp

The best way is to have someone else figure it out :)

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss

Munkeymon posted:

http://browsers.garykeith.com/downloads.asp

The best way is to have someone else figure it out :)

Thanks, I'll dig through that. At first, it seems a big non trivial though.


By the way, what do you guys think of the $_SESSION variable? Does that work when a user has cookies disabled? Are there certain instances when you do not want to use $_SESSION?

On PHP 5.2.3 (I believe)

TreFitty
Jan 18, 2003

I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc.

MononcQc
May 29, 2007

cannibustacap posted:

By the way, what do you guys think of the $_SESSION variable? Does that work when a user has cookies disabled? Are there certain instances when you do not want to use $_SESSION?

On PHP 5.2.3 (I believe)

$_SESSION still uses cookies unless you explicitely have it put the SID in the url. What PHP does is kind of abstract away the need to manage the SID, Time to live and where to put the data (and more) and instead stores it all for you in static files. That static file is associated with the session ID which has been stored in the cookie or the url.

They're nice if you don't know how cookies and session management work, but if you have the time to do it, you'd be better off learning how to do it by hand and managing it all in a database. You gain more control on what you do and can use the data outside of PHP if it's what you want (ie.: compile stats, distribute sessions over many servers, etc).

wil
Mar 2, 2009

TreFitty posted:

I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc.



From my personal experience, CakePHP is the easiest framework to learn and utilize.

wil fucked around with this message at 23:43 on Mar 11, 2009

gibbed
Apr 10, 2006

TreFitty posted:

I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc.
They all have their unique taste and have their own advantages and disadvantages. Use whatever you like.

In that regard, another good option that isn't in the OP is Agavi.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

TreFitty posted:

I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc.

CodeIgniter. But as gibbed said, your needs will dictate what you use, because they all have strengths and weaknesses.

If you are just learning PHP, I'd suggest not using one for a while, until you notice you are writing the same bits of code (DB access, login handling, etc.) over and over. Then it's time to shop for a framework. Sure, you can walk into the dealership and buy a new car, but if you tinker with that old junker and get it running yourself, you'll know what's going on under the hood.

KuruMonkey
Jul 23, 2004
I'm not going to say you're wrong, Lumpy. But the other way to look at is that a framework can act like the stabiliser wheels on a bike while you learn to ride.

Also you can pick apart a framework to see how they've done the fiddly but important tasks like logins and db access...

I would second CodeIgniter as a good framework for learning from, as it lets you use approximately none of its features if thats what you want (well, except the routing)

Despite having personally jumped ship to Kohana, I'd advise against learners using it because apparently they think writing docs is a very low priority indeed, which CI are impressively more focussed on.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

KuruMonkey posted:

I'm not going to say you're wrong, Lumpy. But the other way to look at is that a framework can act like the stabiliser wheels on a bike while you learn to ride.


As I was typing up my reply, part of my brain was saying "yeah, but think of all the time you could have / would have saved had you started using one right away." I stuck with my guns though, because say you do use framework X to learn. Later on, you interview for a job that doesn't use one, or some hot chick wants you to fix her image gallery script for her pretty pony website, and will pay in sex but it doesn't use the framework you learned PHP on. You now have to spend the time learning stuff outside your comfort zone which can be harder once you've established a habit... "Wait, there's a *different* way to make DB connections other than $this->load->db() ???"

If you learn with training wheels, and there is no incentive to ever take them off, if somebody presents you with a new bike that doesn't have them, you may be baffled. I do see your point, and I don't think learning *with* a framework is bad by any means, but having the motivation to go outside of it and look through it's source and so forth would be essential in my opinion.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

TreFitty posted:

I'm learning PHP and was wondering: can you guys recommend any of the frameworks in the original post? I mean, does one completely outclass the other? Which is better for what? etc.

Don't use a framework, you don't need one with PHP.

supster
Sep 26, 2003

I'M TOO FUCKING STUPID
TO READ A SIMPLE GRAPH

fletcher posted:

Don't use a framework, you don't need one with PHP.

I think this is the best way to get started. Except don't just copy and paste those files, use them as a basis for writing your own.

gibbed
Apr 10, 2006

And for the love of god use .php as the extension, not .inc, or at least .inc.php.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

gibbed posted:

And for the love of god use .php as the extension, not .inc, or at least .inc.php.

How will others learn from your mistakes if that can't view your raw, unparsed code via the web? :eek:

Eararaldor
Jul 30, 2007
Fanboys, ruining gaming since the 1980's
Got another interesting question for you goons...

In ASP.NET, theres a ASP.NET Calendar Control function. I was just wondering if theres something I can use that's similar in php?

I'd rather not trust the user typing it out themselves, so an actual calendar popping up would be awesome.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Eararaldor posted:

Got another interesting question for you goons...

In ASP.NET, theres a ASP.NET Calendar Control function. I was just wondering if theres something I can use that's similar in php?

I'd rather not trust the user typing it out themselves, so an actual calendar popping up would be awesome.

The PHP language itself does not include any libraries of GUI elements. You'll need to find a 3rd party javascript thing to do this.

Postess with the Mostest
Apr 4, 2007

Arabian nights
'neath Arabian moons
A fool off his guard
could fall and fall hard
out there on the dunes
JQuery has a UI package that has been pretty nice and I believe includes a calendar. I've been using the dialog, draggable and droppable bits and they've amazingly easy and reliable across browsers.

Vedder
Jun 20, 2006

Hi there

I have only been dabbling in PHP for around a month and my only other experience in this sort of stuff is using ASP.NET. I am converting our companies static website into a more manageable (for me, as I will be the one updating it), streamlined PHP version. Everything is going fine apart from the question I am about to ask you.

I have finished the staff profile pages which has cut out twenty odd static pages and would like to do the same with our news and events page. At present I have a number of Word documents that staff make and at present the only way to do this is to code each page. I have set up a news table in MySQL and and a foreign key linking it to the staff table which all works fine. The only trouble is I receive some Word documents with all sorts of formatting, bold text here, underlining here etc and was wondering whats the best way to insert that data?

I have read up on htmlentities() and while that has worked great for things like pound signs and quotations there doesn't seem to be one for bold, italic, bullet points etc..

What is the best way to do this? I understand for some I could simply add the HTML tags in the textpad but I imagine this is a bit of a scummy way of doing things. Am I better creating some sort of input page for this data as the way I am inserting data into MySQL at present is a bit primitive. Any help appreciated.

wil
Mar 2, 2009

Eararaldor posted:

Got another interesting question for you goons...

In ASP.NET, theres a ASP.NET Calendar Control function. I was just wondering if theres something I can use that's similar in php?

I'd rather not trust the user typing it out themselves, so an actual calendar popping up would be awesome.

Check out http://jqueryui.com/demos/datepicker/

If you like it I can write a quick little tutorial on how to implement it using PHP/Ajax.

Eararaldor
Jul 30, 2007
Fanboys, ruining gaming since the 1980's

wil posted:

Check out http://jqueryui.com/demos/datepicker/

If you like it I can write a quick little tutorial on how to implement it using PHP/Ajax.

Funny you should mention that. I was actually checking it out but was a little miffed as to how I actually implement it.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

Vedder posted:

[...]The only trouble is I receive some Word documents with all sorts of formatting, bold text here, underlining here etc and was wondering whats the best way to insert that data?

I have read up on htmlentities() and while that has worked great for things like pound signs and quotations there doesn't seem to be one for bold, italic, bullet points etc..

What is the best way to do this? I understand for some I could simply add the HTML tags in the textpad but I imagine this is a bit of a scummy way of doing things. Am I better creating some sort of input page for this data as the way I am inserting data into MySQL at present is a bit primitive. Any help appreciated.

It was a neverending pain in the rear end for me in that situation. Generally I'd use Word's Export to HTML (different from "Save as HTML"), then HTML Tidy, then manually fix whatever goofiness remained, then grab the body of the page and throw it into the CMS. There's also "antiword" for Linux which extracts text from Word docs (I don't think anything post-Word 97), but it also strips formatting so you'd have to reapply it all over again.

Making an input page is a good idea in theory, but if people are using Word to write for the web, it's guaranteed that they will just copy from Word and then paste into the form, which leads to all sorts of misery with the curly quotes and formatting. Things like FLK and TinyMCE just exacerbate the problem, because they look like Word so people expect them to actually be Word. I hate to say it, but if you have the power to make suggestions you might want to get contributors to use a WYSIWYG HTML editor rather than Word. You'll still have to clean it up, but at least it'll arrive with the entities already done and no wacky "mso:normal" sort of tags in it.

eHacked
Sep 30, 2003

CONGRATULATIONS!!! YOU ARE THE 6,127,436,218TH PERSON TO VIEW THIS USELESS POST. CLICK TO CLAIM YOUR PRIZE!!!
How do I create a dynamically-generated file that prompts a user to download it?

Say I have a form with 10 fields, once the user submits the form the file gets generated depending on the form's information and the user is prompted to download this file... only the file isn't actually on the server.

Sort of like how gallery generators make the user's list but I don't think the file is ever actually saved to the server.

Thanks!

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


eHacked posted:

How do I create a dynamically-generated file that prompts a user to download it?

Say I have a form with 10 fields, once the user submits the form the file gets generated depending on the form's information and the user is prompted to download this file... only the file isn't actually on the server.

Sort of like how gallery generators make the user's list but I don't think the file is ever actually saved to the server.

Thanks!

Set the header to attachment and just output what you want them to download.

Adbot
ADBOT LOVES YOU

eHacked
Sep 30, 2003

CONGRATULATIONS!!! YOU ARE THE 6,127,436,218TH PERSON TO VIEW THIS USELESS POST. CLICK TO CLAIM YOUR PRIZE!!!

duz posted:

Set the header to attachment and just output what you want them to download.

this:

code:
            header( "Content-Disposition: attachment; filename=\"export.txt\"" );
            echo $fl;
            exit( );
?

That seems way too simple.

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