This topic is locked

Custome php code

9/14/2008 3:23:02 PM
PHPRunner General questions
N
nickrix author

im trying to pull data from another table using the below code - however i only want to return data that is linked to the info i am displaying on the view page.
so i have the view for venue details which has: venue_id , venue name, etc
i want to pull only data from another database where the "nameid" (from the table im trying to pull) matches the "venue_id" (from the table currently in use by phprunner view)
can anyone help?
$sql = mysql_query("SELECT firstname, surname FROM test WHERE nameid LIKE 'venue_id'ORDER BY firstname ASC LIMIT 5") or die("Error connecting to table: ".mysql_error());
while ($rowdetail = mysql_fetch_array($sql)) {

print "<p>Name: ".$rowdetail['firstname']." ".$rowdetail['surname']."<br />\n";

print "Address: ".$rowdetail['address']."<br />\n";

print "Postcode: ".$rowdetail['postcode']."\n";

print "<hr />\n";

}
is there a way for the venue_id in the above code to change depending on the venue id displayed on the view page.
(basically i only want to pull records from a nother table that is related to this record in view)
any help would be much appreciated.
Regards

Nick

T
thesofa 9/14/2008

Use the Master/Detail settings on the Datasource tables page of PHPR,

Give us more detail, like the table names and structure

N
nickrix author 9/15/2008

Use the Master/Detail settings on the Datasource tables page of PHPR,

Give us more detail, like the table names and structure


basically i have a tablecalled venue SQL view from PHP runner below
SELECT

venueid,

venue_name,

admin_id,

`other info`

FROM venue
I want to be able to say pull data from one table (just like my code below does) but only where the nameidcolumn on the test table is the same as the venue_id in use.
does that make sense? or have i got this completley messed up?
nick

T
thesofa 9/15/2008

OK, I have made the two tables, here is the sql dump file

/*

MySQL Data Transfer

Source Host: 192.168.0.44

Source Database: vnu

Target Host: 192.168.0.44

Target Database: vnu

Date: 16/09/2008 00:22:40

*/
SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------

-- Table structure for test

-- ----------------------------

CREATE TABLE `test` (

`test_id` int(11) NOT NULL auto_increment,

`nameid` int(11) NOT NULL,

`firstname` varchar(25) NOT NULL,

`surname` varchar(25) NOT NULL,

`address` varchar(50) NOT NULL,

`postcode` varchar(11) NOT NULL,

PRIMARY KEY (`test_id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Table structure for venue

-- ----------------------------

CREATE TABLE `venue` (

`venueid` int(11) NOT NULL auto_increment,

`venue_name` varchar(25) NOT NULL,

`admin_id` int(11) NOT NULL,

`other info` mediumtext,

PRIMARY KEY (`venueid`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Records

-- ----------------------------

INSERT INTO `test` VALUES ('1', '2', 'John', 'Jones', '2 Last post lane', 'bs82lr');

INSERT INTO `test` VALUES ('2', '2', 'Jenny', 'Smith', '12 watling road', 'dh75rp');

INSERT INTO `test` VALUES ('3', '1', 'david', 'grimsdyke', '1 askey rise', 'ls5 5opp');

INSERT INTO `test` VALUES ('4', '1', 'tim', 'burton', '3 sleepy hollow', 'lost head');

INSERT INTO `test` VALUES ('5', '3', 'J', 'Depp', 'Wonkaland', 'wi33');

INSERT INTO `test` VALUES ('6', '1', 'susan', 'sarandon', '2 robbins row', 'la');

INSERT INTO `venue` VALUES ('1', 'Arena', '17', 'Newcastle Metro Arena');

INSERT INTO `venue` VALUES ('2', 'City Hall', '12', 'Newcastle City Hall, Northumberland Street');

INSERT INTO `venue` VALUES ('3', 'Gala', '11', 'Durham Gala theatre');



Each table has an auto increment primary key and nameid is the foreign key to link to the venue table
Now set up PHPrunner to connect to the database called VNU as I have called it that.

On the datasource tables page, select the table called test, put a tick next to it

On the right of the page, select Venue as the master table and venueid as the primary Key, the detail table will be test and select nameid as the foreign key display the master table info on the detail page should be ticked.

In the tables pane, tick venue as well.
Build the project and you will find that you only see the test records that apply to the venue details when you click the link from the Venue page .

Just try it and see, you will be surprised how little coding is needed. just make sure that venueid and nameid ate the same data type and length.
When you have records in the tables, you will see links next to them to the detail pages.

When you view the venue list page, you will see a link next to each record called test, this will take you to the detail records JUST for that master record.

Hover over the link and see a preview of all the records in the detail table that relate to the record in the main table.

Good innit?

Have I answered your problem?

N
nickrix author 9/16/2008

OK, I have made the two tables, here is the sql dump file

/*

MySQL Data Transfer

Source Host: 192.168.0.44

Source Database: vnu

Target Host: 192.168.0.44

Target Database: vnu

Date: 16/09/2008 00:22:40

*/
SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------

-- Table structure for test

-- ----------------------------

CREATE TABLE `test` (

`test_id` int(11) NOT NULL auto_increment,

`nameid` int(11) NOT NULL,

`firstname` varchar(25) NOT NULL,

`surname` varchar(25) NOT NULL,

`address` varchar(50) NOT NULL,

`postcode` varchar(11) NOT NULL,

PRIMARY KEY (`test_id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Table structure for venue

-- ----------------------------

CREATE TABLE `venue` (

`venueid` int(11) NOT NULL auto_increment,

`venue_name` varchar(25) NOT NULL,

`admin_id` int(11) NOT NULL,

`other info` mediumtext,

PRIMARY KEY (`venueid`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Records

-- ----------------------------

INSERT INTO `test` VALUES ('1', '2', 'John', 'Jones', '2 Last post lane', 'bs82lr');

INSERT INTO `test` VALUES ('2', '2', 'Jenny', 'Smith', '12 watling road', 'dh75rp');

INSERT INTO `test` VALUES ('3', '1', 'david', 'grimsdyke', '1 askey rise', 'ls5 5opp');

INSERT INTO `test` VALUES ('4', '1', 'tim', 'burton', '3 sleepy hollow', 'lost head');

INSERT INTO `test` VALUES ('5', '3', 'J', 'Depp', 'Wonkaland', 'wi33');

INSERT INTO `test` VALUES ('6', '1', 'susan', 'sarandon', '2 robbins row', 'la');

INSERT INTO `venue` VALUES ('1', 'Arena', '17', 'Newcastle Metro Arena');

INSERT INTO `venue` VALUES ('2', 'City Hall', '12', 'Newcastle City Hall, Northumberland Street');

INSERT INTO `venue` VALUES ('3', 'Gala', '11', 'Durham Gala theatre');



Each table has an auto increment primary key and nameid is the foreign key to link to the venue table
Now set up PHPrunner to connect to the database called VNU as I have called it that.

On the datasource tables page, select the table called test, put a tick next to it

On the right of the page, select Venue as the master table and venueid as the primary Key, the detail table will be test and select nameid as the foreign key display the master table info on the detail page should be ticked.

In the tables pane, tick venue as well.
Build the project and you will find that you only see the test records that apply to the venue details when you click the link from the Venue page .

Just try it and see, you will be surprised how little coding is needed. just make sure that venueid and nameid ate the same data type and length.
When you have records in the tables, you will see links next to them to the detail pages.

When you view the venue list page, you will see a link next to each record called test, this will take you to the detail records JUST for that master record.

Hover over the link and see a preview of all the records in the detail table that relate to the record in the main table.

Good innit?

Have I answered your problem?


Yes this is great - however i know how to do this but i want to display info from 3 or 4 other tables on the same page as the record im viewing. - ie i want to see info from the venue table then also display data from test table, reviews table, djs table etc? make sense? - i dont want to have to click through to see the info - i want all 4 tables showing on one page... this is why i thought i had to use custom code????
sorry if i have explained this totally wrong?

T
thesofa 9/16/2008

well, you never mentioned the other tables before, if you want to show all the data from other tables, just make a custom view in MySQL and base your list table on that!

send me the sql dump of the tables and data and gimme a bit more spec and I will have a play for you

N
nickrix author 9/16/2008

well, you never mentioned the other tables before, if you want to show all the data from other tables, just make a custom view in MySQL and base your list table on that!

send me the sql dump of the tables and data and gimme a bit more spec and I will have a play for you


Sorry - im not the best at explaining these things (really sorry)

is the custom view where you join two tables together? if si i have tried this befor but as i will potentially have a lot of data in the tables it came up with some error on the actual website saying the sql string was too long or something (i cant remember exactly now)
also i dont know if it will do exactly as i want , for example.
i want to have a view page (it will show all basic info about the club/bar)

then on the same page i only want to display 5 rows of data from the reviews table that is linked to the same record...
am i making sense?

e.g the last 5 reviews about this club , last 5 images etc - but also will have the option to click through and see all the reviews linked to the record.
just think of any directory listing site - where they show the reviews on same page - also i will be linking it so it will show 5 people who are going to that club - and you can click through to see everyone who is going to that club
obviously all these will be different tables (1 for the club, 1 for reviews, 1 for users who are going to the club etc)
am i going about this all the wrong way ? or is there an easier way? - i will create some proper tables like the ones i will be using and post the sql dump here (if i can sus out how to do that lol)
thanks for all your help so far - you have been great ... maybe if i am still stuck do you charge a rate to actually do some work on this? or am i being cheecky? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=33130&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />
regards

nick

T
thesofa 9/16/2008

not being cheeky, just hopeful!

get the tables sorted, do a sql dump and let me know, then I will have a look, it may be that there is a template avaiable that will help you?

Email support@xlinesoft.com and ask them, I am just a user like you, but I have had loads of help ffrom other users so I try to put something back.

J
Jane 9/17/2008

Nick,
use custom events (Insert PHP code snippet option on the Visual Editor tab) to insert data from another tables.

Here is just a sample:

gobal $conn;

$str = "<tabel><tr><td>Field1</td><td>Field2</td></tr>"

$sql = "select Field1,Field2 from TableName";

$rs = db_query($sql,$conn);

while($data = db_fetch_array($rs))

$str.= "<tr><td>".$data["Field1"]."</td><td>".$data["Field2"]."</td></tr>";

$str.= "</table>";

echo $str;