Hi

I would be greatfull is somebody could help me. Ok vut a long story short I am trying to create a website which has the facility of a database driven banner system, on either left and right hand side of any page. the purpose of this is so that any banner can be displayed on either page or either side.

Ok, my sql tables are:

table menu

colums: id, name, lnk,visible

table banner

columns: id,txt,pic,alnk,lnkfile,height,banner_position,ord,lnk_tblmenuid,vis

the unique identifier between both tables is menu.id and lnk_tblmenuid

i have done this hoping to set it up as a one to many relationship i.e one menu to many banners. I have spent all day trying to figer it out. im not too sure if this is the way I should be doing this. please advise

many thanks

if somebody could come up with a query that would be great thanks

Recommended Answers

All 11 Replies

May I ask why you're using two tables to display only one banner?

you want an array of banners dependent on the menu name in table menu.
Do you want to rotate them on your page or only display one, once per menu call?

hi, no i would like to control which order the banners are viewed on the page i specify, and control which side they appear on, can you help?

yeah, I almost have your backend built but not tested. how about I throw some code at you and you tell me if it works as expected so far.
If you have never used classes, I am really, really big on object oriented programming. I have a 'class' generator that is built straight off mysql tables so I have generated some code for you but I am cleaning it up before showing, warning it may be overwhelming, but that is not my intent... just maybe showing you a different way to look at your problem that said... you need to define your database variables user pass, db name etc... in the DEFINE fields near the top of the class. here are two classes, simply named menu.class.php and banner.class.php The code is untested. the insert update delete statements can all be ignored for now. I based all of this of the fact that you would be passing the id field from the menu table into a call. Finally, here is some code skip to line 270 in menu and read the select_by_id call.

<?php
// begin generated class -->
/*
*
* -------------------------------------------------------
* CLASSNAME:        menu
* GENERATION DATE:  05.08.2011
* CLASS FILE:       C:\wamp\www\PHP_LIB\sql_class_generator/generated_classes/menu.class.php
* FOR MYSQL TABLE:  menu
* FOR MYSQL DB:     test
* -------------------------------------------------------
* CODE GENERATED BY:
* MY PHP-MYSQL-CLASS GENERATOR
* from: >> www.voegeli.li >> 
* CLASS MODIFIED AND EXTENDED BY:
* dmd
* -------------------------------------------------------
*
*/
define(DB_HOST,'localhost');
define(DB_USER,'root');
define(DB_PASS,'');
define(DB_BASE,'test');
// **********************
// CLASS DECLARATION
// **********************
// class : begin
class menu { 
// **********************
// ATTRIBUTE DECLARATION
// **********************
	var $id;   // KEY ATTR. WITH AUTOINCREMENT
	var $name;   // (normal Attribute)
	var $link;   // (normal Attribute)
	var $visible;   // (normal Attribute)

// **********************
// CONSTRUCTOR METHOD
// **********************	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- constructor
	* @param - menu
	* @return - Instance of $class
	* @vers	- 1
	* @Mod - 
	**/
	function menu() {

	}
// **********************
// GETTER METHODS
// **********************

	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_id()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_id() {
		return $this->id;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_name()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_name() {
		return $this->name;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_link()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_link() {
		return $this->link;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_visible()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_visible() {
		return $this->visible;
	}
	// **********************
	// SETTER METHODS
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_id($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_id($val) {
		$this->id = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_name($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_name($val) {
		$this->name = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_link($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_link($val) {
		$this->link = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_visible($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_visible($val) {
		$this->visible = $val;
	}
	// **********************
	// print_to_screen()
	// **********************
	function print_to_screen() { 
		echo "id = ". $this->id ." \n";
		echo "name = ". $this->name ." \n";
		echo "link = ". $this->link ." \n";
		echo "visible = ". $this->visible ." \n"; 
		echo "end p_t_s function \n "; 
	}

	// **********************
	// process a form $_POST()
	/**********************
	function process_form_post($_POST) { 
		$this;
		if (!empty($_POST['id'])) { 
			$this->set_id($_POST['id']);
		}
		if (!empty($_POST['name'])) { 
			$this->set_name($_POST['name']);
		}
		if (!empty($_POST['link'])) { 
			$this->set_link($_POST['link']);
		}
		if (!empty($_POST['visible'])) { 
			$this->set_visible($_POST['visible']);
		} 
		//echo "end post function \n "; 
		return $this;
	}
	*************************/
	// **********************
	// INSERT
	// **********************	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- insert this object
	* @param - insert
	* @return - boolean
	* @vers	- 1
	* @Mod - 
	**/
	function insert() {
		$this->id = ""; // clear key for autoincrement
		$sql = "INSERT INTO menu ( name,link,visible ) VALUES ( '".$this->slashes($this->name)."','".$this->slashes($this->link)."','".$this->slashes($this->visible)."' )";
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}		
		$this->id = mysql_insert_id($dblink);
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}		
		return $retid;
		
	}

	// **********************
	// UPDATE
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- update this object
	* @param - update($id)
	* @return - boolean
	* @vers	- 1
	* @Mod - 
	**/
	function update($id) {
		$sql = " UPDATE menu SET name = '$this->name',link = '$this->link',visible = '$this->visible' WHERE id = $id ";
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}		
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}				
		return $retid;

	}

	// **********************
	// SELECT METHOD / LOAD
	// **********************	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- load this object
	* @param - select_by_id($id)
	* @return - sets this object from "$id"
	* @vers	- 1
	* @Mod - 
	**/
	function select_by_id($id) {
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		$sql =  "SELECT * FROM menu WHERE id = '".$this->slashes($id)."'";
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}
		if ($row = mysql_fetch_array($retid)) {	

			$this->id = $row['id'];
			$this->name = $row['name'];
			$this->link = $row['link'];
			$this->visible = $row['visible'];
			$b = new banner();
			$this->banners = $b->get_all_banners($this->id);
			
		}
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}
		return $this;
	}
	// **********************
	// DELETE
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- delete this object
	* @param - delete($id)
	* @return - boolean
	* @vers	- 1
	* @Mod - 
	**/
	function delete($id) {
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		$sql = "DELETE FROM menu WHERE id = $id;";
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}
		return $retid;
	
	}

	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- $str
	* @param - adding slashes if necessary
	* @return - db safe string
	* @vers	- 1
	* @Mod - 
	**/
	function slashes($str) {
		//if ((get_magic_quotes_gpc()) && (!empty($str))) {
		if (!empty($str)) {
			return addslashes($str);
		} else {
			return $str;
		}
	}
	/**************************************************************/
	/*          ADD YOUR CUSTOM FUNCTIONS BELOW			       */
	/**************************************************************/
// class : end
}

?>

and the banner.class.php main call is get_all_banners on line 474

<?php
// begin generated class -->
/*
*
* -------------------------------------------------------
* CLASSNAME:        banner
* GENERATION DATE:  05.08.2011
* CLASS FILE:       C:\wamp\www\PHP_LIB\sql_class_generator/generated_classes/banner.class.php
* FOR MYSQL TABLE:  banner
* FOR MYSQL DB:     test
* -------------------------------------------------------
* CODE GENERATED BY:
* MY PHP-MYSQL-CLASS GENERATOR
* from: >> www.voegeli.li >> 
* CLASS MODIFIED AND EXTENDED BY:
* dmd
* -------------------------------------------------------
*
*/
define(DB_HOST,'localhost');
define(DB_USER,'root');
define(DB_PASS,'');
define(DB_BASE,'hhdb');
// **********************
// CLASS DECLARATION
// **********************
// class : begin
class banner { 
// **********************
// ATTRIBUTE DECLARATION
// **********************
	var $id;   // KEY ATTR. WITH AUTOINCREMENT
	var $txt;   // (normal Attribute)
	var $pic;   // (normal Attribute)
	var $alnk;   // (normal Attribute)
	var $lnkfile;   // (normal Attribute)
	var $height;   // (normal Attribute)
	var $banner_position;   // (normal Attribute)
	var $ord;   // (normal Attribute)
	var $lnk_tblmenuid;   // (normal Attribute) // link to the menu id many-to-one relationship
	var $vis;   // (normal Attribute)

// **********************
// CONSTRUCTOR METHOD
// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- constructor
	* @param - banner
	* @return - Instance of $class
	* @vers	- 1
	* @Mod - 
	**/
	function banner() {
		// $this->database = new Database();
	}
// **********************
// GETTER METHODS
// **********************

	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_id()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_id() {
		return $this->id;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_txt()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_txt() {
		return $this->txt;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_pic()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_pic() {
		return $this->pic;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_alnk()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_alnk() {
		return $this->alnk;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_lnkfile()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_lnkfile() {
		return $this->lnkfile;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_height()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_height() {
		return $this->height;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_banner_position()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_banner_position() {
		return $this->banner_position;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_ord()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_ord() {
		return $this->ord;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_lnk_tblmenuid()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_lnk_tblmenuid() {
		return $this->lnk_tblmenuid;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- get variable value
	* @param - get_vis()
	* @return - variable
	* @vers	- 1
	* @Mod - 
	**/
	function get_vis() {
		return $this->vis;
	}
	// **********************
	// SETTER METHODS
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_id($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_id($val) {
		$this->id = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_txt($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_txt($val) {
		$this->txt = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_pic($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_pic($val) {
		$this->pic = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_alnk($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_alnk($val) {
		$this->alnk = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_lnkfile($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_lnkfile($val) {
		$this->lnkfile = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_height($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_height($val) {
		$this->height = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_banner_position($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_banner_position($val) {
		$this->banner_position = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_ord($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_ord($val) {
		$this->ord = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_lnk_tblmenuid($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_lnk_tblmenuid($val) {
		$this->lnk_tblmenuid = $val;
	}
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- set variable value
	* @param - set_vis($val)
	* @return - void
	* @vers	- 1
	* @Mod - 
	**/
	function set_vis($val) {
		$this->vis = $val;
	}
	// **********************
	// print_to_screen()
	// **********************
	function print_to_screen() { 
		echo "id = ". $this->id ." \n";
		echo "txt = ". $this->txt ." \n";
		echo "pic = ". $this->pic ." \n";
		echo "alnk = ". $this->alnk ." \n";
		echo "lnkfile = ". $this->lnkfile ." \n";
		echo "height = ". $this->height ." \n";
		echo "banner_position = ". $this->banner_position ." \n";
		echo "ord = ". $this->ord ." \n";
		echo "lnk_tblmenuid = ". $this->lnk_tblmenuid ." \n";
		echo "vis = ". $this->vis ." \n"; 
		echo "end p_t_s function \n "; 
	}
	
	// **********************
	// process a form $_POST()
	/**********************
	function process_form_post($_POST) { 
		$this;
		if (!empty($_POST['id'])) { 
			$this->set_id($_POST['id']);
		}
		if (!empty($_POST['txt'])) { 
			$this->set_txt($_POST['txt']);
		}
		if (!empty($_POST['pic'])) { 
			$this->set_pic($_POST['pic']);
		}
		if (!empty($_POST['alnk'])) { 
			$this->set_alnk($_POST['alnk']);
		}
		if (!empty($_POST['lnkfile'])) { 
			$this->set_lnkfile($_POST['lnkfile']);
		}
		if (!empty($_POST['height'])) { 
			$this->set_height($_POST['height']);
		}
		if (!empty($_POST['banner_position'])) { 
			$this->set_banner_position($_POST['banner_position']);
		}
		if (!empty($_POST['ord'])) { 
			$this->set_ord($_POST['ord']);
		}
		if (!empty($_POST['lnk_tblmenuid'])) { 
			$this->set_lnk_tblmenuid($_POST['lnk_tblmenuid']);
		}
		if (!empty($_POST['vis'])) { 
			$this->set_vis($_POST['vis']);
		} 
		//echo "end post function \n "; 
		// do something useful, like insert your data
		// $this->insert();
		// return $this ( which is an instance of this object).
		return $this;
	}
	****************************************/
	// **********************
	// INSERT
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- insert this object
	* @param - insert
	* @return - boolean
	* @vers	- 1
	* @Mod - 
	**/
	function insert() {
		$this->id = ""; // clear key for autoincrement
		$sql = "INSERT INTO banner ( txt,pic,alnk,lnkfile,height,banner_position,ord,lnk_tblmenuid,vis ) VALUES ( '".$this->slashes($this->txt)."','".$this->slashes($this->pic)."','".$this->slashes($this->alnk)."','".$this->slashes($this->lnkfile)."','".$this->slashes($this->height)."','".$this->slashes($this->banner_position)."','".$this->slashes($this->ord)."','".$this->slashes($this->lnk_tblmenuid)."','".$this->slashes($this->vis)."' )";
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}		
		$this->id = mysql_insert_id($dblink);
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}		
		return $retid;
		
	}

	// **********************
	// UPDATE
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- update this object
	* @param - update($id)
	* @return - boolean
	* @vers	- 1
	* @Mod - 
	**/
	function update($id) {
		$sql = " UPDATE banner SET  txt = '$this->txt',pic = '$this->pic',alnk = '$this->alnk',lnkfile = '$this->lnkfile',height = '$this->height',banner_position = '$this->banner_position',ord = '$this->ord',lnk_tblmenuid = '$this->lnk_tblmenuid',vis = '$this->vis' WHERE id = $id ";
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}		
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}				
		return $retid;

	}

	// **********************
	// SELECT METHOD / LOAD
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- load an array of this object and pass back to the menu class.
	* @param - get_all_banners($id)
	* @return - sets this object from "$id" which is relation to menu.id and lnk_tblmenuid
	* @vers	- 1
	* @Mod - 
	**/
	function get_all_banners($id) {
		// we are going to return an array of banners  back to the menu class so set an array variable here.
		$return_array = array();
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		$sql =  "SELECT * FROM banner WHERE lnk_tblmenuid = '".$this->slashes($id)."'";
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}
		// notice the while statement here...
		while ($row = mysql_fetch_array($retid)) {	
			// create a 'self' object and stick set all fields returning from the db.
			$b = new banner();
			$b->id = $row['id'];
			$b->txt = $row['txt'];
			$b->pic = $row['pic'];
			$b->alnk = $row['alnk'];
			$b->lnkfile = $row['lnkfile'];
			$b->height = $row['height'];
			$b->banner_position = $row['banner_position'];
			$b->ord = $row['ord'];
			$b->lnk_tblmenuid = $row['lnk_tblmenuid'];
			$b->vis = $row['vis'];
			// push the $b banner object to your array.
			array_push($return_array,$b);
		}
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}
		// return an array of banners that can be used by menu class.
		return $return_array;
	}
	// **********************
	// DELETE
	// **********************
	
	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- delete this object
	* @param - delete($id)
	* @return - boolean
	* @vers	- 1
	* @Mod - 
	**/
	function delete($id) {
		$dblink = null;
		try	{
			$dblink = mysql_connect(DB_HOST,DB_USER,DB_PASS);
			mysql_select_db(DB_BASE,$dblink);
		} catch(Exception $ex) {
			echo "Could not connect to " . DB_HOST . ":" . DB_BASE . "\n";
			echo "Error: " . $ex->message;
			exit;
		}
		$sql = "DELETE FROM banner WHERE id = $id;";
		
		$retid = mysql_query($sql,$dblink) or die(mysql_error());
		if (!$retid) { 
			echo( mysql_error()); 
		}
		
		if(is_resource($dblink)) {		
			mysql_close($dblink);
		}
		return $retid;
	
	}

	/**
	* @author - Dana Dymacek
	* @type	- public
	* @desc	- $str
	* @param - adding slashes if necessary
	* @return - db safe string
	* @vers	- 1
	* @Mod - 
	**/
	function slashes($str) {
		//if ((get_magic_quotes_gpc()) && (!empty($str))) {
		if (!empty($str)) {
			return addslashes($str);
		} else {
			return $str;
		}
	}

	/**************************************************************/
	/*          ADD YOUR CUSTOM FUNCTIONS BELOW			       */
	/**************************************************************/
// class : end
}

?>

on about line 20 of both files starts the 'DEFINE' fields for your db. update those and this class should work for you.
Here is how to use it.

include ('menu.class.php');
// 
$id = 7;  //  or however you are calling your menu ids <---
$m = new menu();
$menu = $m->select_by_id($id);
// now you have some options on how to access your banners but just so you
// are clear, that they are in an array, lets go ahead and make one on the page.
$banners = array();
$banners = $menu->get_banners();
echo count($banners);  // see how many are in there.
foreach($banners as $banner) {
  echo $banner->get_txt();
  echo $banner->get_alnk();
  echo $banner->ord();
}

if they need to go in the array and pulled out in a certain order some of that can be done when querying the database as well... none of this is 'set in stone' feel free to adjust and ask questions as necessary.
enjoy

oops. I was a little hasty you need to go into the menu class and add at least 2 things.
under var $visible line 35 that should do it,

var $banners = array();
function get_banners() {
    return $this->banners;
}

that should do it, the classes should both be functional.

also, some of the sql may need to be cleaned for instance looking at the statement for get_all_banners(), you might want to remove the last two ' ticks

you might need to change the end of the sql from 
// lose the '-->  '".$this->slashes($id)."'  //<-- lose the '
to
".$this->slashes($id).";

please test and advise if you need more help.

wow thats mad, im not that familiar in writing php in classes. so as long as the $id contains the id number of the menu it should work. ill give it ago this weekend and let you know how i get on. will the output of eachh field be sent to the browser as a variable so i can then put it into a dynamic table?

reason being is because the way css is configured, each row in the banner table outputted to the screen in a table. width is fixed and height is variable set in the height field.

yes, we can work on page code separately though. it will look something like

// assuming you have called $menu new menu() etc.
$banners = array();
$banners = $menu->get_banners();
echo count($banners); // see how many are in there.
// in html:
<table>
   <tr>
<?php // switch to php.
foreach($banners as $banner) {
  // you don't have to echo anything here this is just 'sample' code so you 
// can see how a field that is set in 'banner' that is referenced by 'menu' can be
// pulled onto your page
  echo $banner->get_txt();
  echo $banner->get_alnk();
  echo $banner->ord();
  // so you could do something like...
  $html = "<td class="css" height=".$banner->get_height(). ">".$banner->get_txt()."</td>"
  echo "$html";  // where you can build your table rows up the foreach statement.
}

lets just try to get the code to work first if it works and you have all of your data in the $menu item we can then turn to the html part of the page to display a selected menu / banner.

its a little trickier than that, again, just sample here once you have the data objects working we can do page code to solve your display issues.

excellent, thank you so much for helping me with this, im looking forward to testing it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.