Jump to content

seran128

Members
  • Posts

    4
  • Joined

  • Last visited

seran128's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. seran128

    PHP Classes

    could you take my example and code that the way it should be. I am having a problem with the syntax
  2. seran128

    PHP Classes

    OK what I want to do is create a class that I can include on my other pages, call function from that class and return those resluts to the calling page. Any references to online materials on php classes would be great!My code should be something like;class_db.php class db(){//Top level db connectionvar $db_name="db_name"; var $db_host="localhost";var $db_user="db_user";var $db_password="db_password";$connection=mysql_connect($db_host,$db_user,$db_password) or die("I Couldn't connect"); $db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database");function getlist($inTable){$sql="select * from $inTable order by ID"; $result=mysql_query($sql,$connection) or die(mysql_error());//I need to return my $result here but don't know how} function updatelist($inTable,$description,$id){ $sql="update $inTable set description='$description' where regionId='$id'"; $result=mysql_query($sql,$connection) or die(mysql_error()); //I need to return my $result here but don't know how} function deletelist($inTable,$id){ $sql="delete from $inTable where regionId='$id'"; $result=mysql_query($sql,$connection) or die(mysql_error()); //I need to return my $result here but don't know how}//also need to close any dbconnection but don't know how//end the class}page.phpinclude("class_db.php");.......<? getlist(my_table)$i = 0;//Need to return the output from the function so the following line can use it.while($row=mysql_fetch_array($result)) { $i++;echo "<tr class=\"d".($i & 1)."\">";?> ....other HTML code Is Here........<? } ?>
  3. seran128

    Mysql Function

    would my code look like?class db{ var $msa; function db($host,$user,$pass,$db){ $this->msa = mysql_connect($host,$user,$pass); if(!($this->msa )){ die("could not connect!<br/>".mysql_error()); } @mysql_select_db($db) or die(mysql_error()); }function mysqllist1($inTable1){$table = $inTable;$varClass->query("select * from $table order by ID"); } function mysqllist2($inTable2){$table = $inTable;$varClass->query("select col1, col5, col7 from $table order by ID"); } }Then how would I pass the results back to my other page?Would I still need to call the functions in the class likepage.php......<? mysqllist("my_tableName"));$i = 0;while($row=mysql_fetch_array($result)) { $i++;echo "<tr class=\"d".($i & 1)."\">";?> ...............HTML CODE HERE...............<? } ?>
  4. seran128

    Mysql Function

    ok I want to create a function for each type of sql call I do to the Mysql database. Something likedatabase.php<?function mysqlconnection(){ $db_name="db_name"; $db_host="localhost"; $db_user="db_user"; $db_password="db_password"; $connection=mysql_connect($db_host,$db_user,$db_password) or die("I Couldn't connect"); $db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database");}function mysqllist($inTable){ mysqlconnection(); $table = $inTable; $sql="select * from $table order by ID"; $result=mysql_query($sql,$connection) or die(mysql_error()); } other functions here reusing the ...........mysqlconnection();..........?>Then I want to call these functions in my other pages likepage.php...... <? mysqllist("my_tableName")); $i = 0; while($row=mysql_fetch_array($result)) { $i++; echo "<tr class=\"d".($i & 1)."\">"; ?> ...............HTML CODE HERE............... <? } ?>
×
×
  • Create New...