Something went awfully wrong in PHP+MySQL :(


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Something went awfully wrong in PHP+MySQL :(
# 15  
Old 11-03-2007
It should be definitely possible ! Smilie

But I don't understand the relation you had specified ( sorry ! )

Are two tables being referred here ?

Is it the relation list that contains elements from both the tables.

Could you please explain that ?
# 16  
Old 11-03-2007
I'm sorry about that... Great to hear that it is possible... Its from a single table... For instance, consider two columns,

Column1 | Column2
A | B
B | C
C | D
A | F
E | G
G | H

X|Y => X is connected to Y or Y is connected to X. So the output should be something like:

A B C D F

and

E G H

Hope I was able to explain this time. Please let me know if I'm not clear so that I'll write a more detailed example this time Smilie
# 17  
Old 11-06-2007
Any suggestions please?
# 18  
Old 11-06-2007
this would achieve the above,

I know its not optimized

this is just as a pointer

Code:
#! /opt/third-party/bin/perl

my $first = 1;
open(FILE, "<", "filename");

while(<FILE>) {
  chomp;
  s/ //g;
  my @arr = split(/\|/);
  $first == 1 || exists $firstHash{$arr[0]} ? pushValues(\%firstHash, \@arr, \$first) : pushValues(\%secondHash, \@arr, \$first);
}

close(FILE);

foreach my $k ( keys %firstHash ) {
  print "first set:$k\n";
}

foreach my $k ( keys %secondHash ) {
  print "second set:$k\n";
}

sub pushValues {
  my ($hash, $arr, $first) = @_;

  $$first = 0;
  foreach (@$arr) {
    $hash->{$_} = 1;
  }
}

exit 0

# 19  
Old 11-06-2007
Thank you... I'm not well versed with perl so I'll take some time in converting the logic to php Smilie Actually I was trying something with one of the functions that mysql provided - Group_Concat... I wasn't particularly clear about getting the data in a format that I wanted... Using group_concat do you know of a way of getting the sub children too in a single line? As of now, I am able to get the following:

Code:
Parent -> A
Children -> B E F G

Parent -> B
Children-> C D

Don't bother about the children being the same... What I wanted was something like if C and D are children of B, then I want something like:

Quote:
Parent -> A
Children -> B{C,D} E F G
I see a hint of recursion here but I might be wrong.

The statement that I framed was:

Code:
SELECT ip2 AS Parent, GROUP_CONCAT(ip1 SEPARATOR ', ') AS Children FROM br GROUP BY ip2 LIMIT 15;

# 20  
Old 11-09-2007
Sorry but someone please? I'm afraid I couldn't adapt your perl code in php. This database of mine contains millions of records so I don't know how to write that... Any thoughts on my previous post?
# 21  
Old 11-09-2007
Quote:
Originally Posted by Legend986
Sorry but someone please? I'm afraid I couldn't adapt your perl code in php. This database of mine contains millions of records so I don't know how to write that... Any thoughts on my previous post?
Sorry if am deviating you from the problem!

The above posted code to select the relation set works fine.

If you are not able to incorporate the perl code into php,
what you could do is have the perl script as a separate script and call that from php script

Something like,

perl script to be named as run.pl
within php,
select column1, column2 from table1; ## dump the output in a file
call the perl file run.pl

and now you should have the output needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Web Development

Can't Install MySQL with PHP

Hi, I'm on a Raspberry Pi with Raspbian Wheezy. I urgently need to get MySQL running with PHP, but I get an error. For example: $con=mysql_connect("127.0.0.1","root","******","ids"); gives PHP Fatal error: Call to undefined function mysql_connect() So, I found I needed to install some... (2 Replies)
Discussion started by: FreddoT
2 Replies

2. Programming

PHP and MySQL

Hello, While I was interpretation the PHP manual on database security the recent past, it said that you should by no means connect to the database as the super user but rather as one more user with more limited options. My question is: How do you generate new users and set access... (2 Replies)
Discussion started by: AimyThomas
2 Replies

3. Emergency UNIX and Linux Support

Migration of website... PHP/Mysql -which path for DB.php

Hi, I have two websites: website1.com and website2.com I didn't write either but have successfully moved all the files from website1.com to website2.com I (thought) I installed all the correct php modules and website2 is mostly up and running. However, my boss found that when we go to a... (15 Replies)
Discussion started by: Astrocloud
15 Replies

4. Shell Programming and Scripting

Mysql is not connected in php

Hi, The php is not able to connect into my mysql database. But i can able to connect by manually. I think that I have missed some points. Please guild for the same. Thanks, Mani (1 Reply)
Discussion started by: Mani_apr08
1 Replies

5. Programming

MySQL - PHP

Hello every one i have question i want to build DATAbase using PHP as interface i use shell to access to linux . i have in linux psql and SQLplus i'll call all html files that has db tabels from shell directory. what should to do before design php pages. can build the database sql design... (3 Replies)
Discussion started by: Scotch
3 Replies

6. Shell Programming and Scripting

PHP/MySQL slow_queries

Hi All, I have a problem with my database having lots of 'stale' slow_queries. I think the problem may be because of the following code: $numresults=mysql_query("select * from links where catagory=".$catagory." order by linknum"); $numrows=mysql_num_rows($numresults); I believe this... (4 Replies)
Discussion started by: pondlife
4 Replies

7. Shell Programming and Scripting

Problem with PHP and MySQL

Okay, I'm new to this PHP and MySQL stuff, so help would be VERY much appreciated. :) On my iMac runnning Panther, it has MySQL and PHP installed. Yet when I view a PHP file from the iMac or another computer at my house, I get the source code. What's wrong? (11 Replies)
Discussion started by: Danny_10
11 Replies

8. UNIX for Dummies Questions & Answers

PHP and MySQL

I want to design a database, using mysql as a backend, and PHP as the frontend, I wanna be able to easily build forms in PHP to communicate with MySQL, is there any programs that will allow this, I really dont want to program all the forms by hand.. thankyou (2 Replies)
Discussion started by: kwalick
2 Replies

9. Cybersecurity

mysql php

with a limited knowledege of php and sql, what is a good and secure way to do passwords running an https server? (1 Reply)
Discussion started by: macdonto
1 Replies
Login or Register to Ask a Question