Jump to content

Archived

This topic is now archived and is closed to further replies.

turbocueca

Classes and Objects

Recommended Posts

Hello people, long time no see. I've been studying some manuals of PHP, but there was one thing I didn't understand, what are classes and objects? Can someone please explain to me?

Share this post


Link to post
Share on other sites
Here's how I interpret each...

-A [b]class[/b] is a collection of variables and functions that operate on those variables.

-An [b]object[/b] is an instance of classes that group data and relevant methods together.

I hope this helps in deciphering it all out.

Share this post


Link to post
Share on other sites
Its all important because it is the structure in which PHP functions and are built.

Here's a better way of looking at it... in a general sense... your "Objects" are like your generals in an army who know exactally everything that is going on... they in turn command the "Classes" (aka. your squad leaders) to do their bidding... and the functions and variables to do the true dirty work (aka your grunts/privates).

Its all a higher-archy that works together to get the job done.

Share this post


Link to post
Share on other sites
Try this one out...

[a href=\"http://www.phpfreaks.com/quickcode/Basic-MySQL-Search/12.php\" target=\"_blank\"]http://www.phpfreaks.com/quickcode/Basic-MySQL-Search/12.php[/a]

Always check out the free code on this site... alot of it is very powerful

Share this post


Link to post
Share on other sites
Any other questions... I think this is up my alley of expert-ezz, lol

Share this post


Link to post
Share on other sites
whats this? :

Parse error: parse error, unexpected '\"' in /home/www/infocenter.awardspace.com/inter/ps2ub/search.php on line 50

[code]$sql = mysql_query("SELECT name, work_status FROM usbextreme WHERE name LIKE "" . $_POST['query'] . "" OR work_status LIKE "" .$_POST['query'] . """) or die (mysql_error());[/code]

Note: I did the first way and mysql said something about the syntax, then I tried with the way justin16l told and it gave this error.

Share this post


Link to post
Share on other sites
ok understanding concepts is my stronger suit right now and the coding follows after that. But I'll take a shot in the dark with this one.

I don't understand why your trying to limit the mysql_query with the $_POST command. If your trying to limit the query from one page to another it should be using the $_GET command. I don't see how the $_POST will limit your query of the database.

I'm not sure the solution, but this should go into a new topic post if you want this one answered and you might want to put more code up than just that small smidget so people can understand what the code is trying to do. Sorry i couldn't help, I'm better at the concepts of how php works than the detailed coding.

Share this post


Link to post
Share on other sites
Your problem stems from all the double quotes "". Also, naming the returned value from a mysql_query() $sql is very misleading. If successfull mysql_query will return a result resource, on failure it will return a bool false. Naming it something like $result is much more suitable.
[code]
$result = mysql_query("SELECT name, work_status FROM usbextreme WHERE name LIKE '". $_POST['query']. "' OR work_status LIKE '". $_POST['query']. '") or die (mysql_error());
[/code]
Not sure what titangf was talking about in his post.... there is no LIMIT clause in your sql statement.

Share this post


Link to post
Share on other sites
Sorry turbo, didn't mean to mislead you. Well... I guess you learn something new everyday...

didn't realize that mysql_query had no limits... Guess i'll have to just go with my motto with this one...


Even the true masters of their times only claim to be students.

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]didn't realize that mysql_query had no limits[/quote]
Sorry, you've lost me. You can limit results by using a LIMIT clause in your sql statement, but that has nothing to do with the php function mysql_query().

Share this post


Link to post
Share on other sites
no worries... I think i'm a little lost too... lol

Share this post


Link to post
Share on other sites
Here is what happen:

[a href=\"http://infocenter.awardspace.com/inter/ps2ub/search.php\" target=\"_blank\"]http://infocenter.awardspace.com/inter/ps2ub/search.php[/a]

[code]<html>
<head><title>ola</title></head>
<body>
<form method="POST" action="">
Search Word: <input type="text" name="query">
<input type="SUBMIT" value="Search!">
</form>

<?
include 'db.php';
// PHP Search Script

$result = mysql_query("SELECT name, work_status FROM usbextreme WHERE name LIKE '". $_POST['query']. "' OR work_status LIKE '". $_POST['query']. '"') or die (mysql_error());

while(list($column1, $column2)=mysql_fetch_array($result)){

echo "Result: $column1, $column2 <br />";

}
?>
</body>
</html>[/code]

Share this post


Link to post
Share on other sites

×

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.