[PHP] move if logic from php into query

2007-04-26 Thread Thufir
I couldn't get the page to load when the logic for line 31, ($id ==
$_POST[recordID]), was in the query.   Can the logic for that be moved to the
query?  I expect so.

I tried changing the where clause of the query, no go.


[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ cat /var/www/html/insertContacts.php -n
 1  html
 2  headtitleinsert contacts/title/head
 3  body
 4  ?php
 5
 6
 7  $user=feeds;
 8  $host=localhost;
 9  $password=password;
10  $database = feeds;
11
12  $connection = mysql_connect($host,$user,$password)
13  or die (couldn't connect to server);
14  $db = mysql_select_db($database,$connection)
15  or die (Couldn't select database);
16
17  $query = INSERT INTO contacts (id , notes) VALUES
('$_POST[recordID]' , '$_POST[contacts]');
18  $result = mysql_query($query)
19  or die (Couldn't execute insert query.);
20
21  $query =SELECT contacts.id, px_items.id, title, notes
FROM contacts, px_items WHERE 
22  contacts.id=px_items.id;
23
24  $result = mysql_query($query)
25  or die (Couldn't execute second query.);
26
27  while ($row = mysql_fetch_array($result)) 
28  {
29  extract ($row);
30
31  if ($id == $_POST[recordID])
32  {
33  echo $id;
34  echo br;
35  echo $title;
36  echo brbr;
37  echo $notes;
38  echo brbrbrbr;
39  echo brbrbrbr;
40
41  }//if
42  }//while
43
44
45
46
47  echo br;
48  echo a href=\;
49  echo http://localhost/contacts.php;;
50  echo \;
51  echo http://localhost/contacts.php;;
52  echo /a;
53  echo brbr;
54
55
56  echo br;
57  echo a href=\;
58  echo http://localhost/items_notes.php;;
59  echo \;
60  echo http://localhost/items_notes.php;;
61  echo /a;
62  echo brbr;
63
64
65  ?
66   /body /html 
[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ date
Thu Apr 26 09:24:31 BST 2007
[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ 



thanks,

Thufir

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] everything printed suddenly has blue text, as if were a link

2007-04-25 Thread Thufir
When I print out my list of apartments, everything after
http://vancouver.craigslist.org/apa/318594679.html, which is grabbed via
http://code.google.com/p/feed-on-feeds/ is suddenly blue.  So, the first few
are fine, have black text, after that it's all blue.

Do I put some html in the loop to make sure that the color is blue?  seems kinda
silly.

[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# cat /var/www/html/apartments.php -n
 1  html
 2  headtitleapartments/title/head
 3  body
 4  ?php
 5  $user=feeds;
 6  $host=localhost;
 7  $password=password;
 8  $database = feeds;
 9  
10  $connection = mysql_connect($host,$user,$password)
11  or die (couldn't connect to server);
12  $db = mysql_select_db($database,$connection)
13  or die (Couldn't select database);
14  
15  $query = SELECT id, link, title, content FROM px_items WHERE
feed_id=1 ORDER BY id DESC;
16  $result = mysql_query($query)
17  or die (Couldn't execute query.);
18
19
20  $count =1;
21
22  while ($row = mysql_fetch_array($result)) 
23  {
24  extract ($row);
25
26  echo bigbigb;
27  echo $id;
28  echo /b/big/big;
29
30  echo br;
31  echo $title;
32
33  echo br;
34  echo $content;
35  echo br;
36
37  echo a href=\;
38  echo $link;
39  echo \;
40  echo $link;
41  echo /a;
42
43  echo brbr;
44
45  }//while
46  ?
47  /body
48  /html 
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# date
Wed Apr 25 19:23:20 BST 2007
[EMAIL PROTECTED] ~]# 


thanks,

Thufir

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] printing a one-to-many relationship

2007-04-25 Thread Thufir
There's a one-to-many relationship between px_items.id and contacts.id, and I
want a printout of some data from each.

I want to print out the query results px_items.id field once and once only, but
the contacts.notes field many times, as there could be many entries.

Right now it prints out each row, which is workable for now, but could get
annoying.  I'm trying for something like


entry one
note a
note b
note c

entry two
note a

entry three
notb a
note b



Here's my schema and code:

[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# cat /var/www/html/items_notes.php -n
 1  html
 2  headtitleitems and notes/title/head
 3  body
 4  ?php
 5  $user=feeds;
 6  $host=localhost;
 7  $password=password;
 8  $database = feeds;
 9  
10  $connection = mysql_connect($host,$user,$password)
11  or die (couldn't connect to server);
12  $db = mysql_select_db($database,$connection)
13  or die (Couldn't select database);
14
15
16  $query = SELECT * FROM contacts, px_items WHERE
contacts.id=px_items.id ORDER BY px_items.id DESC;
17
18  $result = mysql_query($query)
19  or die (Couldn't execute query.);
20
21  while ($row = mysql_fetch_array($result)) 
22  {
23  extract ($row);
24
25  echo bigbigb;
26  echo $id;
27  echo /b/big/big;
28
29  echo br;
30  echo $title;
31
32  echo br;
33  echo $content;
34  echo br;
35
36  echo br;
37  echo $timestamp;
38  echo br;
39
40  echo br;
41  echo $notes;
42  echo br;
43
44  echo a href=\;
45  echo $link;
46  echo \;
47  echo $link;
48  echo /a;
49
50  echo brbr;
51
52  }//while
53  ?
54  /body
55  /html 
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# mysql -u feeds -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25 to server version: 5.0.27

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql use feeds;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql show tables;
+-+
| Tables_in_feeds |
+-+
| contacts| 
| px_feeds| 
| px_items| 
+-+
3 rows in set (0.00 sec)

mysql describe contacts;
+---+---+--+-+---+---+
| Field | Type  | Null | Key | Default   | Extra |
+---+---+--+-+---+---+
| id| int(11)   | YES  | MUL | NULL  |   | 
| timestamp | timestamp | NO   | | CURRENT_TIMESTAMP |   | 
| notes | longtext  | YES  | | NULL  |   | 
+---+---+--+-+---+---+
3 rows in set (0.07 sec)

mysql describe px_items;
+---+--+--+-+---++
| Field | Type | Null | Key | Default   | Extra  |
+---+--+--+-+---++
| id| int(11)  | NO   | PRI | NULL  | auto_increment | 
| feed_id   | int(11)  | NO   | MUL | 0 || 
| timestamp | timestamp| NO   | | CURRENT_TIMESTAMP || 
| link  | text | YES  | | NULL  || 
| title | varchar(250) | YES  | | NULL  || 
| content   | text | YES  | | NULL  || 
| dcdate| text | YES  | | NULL  || 
| dccreator | text | YES  | | NULL  || 
| dcsubject | text | YES  | | NULL  || 
| read  | tinyint(4)   | YES  | MUL | NULL  || 
+---+--+--+-+---++
10 rows in set (0.00 sec)

mysql quit
Bye
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# date
Wed Apr 25 19:30:38 BST 2007
[EMAIL PROTECTED] ~]# 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] breakthrough: get record, insert on different table works

2007-04-24 Thread Thufir
it ain't pretty, but it's like a sugar rush!  Finally, able to enter data on
forms which I can create :)

[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# cat /var/www/html/contacts.php -n
 1  html
 2  headtitlecontacts/title/head
 3  body
 4  ?php
 5  $user=feeds;
 6  $host=localhost;
 7  $password=password;
 8  $database = feeds;
 9  
10  $connection = mysql_connect($host,$user,$password)
11  or die (couldn't connect to server);
12  $db = mysql_select_db($database,$connection)
13  or die (Couldn't select database);
14  
15  $query = SELECT id, link, title, content FROM px_items WHERE
feed_id=1 ORDER BY id;
16  $result = mysql_query($query)
17  or die (Couldn't execute query.);
18  ?
19   
20  form action=process.php method=post
21  select name=id
22
23  ?php
24  while($nt=mysql_fetch_array($result))
25  echo 'option 
value='.$nt['id'].''.$nt['id'].'/option';
26  ?
27
28  /select
29  input type=submit value=SEND/
30  /form
31
32  /body
33  /html 
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# cat /var/www/html/process.php -n
 1  html
 2  headtitlecontacts/title/head
 3  body
 4  ?php
 5
 6  error_reporting(E_ALL);
 7
 8  $user=feeds;
 9  $host=localhost;
10  $password=password;
11  $database = feeds;
12  $connection = mysql_connect($host,$user,$password)
13  or die (couldn't connect to server);
14  $db = mysql_select_db($database,$connection)
15  or die (Couldn't select database);
16
17  foreach ($_POST as $key = $value)
18  {
19  //  echo $key, $value brbr;
20  $record=$value;
21  }//foreach
22
23
24  //  echo br get record ;
25  //  echo $record;
26  //  echo brbr;
27
28  $query = SELECT id, link, title, content FROM px_items WHERE
id='$record' ORDER BY id;
29  $result = mysql_query($query)
30  or die (Couldn't execute query.);
31
32  $result = mysql_query($query); if (!$result) { echo
$query.'br'.mysql_error(); exit(1); }
33
34
35  //  print_r($result);
36
37
38  while ($row = mysql_fetch_array($result)) 
39  {
40  extract ($row);
41  echo $id;
42  echo brbr;
43  echo $title;
44  }//while
45
46
47  echo form action='insertContacts.php' method='post';
48  echo input type='text'name='contacts';
49  echo input type='hidden'  name='recordID'
value=$record;
50  echo input type='submit' 
value='SEND';
51  echo /form\n;
52
53  ?
54   /body /html 
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# cat /var/www/html/insertContacts.php -n
 1  html
 2  headtitleinsert contacts/title/head
 3  body
 4  ?php
 5
 6  $user=feeds;
 7  $host=localhost;
 8  $password=password;
 9  $database = feeds;
10  $connection = mysql_connect($host,$user,$password)
11  or die (couldn't connect to server);
12  $db = mysql_select_db($database,$connection)
13  or die (Couldn't select database);
14
15  foreach ($_POST as $key = $value)
16  {
17  echo $key, $value brbr;
18  $record=$value;
19  $contactData=$key;
20  }//foreach
21  
22
23  echo recordID  ;
24  echo $_POST[recordID];
25  echo br contacts;
26  echo $_POST[contacts];
27  echo br;
28
29  $query = INSERT INTO contacts (id , notes) VALUES
('$_POST[recordID]' , '$_POST[contacts]');
30  $result = mysql_query($query)
31  or die (Couldn't execute query.);
32
33  ?
34   /body /html 
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# date
Wed Apr 25 00:06:59 BST 2007
[EMAIL PROTECTED] ~]# 
[EMAIL PROTECTED] ~]# 




Any thoughts/suggestions/advice as a next step?  I need to add a timestamp when
the data's entered, but that's a small thing.  This is adding notes onto
craigslist rss feeds database using http://code.google.com/p/feed-on-feeds/,
which is an amazing app.



-Thufir

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] first script

2007-04-20 Thread Thufir
adapted from php/mysql for dummies, I'd like it to return the notes field,
too, pls.  I know that I want to echo notes, but can't figure out where to do
so.  any pointers would be appreciated :)

[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ cat /var/www/html/showapts.php
html
headtitleapts/title/head
body
?php
  $user=root;
  $host=localhost;
  $password=password;
  $database = apts;

  $connection = mysql_connect($host,$user,$password)
   or die (couldn't connect to server);
  $db = mysql_select_db($database,$connection)
   or die (Couldn't select database);
  $query = SELECT DISTINCT * FROM craigslist ORDER BY id;
  $result = mysql_query($query)
   or die (Couldn't execute query.);

  /* create form containing selection list */
  echo form action='processform.php' method='post'
select name='id'\n;

  while ($row = mysql_fetch_array($result))
  {
 extract($row);
 echo option value='$id'$id\n;
  }
  echo /select\n;
  echo input type='submit' value='id'
/form\n;
?
/body
/html
[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 98 to server version: 5.0.27

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql show databases;
++
| Database   |
++
| information_schema | 
| apts   | 
| mysql  | 
| test   | 
++
4 rows in set (0.00 sec)

mysql use apts;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql show tables;
++
| Tables_in_apts |
++
| craigslist | 
++
1 row in set (0.00 sec)

mysql describe craigslist;
+---+-+--+-+-+---+
| Field | Type| Null | Key | Default | Extra |
+---+-+--+-+-+---+
| notes | longtext| NO   | | |   | 
| id| bigint(15) unsigned | NO   | | |   | 
+---+-+--+-+-+---+
2 rows in set (0.01 sec)

mysql quit
Bye
[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ date
Fri Apr 20 19:40:29 BST 2007
[EMAIL PROTECTED] ~]$ 
[EMAIL PROTECTED] ~]$ 



thanks,

Thufir

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: first script

2007-04-20 Thread Thufir
Richard Lynch ceo at l-i-e.com writes:

 
 On Fri, April 20, 2007 2:05 pm, Thufir wrote:
 
 Please tell me that's not your real name...
[...]

It's the name I use on the internet.


-Thufir

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php