[PHP] SQL query to array?

2006-04-26 Thread William Stokes
Hello,

Can someone please help me to put the results of a query to an array. Never 
done this before:

$sql = SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY sortteri 
ASC;
$result = mysql_query($sql);
$num = mysql_num_rows($result);
$cur = 1;

//create empty array that contains an array before loop
$arr = array(Team = array());

while ($num = $cur) {
$row = mysql_fetch_array($result);
$id = $row[jouk_id];
$srt = $row[sortteri];
$nimi = $row[jouk_nimi];

//append values to the array
$arr = array(Team$cur = array(0 = $id, 1 = $srt, 2 = $nimi));

$cur++;
}

Thanks
-Will 

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



Re: [PHP] SQL query to array?

2006-04-26 Thread Jim Lucas

William Stokes wrote:

Hello,

Can someone please help me to put the results of a query to an array. Never 
done this before:


$sql = SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY sortteri 
ASC;

$result = mysql_query($sql);
$num = mysql_num_rows($result);
$cur = 1;

//create empty array that contains an array before loop
$arr = array(Team = array());

while ($num = $cur) {
$row = mysql_fetch_array($result);
$id = $row[jouk_id];
$srt = $row[sortteri];
$nimi = $row[jouk_nimi];

//append values to the array
$arr = array(Team$cur = array(0 = $id, 1 = $srt, 2 = $nimi));

$cur++;
}

Thanks
-Will 

  

You might try this as an alternative:

$cur = 0;
while (list($id, $srt, $nimi) = $mysql_fetch_array($result)) {
	$arr = array(Team{$cur} = array(0 = $id, 
	1 = $srt,

2 = $nimi));
$cur++;
}


Jim

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



Re: [PHP] SQL query to array?

2006-04-26 Thread Richard Lynch
On Wed, April 26, 2006 1:39 am, William Stokes wrote:
 Can someone please help me to put the results of a query to an array.

There are only a few thousand tutorials on this on the 'net...

 Never
 done this before:

 $sql = SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY
 sortteri
 ASC;
 $result = mysql_query($sql);
 $num = mysql_num_rows($result);
 $cur = 1;

 //create empty array that contains an array before loop
 $arr = array(Team = array());

 while ($num = $cur) {

If you do not start indenting your code correctly now, you will most
likely never enjoy much success in your programming efforts.

 $row = mysql_fetch_array($result);
 $id = $row[jouk_id];
 $srt = $row[sortteri];
 $nimi = $row[jouk_nimi];

 //append values to the array
 $arr = array(Team$cur = array(0 = $id, 1 = $srt, 2 = $nimi));

While there is nothing technically wrong with this, it's going to
make life harder for you to deal with the Team$cur index.

Much easier to do:
$arr[] = $row;

to append to the array.

 $cur++;
 }

Or did I miss the part where you described what you saw and what you
expected to see?

Because what you posted is fine as far as it goes, as far as I can
tell.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] SQL query to array?

2006-04-26 Thread Joe Wollard
Will,

Seems to me like you've just done it! Here's another way of doing it that
will utilize mysql_fetch_assoc() to allow your query to dictate the elements
of the array. Keep in mind, I haven't tested this, but since I'm not
entirely sure what you are asking the list, I'll offer it anyway ;-)

?php
/*...do connection stuff here...*/
$sql = SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY sortteri
ASC;
$result = mysql_query($sql);
$num = mysql_num_rows($result);
$Team = null; //We'll fill this up later - gotta love PHP ;-)

// loop over each row in the result set
for($i=0; $i$num; $i++){
$tmp = mysql_fetch_assoc($result);

// loop over each column in the current row
while(list($key, $val) = each($tmp))
   $Team[$key][$i] = $val;
}
// display the contents of the $Team array
print_r($Team);
?




On 4/26/06, William Stokes [EMAIL PROTECTED] wrote:

 Hello,

 Can someone please help me to put the results of a query to an array.
 Never
 done this before:

 $sql = SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY sortteri
 ASC;
 $result = mysql_query($sql);
 $num = mysql_num_rows($result);
 $cur = 1;

 //create empty array that contains an array before loop
 $arr = array(Team = array());

 while ($num = $cur) {
 $row = mysql_fetch_array($result);
 $id = $row[jouk_id];
 $srt = $row[sortteri];
 $nimi = $row[jouk_nimi];

 //append values to the array
 $arr = array(Team$cur = array(0 = $id, 1 = $srt, 2 = $nimi));

 $cur++;
 }

 Thanks
 -Will

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




Re: [PHP] SQL query to array?

2006-04-26 Thread William Stokes
Ooopps.

I just did have array too many. This did the append corretly:

$arr[Team$cur] = array(id = $id, sort = $srt, jnimi = $nimi);

-Will


Joe Wollard [EMAIL PROTECTED] kirjoitti 
viestissä:[EMAIL PROTECTED]
Will,

Seems to me like you've just done it! Here's another way of doing it that
will utilize mysql_fetch_assoc() to allow your query to dictate the elements
of the array. Keep in mind, I haven't tested this, but since I'm not
entirely sure what you are asking the list, I'll offer it anyway ;-)

?php
/*...do connection stuff here...*/
$sql = SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY sortteri
ASC;
$result = mysql_query($sql);
$num = mysql_num_rows($result);
$Team = null; //We'll fill this up later - gotta love PHP ;-)

// loop over each row in the result set
for($i=0; $i$num; $i++){
$tmp = mysql_fetch_assoc($result);

// loop over each column in the current row
while(list($key, $val) = each($tmp))
   $Team[$key][$i] = $val;
}
// display the contents of the $Team array
print_r($Team);
?




On 4/26/06, William Stokes [EMAIL PROTECTED] wrote:

 Hello,

 Can someone please help me to put the results of a query to an array.
 Never
 done this before:

 $sql = SELECT sortteri,jouk_id,jouk_nimi FROM x_table ORDER BY sortteri
 ASC;
 $result = mysql_query($sql);
 $num = mysql_num_rows($result);
 $cur = 1;

 //create empty array that contains an array before loop
 $arr = array(Team = array());

 while ($num = $cur) {
 $row = mysql_fetch_array($result);
 $id = $row[jouk_id];
 $srt = $row[sortteri];
 $nimi = $row[jouk_nimi];

 //append values to the array
 $arr = array(Team$cur = array(0 = $id, 1 = $srt, 2 = $nimi));

 $cur++;
 }

 Thanks
 -Will

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



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



Re: [PHP] sql query

2005-03-03 Thread Jochem Maas
Jason Petersen wrote:
On Wed, 2 Mar 2005 13:02:39 +0200, William Stokes [EMAIL PROTECTED] wrote:
Hello
Can someone explain this to me. I don't know how to read this.
if (!$variable = mysql_query(select id,sessid from users where ...
What is this if(!

This is a way to run a SQL query, capture the return value, and
perform an action if the query failed. For code readability, I would
probably write that as two statements:
$variable = mysql_query(SELECT * FROM blah);
if(!$variable) { error_handler(mysql_error()); }
in terms of readability an alternative if to write it like so:
if(! ($variable = mysql_query(SELECT * FROM blah)) {
// do stuff
}
what you have to realise is that the expression '$variable = mysql_query(SELECT * 
FROM blah)'
has a return value itself - which just happens to be the same as the value of 
$variable.
to put it another way, when you do:
echo $variable;
your not saying:
 output the contents of this variable
but your actually saying:
 output the result of the expression '$variable'
it just so happens that the result of the expression is this case
if the contents of $variable.
hopefully you get what I mean!, no doubt there are others that can explain it 
better!
See the documentation for information on mysql_query return values:
http://us2.php.net/manual/en/function.mysql-query.php
Jason
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] sql query

2005-03-02 Thread William Stokes
Hello

Can someone explain this to me. I don't know how to read this.

if (!$variable = mysql_query(select id,sessid from users where ...

What is this if(!

I mean the ! sign.

Thanks

-Will

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



Re: [PHP] sql query

2005-03-02 Thread Jason Petersen
On Wed, 2 Mar 2005 13:02:39 +0200, William Stokes [EMAIL PROTECTED] wrote:
 Hello
 
 Can someone explain this to me. I don't know how to read this.
 
 if (!$variable = mysql_query(select id,sessid from users where ...
 
 What is this if(!

This is a way to run a SQL query, capture the return value, and
perform an action if the query failed. For code readability, I would
probably write that as two statements:

$variable = mysql_query(SELECT * FROM blah);
if(!$variable) { error_handler(mysql_error()); }

See the documentation for information on mysql_query return values:
http://us2.php.net/manual/en/function.mysql-query.php

Jason

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



Re: [PHP] sql query

2005-03-02 Thread William Stokes
OK got that. Thanks...


Jason Petersen [EMAIL PROTECTED] kirjoitti 
viestissä:[EMAIL PROTECTED]
 On Wed, 2 Mar 2005 13:02:39 +0200, William Stokes [EMAIL PROTECTED] 
 wrote:
 Hello

 Can someone explain this to me. I don't know how to read this.

 if (!$variable = mysql_query(select id,sessid from users where ...

 What is this if(!

 This is a way to run a SQL query, capture the return value, and
 perform an action if the query failed. For code readability, I would
 probably write that as two statements:

 $variable = mysql_query(SELECT * FROM blah);
 if(!$variable) { error_handler(mysql_error()); }

 See the documentation for information on mysql_query return values:
 http://us2.php.net/manual/en/function.mysql-query.php

 Jason 

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



[PHP] SQL Query Statement for MySQL... (DataType -- TEXT vs BLOB)

2004-06-10 Thread Scott Fletcher
I'm wrestling over deciding on which data type to go with, TEXT or BLOB.  I
have one table with one column of 400 characters, I was thinking that TEXT
may be the way to go for that one.

I also have another table that use 4 columns of 800 characters along with 5
columns that use 250 characters.  I'm thinking of using TEXT for 9 of those
columns.

The reason is because I read the MySQL Manual there that say TEXT and BLOB
are pretty much the same in many ways, the only thing different is that BLOB
use VARCHAR Binary while TEXT use VARCHAR.  But reading the article
somewhere (not part of MySQL's Manual) say this...

--snip--
If it doesn't have to be searchable then a BLOB might be more efficient and
you shouldn't have to worry about size (Like size is important?  ). The
reason being that BLOB information is stored seperate from the table data
and is related by a reference number in the table. This keeps the table
smaller and faster as I understand.
--snip--

So, I don't feel too sure what to decide on...  Care for some advice or
recommendation??

Thanks,
 Scott Fletcher


begin 666 eek.gif
M1TE.#EA$ `0`/Z`/___P```-7__\___\O+S `$N3DYOL]@*#QD9'?]]
M``0(#3)%2#)'[EMAIL PROTECTED]/65_O6HQ24X.RI2KV\Q0/%+PM[R\Q#PP, H3/+R
M_+V]QN7EYG*O_[CSTQ,4^!8!_/S_OK]CJ] ,]35/]^`+O__]?:XS1
M24%OZE1*3K?__P`6+G)RG.QS^7__UQPF3-76.G__S\\.X'%_X___'N[+?!
MTZ7__WLG`*7[_\# P$Q19[EMAIL PROTECTED]:6VPY#=_WW^M+2TW-U=3A@
M;EF,_WV-GFZST8O:^R=%:TL\.S1,3XVAKBQ5PG1I:\G#PYZLT(^9M'M[?7K!
M_S5-48%AX:J+BXP51_T7J,H#HV-=O;Y1]!B@(.3X!(2$S]IAH:'@`1
M)@4'#BU#1YSO_[VOR)F0\/%!L9KJ[PZS__[R\O?KX^9W@,A'M?__T)
M1Z/Z_WBAI./CY T-#;/%T2DY/KRSLLG'RM___U$IVVLTMK[E \WEPG_!
M_U=.0A X?4_UZ,MT^,HF.BO.;H\]#*RSQ98=78YM#/TA0_6N[KZN'D[P`7
M-P(!?OW]M[Z.KFY^5;!2M07C8D'I24FT-MXC-?;S\_0ZZNK\2ZNEB CY+ 
MU31W2PA*V*?NE)2604'#(BNP'HR0`4'WVKKP(!!8/'[S]KRZGIW8FK2^
MRP8'4Q7VDI[WP#8K*IJ:[EMAIL PROTECTED]/7U_P``
M
M
M
M
M`'Y! $``+H`+ `0`! `0 C_`'7IHD2*$YM0
M3K!TF##'0Q!II08^:+*C!P9+P9(D#1BR9$'M5H!2) +0*4\$ `*,0*=,
MND1L\F,H`()3L18$T (H32)=( ! [EMAIL PROTECTED]((M(@`)(AR!JE*ES5X:$TSA1(
MAU:[EMAIL PROTECTED]`B^C0*/3DCT!=( [EMAIL PROTECTED], ZU:7ACALB,U -J4*2Z,=
M86;ILE $P 8[`#R1B*$'@ $#`*AD07,%`($6`!0U:!+%\AX`/2J LL7DT9M 
M% 0(P [EMAIL PROTECTED]:[EMAIL PROTECTED]:[EMAIL PROTECTED]@=-
8LZN-2'!:X2G)$8N6%T=RS/EXA!MER0^[@ `[
`
end

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



RE: [PHP] SQL Query Statement for MySQL... (DataType -- TEXT vs BLOB)

2004-06-10 Thread Dennis Seavers
Probably a good question for a MySQL e-mail list.


 [Original Message]
 From: Scott Fletcher [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Date: 06/10/2004 12:49:07 PM
 Subject: [PHP] SQL Query Statement for MySQL...  (DataType -- TEXT vs
BLOB)

 I'm wrestling over deciding on which data type to go with, TEXT or BLOB. 
I
 have one table with one column of 400 characters, I was thinking that TEXT
 may be the way to go for that one.

 I also have another table that use 4 columns of 800 characters along with
5
 columns that use 250 characters.  I'm thinking of using TEXT for 9 of
those
 columns.

 The reason is because I read the MySQL Manual there that say TEXT and BLOB
 are pretty much the same in many ways, the only thing different is that
BLOB
 use VARCHAR Binary while TEXT use VARCHAR.  But reading the article
 somewhere (not part of MySQL's Manual) say this...

 --snip--
 If it doesn't have to be searchable then a BLOB might be more efficient
and
 you shouldn't have to worry about size (Like size is important?  ). The
 reason being that BLOB information is stored seperate from the table data
 and is related by a reference number in the table. This keeps the table
 smaller and faster as I understand.
 --snip--

 So, I don't feel too sure what to decide on...  Care for some advice or
 recommendation??

 Thanks,
  Scott Fletcher



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

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



[PHP] sql query question

2004-02-12 Thread tony
hi

if i have  new  car and i want to search
each word in description
can i do
SELECT * FROM table WHERE
descript = new OR descript =car??

any help is appreciated

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



RE: [PHP] R: [PHP] SQL Query Not Kosher?

2004-02-04 Thread Ford, Mike [LSS]
On 03 February 2004 13:45, Alessandro Vitale contributed these pearls of
wisdom:

 try removing curly braces as follows:
 
 $query = mysql_query(UPDATE stories SET status='approved'
WHERE story_id={$id}); |

Nothing wrong with the above, it's perfectly valid -- just a slightly
different way of writing:

 $query = mysql_query(UPDATE stories SET status='approved'
 WHERE story_id=${id}); 

Cheers!

Mike

-- 
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

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



Re: [PHP] SQL Query Not Kosher?

2004-02-03 Thread Marek Kilimajer
The argument to mysql_affected_rows must be mysql CONNECTION identifier 
(from mysql_connect), not RESULT identifier (from mysql_query). Removing 
the argument will work for you.

Mr. Austin wrote:

Hi all:

I am trying to get this to work, but always get the same error: that the resource in mysql_affected_rows() is not valid.  Anyone see why this would be?  All variables have been tested for accuracy.

$query = mysql_query(UPDATE stories SET status='approved' WHERE story_id={$id});
  if(mysql_affected_rows($query) == 1) {
print(Your approval of \$title\ was successful.  If this user entered an email 
address, they have been sent a notice of its approval and publication on the site.);
  } else {
print(The approval of \$title\ was not successful.  Please check with the site 
administrator for assistance.);
  }
The above SQL statement works perfectly with phpMyAdmin (and, oddly enough, works with the above script, yet the Warning is produced and the 'not successful' message is displayed)  Any thoughts are appreciated!

Mr. Austin

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


[PHP] R: [PHP] SQL Query Not Kosher?

2004-02-03 Thread Alessandro Vitale
try removing curly braces as follows:

$query = mysql_query(UPDATE stories SET status='approved' WHERE
story_id={$id});
   |
   |
   |
  \/
$query = mysql_query(UPDATE stories SET status='approved' WHERE
story_id=$id);

or

$query = mysql_query(UPDATE stories SET status='approved' WHERE
story_id=${id});



this applies if story_id is of type int in mysql table definition, or you
should enclose it among '' if is of type char, varchar or similar.

cheers

alessandro




-Messaggio originale-
Da: Mr. Austin [mailto:[EMAIL PROTECTED]
Inviato: martedì 3 febbraio 2004 5.35
A: [EMAIL PROTECTED]
Oggetto: [PHP] SQL Query Not Kosher?


Hi all:

I am trying to get this to work, but always get the same error: that the
resource in mysql_affected_rows() is not valid.  Anyone see why this would
be?  All variables have been tested for accuracy.

$query = mysql_query(UPDATE stories SET status='approved' WHERE
story_id={$id});
  if(mysql_affected_rows($query) == 1) {
print(Your approval of \$title\ was successful.  If this user entered
an email address, they have been sent a notice of its approval and
publication on the site.);
  } else {
print(The approval of \$title\ was not successful.  Please check with
the site administrator for assistance.);
  }

The above SQL statement works perfectly with phpMyAdmin (and, oddly enough,
works with the above script, yet the Warning is produced and the 'not
successful' message is displayed)  Any thoughts are appreciated!

Mr. Austin

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



[PHP] SQL Query Not Kosher?

2004-02-02 Thread Mr. Austin
Hi all:

I am trying to get this to work, but always get the same error: that the resource in 
mysql_affected_rows() is not valid.  Anyone see why this would be?  All variables have 
been tested for accuracy.

$query = mysql_query(UPDATE stories SET status='approved' WHERE story_id={$id});
  if(mysql_affected_rows($query) == 1) {
print(Your approval of \$title\ was successful.  If this user entered an email 
address, they have been sent a notice of its approval and publication on the site.);
  } else {
print(The approval of \$title\ was not successful.  Please check with the site 
administrator for assistance.);
  }

The above SQL statement works perfectly with phpMyAdmin (and, oddly enough, works with 
the above script, yet the Warning is produced and the 'not successful' message is 
displayed)  Any thoughts are appreciated!

Mr. Austin


Re: [PHP] SQL Query Not Kosher?

2004-02-02 Thread Mr. Austin
That would explain why it displays the second message saying it was not
successful.  But why then does it still display this warning?

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link
resource in c:\apache\htdocs\admin\stories.php on line 112

Mr. Austin
- Original Message -
From: Jochem Maas [EMAIL PROTECTED]
To: Mr. Austin [EMAIL PROTECTED]
Sent: Monday, February 02, 2004 10:41 PM
Subject: Re: [PHP] SQL Query Not Kosher?


 from the php function manual:

 quote
 Note: When using UPDATE, MySQL will not update columns where the new
 value is the same as the old value. This creates the possibility that
 mysql_affected_rows() may not actually equal the number of rows matched,
 only the number of rows that were literally affected by the query.
 /quote

 http://nl2.php.net/mysql_affected_rows

 Mr. Austin wrote:

  Hi all:
 
  I am trying to get this to work, but always get the same error: that the
resource in mysql_affected_rows() is not valid.  Anyone see why this would
be?  All variables have been tested for accuracy.
 
  $query = mysql_query(UPDATE stories SET status='approved' WHERE
story_id={$id});
if(mysql_affected_rows($query) == 1) {
  print(Your approval of \$title\ was successful.  If this user
entered an email address, they have been sent a notice of its approval and
publication on the site.);
} else {
  print(The approval of \$title\ was not successful.  Please check
with the site administrator for assistance.);
}
 
  The above SQL statement works perfectly with phpMyAdmin (and, oddly
enough, works with the above script, yet the Warning is produced and the
'not successful' message is displayed)  Any thoughts are appreciated!
 
  Mr. Austin
 



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



[PHP] sql query and some math

2003-12-17 Thread Patrik Fomin
Hi,

q1)
i got a database with 2 diffrent tables,
i want to take out all the information that arent duplicated from
on of the tables, like this:

$sql = SELECT t1.rubrik, t1.info, t2.priser FROM table1 AS t1, table2 AS t2
WHERE t1.arkiv = '0' ORDER BY t1.rubrik;

the problem is that i got alot of duplicates (its for another purpose), so i
need to filter out the duplicates in the rubrik field to get just one match
each, like:

id - rubrik - info

0 -  - some info
1 -  - some info
2 -  - some info
3 -  - some info
4 -  - some info

would print out
0 -  - some info
1 -  - some info
2 -  - some info
3 -  - some info


q2)
i got like 100 matches from a database into a $num variable,
then i want to devide that by 3 aslong as it can be done, eg:

while ($num != 0) {

ïf ($num / 3 = true){
some code to display some fields from a database

$num = $num - 3;
}
else {
some other code to display
$num = 0;
}
}

basicly i want the if statement to check if its more then 3 posts left to
print out, if not its gonna print out the remaining last 1 - 2 post in a
diffrent way (for the looks)


regards
patrick

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



RE: [PHP] sql query and some math

2003-12-17 Thread Jay Blanchard
[snip]
q1)
i got a database with 2 diffrent tables,
i want to take out all the information that arent duplicated from
on of the tables, like this:

$sql = SELECT t1.rubrik, t1.info, t2.priser FROM table1 AS t1, table2 AS t2
WHERE t1.arkiv = '0' ORDER BY t1.rubrik;
[/snip]

It's a SQL question, but I'll answer...

$sql = SELECT DISTINCT(t1.rubrik), t1.info, t2.priser FROM table1 AS t1, table2 AS t2
WHERE t1.arkiv = '0' ORDER BY t1.rubrik;

[snip]
q2)
i got like 100 matches from a database into a $num variable,
then i want to devide that by 3 aslong as it can be done, eg:

while ($num != 0) {

ïf ($num / 3 = true){
some code to display some fields from a database

$num = $num - 3;
}
else {
some other code to display
$num = 0;
}
}

basicly i want the if statement to check if its more then 3 posts left to
print out, if not its gonna print out the remaining last 1 - 2 post in a
diffrent way (for the looks)
[/snip]

if(($num / 3) == true)

Happy Holidays!

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



[PHP] sql query/displaying results question

2003-10-23 Thread Adam Williams
I have a php page I am writing with an SQL query.  I am going to query the 
database for a couple of fields.  One of the fields I am querying is the 
title oh the document someone is searching for.  The title will be used at 
the top of the html page and will say:

you are searching for document number ###: document $title 

but then later on down on the page when it starts returning your results:

document $title: document $location

So I will have 1 query that needs to print the document $title at the top 
of the page and then when it starts showing results.  I won't know what 
the document title is until the database is queried (because they are 
doing a query for keywords in the documents stored in that table in the 
database).  So at the top of the page can I use my $title from the 
database and then when I start showing the results, can I show the same 
document $title from the 1st row returned if I am using a while loop, or 
because I already used $title at the top from the 1st row returned, will 
it want to start at the 2nd row returned when I start my while loop to 
return all of the data?

Adam

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



Re: [PHP] sql query/displaying results question

2003-10-23 Thread Jason Wong
On Thursday 23 October 2003 22:06, Adam Williams wrote:

 So I will have 1 query that needs to print the document $title at the top
 of the page and then when it starts showing results.  I won't know what
 the document title is until the database is queried (because they are
 doing a query for keywords in the documents stored in that table in the
 database).  So at the top of the page can I use my $title from the
 database and then when I start showing the results, can I show the same
 document $title from the 1st row returned if I am using a while loop, or
 because I already used $title at the top from the 1st row returned, will
 it want to start at the 2nd row returned when I start my while loop to
 return all of the data?

After displaying $title use mysql_data_seek() to return to start of results 
dataset.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
I learned to play guitar just to get the girls, and anyone who says they
didn't is just lyin'!
-- Willie Nelson
*/

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



[PHP] SQL Query OT question for the experts :)

2003-10-17 Thread Andrew Brampton
Hi,
I have a client with a database of around 17k entries. Now due to powers out
of my control the table structure looks like:

CREATE TABLE londonhotelsallphotos (
  HotelID double default NULL,
  active_hotel_photo_Name varchar(255) default NULL,
  URL varchar(255) default NULL,
  Number varchar(50) default NULL,
  Name varchar(255) default NULL
) TYPE=MyISAM;

and a few example rows look like:
(105304,NULL,'http://blah/photos/105304/BAB105304.jpg','1','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/CAB105304.jpg','2','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/DAB105304.jpg','3','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/EAB105304.jpg','4','Cairn Hotel');

However the client has recently updated the database and now all entries
look something like:
(105304,NULL,'http://blah/photos/105304/AAB105304.jpg',NULL,NULL);
(105304,NULL,'http://blah/photos/105304/DAB105304.jpg',NULL,NULL);
(105304,NULL,'http://blah/photos/105304/BAB105304_2.jpg',NULL,NULL);
(105304,NULL,'http://blah/photos/105304/BAB105304_3.jpg',NULL,NULL);

Now you will notice that the last 3 fields have changed... The client wanted
to change the URL field, but also changed the Number  Name fields With
the current coding it appears they require the Number field to be set to 1,
2, 3, 4 etc... However as you can see the number field are all NULL now,
this is meaning the rows aren't being shown on the PHP page due to the way
the page was coded..

Now what I'm asking is for a SQL Query I can use to re-number all the rows
(17,000 ish). The table has many different HotelIDs in it, with at most 5
rows with the same ID meaning that the Number field won't be higher than 5.
The URL field I think is always unique for all the rows Also I don't
mind that the Name field is left NULL.

A few example rows would be:
(105304,NULL,'http://blah/photos/105304/BAB105304.jpg','1','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/CAB105304.jpg','2','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/DAB105304.jpg','3','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/EAB105304.jpg','4','Cairn Hotel');
(105356,NULL,'http://blah/photos/105356/EAB105356.jpg','1','Ramada Jarvis
Bolton');
(105356,NULL,'http://blah/photos/105356/CAB105498.jpg','2','Ramada Jarvis
Bolton');

If I can't do this with some quick and dirty SQL, I'll write some PHP to do
the process, but since I'm not being paid to fix this problem, and the
client caused it himself I thought I'll take the easier option of using SQL
before I wrote some code out of kindness...

Thanks very much
Andrew

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



Re: [PHP] SQL Query OT question for the experts :)

2003-10-17 Thread Marek Kilimajer
I think you (or me) will make some php code out of kindness. Order the 
rows by the id (still there should be some REALLY uniq id) ad then 
update the same row with a variable that you reset each time that you 
encounter new id.

$i=0;
while($row=...) {
 if($prev != $row['HotelID']) {
  $i=0;
  $prev = $row['HotelID'];
 }
 $i++;
 update londonhotelsallphotos set Number=$i where URL=$row['URL']
}



Andrew Brampton wrote:
Hi,
I have a client with a database of around 17k entries. Now due to powers out
of my control the table structure looks like:
CREATE TABLE londonhotelsallphotos (
  HotelID double default NULL,
  active_hotel_photo_Name varchar(255) default NULL,
  URL varchar(255) default NULL,
  Number varchar(50) default NULL,
  Name varchar(255) default NULL
) TYPE=MyISAM;
and a few example rows look like:
(105304,NULL,'http://blah/photos/105304/BAB105304.jpg','1','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/CAB105304.jpg','2','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/DAB105304.jpg','3','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/EAB105304.jpg','4','Cairn Hotel');
However the client has recently updated the database and now all entries
look something like:
(105304,NULL,'http://blah/photos/105304/AAB105304.jpg',NULL,NULL);
(105304,NULL,'http://blah/photos/105304/DAB105304.jpg',NULL,NULL);
(105304,NULL,'http://blah/photos/105304/BAB105304_2.jpg',NULL,NULL);
(105304,NULL,'http://blah/photos/105304/BAB105304_3.jpg',NULL,NULL);
Now you will notice that the last 3 fields have changed... The client wanted
to change the URL field, but also changed the Number  Name fields With
the current coding it appears they require the Number field to be set to 1,
2, 3, 4 etc... However as you can see the number field are all NULL now,
this is meaning the rows aren't being shown on the PHP page due to the way
the page was coded..
Now what I'm asking is for a SQL Query I can use to re-number all the rows
(17,000 ish). The table has many different HotelIDs in it, with at most 5
rows with the same ID meaning that the Number field won't be higher than 5.
The URL field I think is always unique for all the rows Also I don't
mind that the Name field is left NULL.
A few example rows would be:
(105304,NULL,'http://blah/photos/105304/BAB105304.jpg','1','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/CAB105304.jpg','2','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/DAB105304.jpg','3','Cairn Hotel');
(105304,NULL,'http://blah/photos/105304/EAB105304.jpg','4','Cairn Hotel');
(105356,NULL,'http://blah/photos/105356/EAB105356.jpg','1','Ramada Jarvis
Bolton');
(105356,NULL,'http://blah/photos/105356/CAB105498.jpg','2','Ramada Jarvis
Bolton');
If I can't do this with some quick and dirty SQL, I'll write some PHP to do
the process, but since I'm not being paid to fix this problem, and the
client caused it himself I thought I'll take the easier option of using SQL
before I wrote some code out of kindness...
Thanks very much
Andrew
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] SQL Query OT question for the experts :)

2003-10-17 Thread Nicholas Robinson
The following works in MySQL, but obviously (and unlike your client!) you'll 
want to do this on a copy of the table first...

update londonhotelsallphotos set Number = ( if (@hi != HotelID, @line := 1, 
@line := @line + 1)), HotelID = (@hi := HotelID)

Note that if you run this query more than once, you'll need to reset @line 
manually in between otherwise the first hotelid will have not have numbers 
running from 1, but from n+1 where n was the maximum number of the last hotel 
id.

Nick

On Friday 17 Oct 2003 9:09 pm, Andrew Brampton wrote:
 Hi,
 I have a client with a database of around 17k entries. Now due to powers
 out of my control the table structure looks like:

 CREATE TABLE londonhotelsallphotos (
   HotelID double default NULL,
   active_hotel_photo_Name varchar(255) default NULL,
   URL varchar(255) default NULL,
   Number varchar(50) default NULL,
   Name varchar(255) default NULL
 ) TYPE=MyISAM;

 and a few example rows look like:
 (105304,NULL,'http://blah/photos/105304/BAB105304.jpg','1','Cairn Hotel');
 (105304,NULL,'http://blah/photos/105304/CAB105304.jpg','2','Cairn Hotel');
 (105304,NULL,'http://blah/photos/105304/DAB105304.jpg','3','Cairn Hotel');
 (105304,NULL,'http://blah/photos/105304/EAB105304.jpg','4','Cairn Hotel');

 However the client has recently updated the database and now all entries
 look something like:
 (105304,NULL,'http://blah/photos/105304/AAB105304.jpg',NULL,NULL);
 (105304,NULL,'http://blah/photos/105304/DAB105304.jpg',NULL,NULL);
 (105304,NULL,'http://blah/photos/105304/BAB105304_2.jpg',NULL,NULL);
 (105304,NULL,'http://blah/photos/105304/BAB105304_3.jpg',NULL,NULL);

 Now you will notice that the last 3 fields have changed... The client
 wanted to change the URL field, but also changed the Number  Name
 fields With the current coding it appears they require the Number field
 to be set to 1, 2, 3, 4 etc... However as you can see the number field are
 all NULL now, this is meaning the rows aren't being shown on the PHP page
 due to the way the page was coded..

 Now what I'm asking is for a SQL Query I can use to re-number all the rows
 (17,000 ish). The table has many different HotelIDs in it, with at most 5
 rows with the same ID meaning that the Number field won't be higher than 5.
 The URL field I think is always unique for all the rows Also I don't
 mind that the Name field is left NULL.

 A few example rows would be:
 (105304,NULL,'http://blah/photos/105304/BAB105304.jpg','1','Cairn Hotel');
 (105304,NULL,'http://blah/photos/105304/CAB105304.jpg','2','Cairn Hotel');
 (105304,NULL,'http://blah/photos/105304/DAB105304.jpg','3','Cairn Hotel');
 (105304,NULL,'http://blah/photos/105304/EAB105304.jpg','4','Cairn Hotel');
 (105356,NULL,'http://blah/photos/105356/EAB105356.jpg','1','Ramada Jarvis
 Bolton');
 (105356,NULL,'http://blah/photos/105356/CAB105498.jpg','2','Ramada Jarvis
 Bolton');

 If I can't do this with some quick and dirty SQL, I'll write some PHP to do
 the process, but since I'm not being paid to fix this problem, and the
 client caused it himself I thought I'll take the easier option of using SQL
 before I wrote some code out of kindness...

 Thanks very much
 Andrew

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



[PHP] SQL Query request is just hanging.

2003-08-27 Thread Larry_Li
I'm using IIS5.0 on W2k. I have upgraded w2k to sp4 and ms sql server to 
sp3. I created a new table and just do a simple query in php program. But 
it seems sql server doesn't return any query result. I'm using 
mssql_fetch_array() function, but no any return. PHP program is just 
pending there. I checked process info and found wait type is NETWORKIO. No 
problem for other existing queries. Only this new one. Almost got 
crazy

Any idea, Thanks a lot!

Larry


RE: [PHP] SQL Query request is just hanging.

2003-08-27 Thread Jay Blanchard
[snip]
I'm using IIS5.0 on W2k. I have upgraded w2k to sp4 and ms sql server to

sp3. I created a new table and just do a simple query in php program.
But 
it seems sql server doesn't return any query result. I'm using 
mssql_fetch_array() function, but no any return. PHP program is just 
pending there. I checked process info and found wait type is NETWORKIO.
No 
problem for other existing queries. Only this new one. Almost got 
crazy
[/snip]

Can we see the query? The code? It would probably help.

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



[PHP] SQL Query slow with 'Select' ....

2003-07-09 Thread Scott Fletcher
I noticed that database are very quick with the SQL Query string such as
Insert, Delete and Update.  But with Select, it become very slow.  I noticed
that I can do the INT() or DOUBLE() for one of the field when using Select
and it become very quick.  But I am unable to make it work for CHAR() or
varchar for MS-SQL.  Does anyone know?

Thanks...



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



[PHP] SQL Query

2003-02-14 Thread Zydox
I have a problem writing a query that can select a Interest for a specific
user... There are tvo tables, IList and IIndex...
IList contains this :
  ID  SubID  Interest  Valid
  Edit  Delete  1 0 Datorer 0
  Edit  Delete  2 1 Spel 0
  Edit  Delete  3 2 Strategi 0
  Edit  Delete  4 3 Star Craft 1
  Edit  Delete  5 3 Star Wars: Gallactic Battelinggrounds 1
  Edit  Delete  6 2 Shoot-Em-Up 0
  Edit  Delete  7 6 Half-Life 0
  Edit  Delete  8 7 Team Fortress 1
  Edit  Delete  9 7 Counter-Strike 1


And IIndex contains a UserID And InterestID... this query :
SELECT DISTINCTROW InterestsList.ID, InterestsList.SubID,
InterestsList.Interest, InterestsList.Valid FROM InterestsList AS II RIGHT
JOIN InterestsList ON InterestsList.ID=II.SubID LEFT JOIN InterestsIndex ON
InterestsList.ID=InterestsIndex.InterestID AND InterestsIndex.UserID='1'

Selects all rows from IList... even if there Is'nt any instans in IIndex...
this thougt is that a User can choose a Valid Interest and then the query
should select all SubInterests... anyone know how to do that ?

// Regards Zydox



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




RE: [PHP] SQL Query

2003-02-14 Thread Dennis Cole
There is a nice piece of software that you should get,
http://ems-hitech.com/mymanager/! It's not free, but you can download a
trial. (I would get it) It is great for building querys across tables.

-Original Message-
From: Zydox [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 14, 2003 11:18 PM
To: [EMAIL PROTECTED]
Subject: [PHP] SQL Query


I have a problem writing a query that can select a Interest for a specific
user... There are tvo tables, IList and IIndex...
IList contains this :
  ID  SubID  Interest  Valid
  Edit  Delete  1 0 Datorer 0
  Edit  Delete  2 1 Spel 0
  Edit  Delete  3 2 Strategi 0
  Edit  Delete  4 3 Star Craft 1
  Edit  Delete  5 3 Star Wars: Gallactic Battelinggrounds 1
  Edit  Delete  6 2 Shoot-Em-Up 0
  Edit  Delete  7 6 Half-Life 0
  Edit  Delete  8 7 Team Fortress 1
  Edit  Delete  9 7 Counter-Strike 1


And IIndex contains a UserID And InterestID... this query :
SELECT DISTINCTROW InterestsList.ID, InterestsList.SubID,
InterestsList.Interest, InterestsList.Valid FROM InterestsList AS II RIGHT
JOIN InterestsList ON InterestsList.ID=II.SubID LEFT JOIN InterestsIndex ON
InterestsList.ID=InterestsIndex.InterestID AND InterestsIndex.UserID='1'

Selects all rows from IList... even if there Is'nt any instans in IIndex...
this thougt is that a User can choose a Valid Interest and then the query
should select all SubInterests... anyone know how to do that ?

// Regards Zydox



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


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




[PHP] SQL Query (Group By)

2002-04-30 Thread Andrew Brampton

Hi,
This is more a SQL question that a php one, but here goes:

I have a table with 3 fields, Date, IP, ISP.
Basically I have written some php to store the following in the table each time 
someone hits a page on my site. Now I want to display some info about the users 
currently on my site, but I want to try and do it with 1 SQL query.

Basically I want to display a count of how many unique IPs there are on my site from 
each ISP... for example
3 NTL 
1 BT
5 Freeserve

but in each group there will be more than 1 entry for each user due to them causing a 
row in the table on each hit. I can't seem to group it together how I want with 1 
query. The best I can do is count how many rows are from each IP (but this figure is 
too high since it doesn't take into account that the IPs must be unique). Here is my 
current SQL:

$sql = SELECT ISP, COUNT(*) as total FROM track GROUP BY ISP ORDER BY total DESC;

I could make this work by doing some sorting in PHP once I get the data, but I would 
prefer to do it with SQL... Anyone know how to do what I want?

Thanks
Andrew



[PHP] SQL Query Question

2001-12-08 Thread Andrew Brampton

Hi,
This isn't a php question, more of a SQL question, but I don't know any where better 
to send it, and I guess its trival enough for someone here to answer.

Anyway, I have a list of members each with a score field. How can I say that Member 3 
is ranked 10 out of 100 members for example.

Here is the layout of the members table:
ID, Name, Score

I can get the total count of members in the table, but I don't know how to determine 
what rank they are, unless I return all the rows in the table (sorted), and cycle 
through them until I find the member I want, counting how many people are above him... 
This method would work, but would be slow (and wastful), is there a better way to 
determine his position with a SQL Query?

Thanks in advance
Andrew

P.S
If it matters I'm using MySQL  PHP 4.0.6 on WinXP under Apache 1.3.22



Re: [PHP] SQL Query Question

2001-12-08 Thread Jason G.


Assuming you have the variable member_id (for the member in question)...
Get the score for that member and store it to $score...

SELECT score FROM members WHERE id=$member_id

Then to determine rank, just do this...
SELECT COUNT(*)+1 as rank FROM members WHERE SCORE$score;

-Jason Garber
IonZoft.com

At 08:47 PM 12/8/2001 +, Andrew Brampton wrote:
Hi,
This isn't a php question, more of a SQL question, but I don't know any 
where better to send it, and I guess its trival enough for someone here to 
answer.

Anyway, I have a list of members each with a score field. How can I say 
that Member 3 is ranked 10 out of 100 members for example.

Here is the layout of the members table:
ID, Name, Score

I can get the total count of members in the table, but I don't know how to 
determine what rank they are, unless I return all the rows in the table 
(sorted), and cycle through them until I find the member I want, counting 
how many people are above him... This method would work, but would be slow 
(and wastful), is there a better way to determine his position with a SQL 
Query?

Thanks in advance
Andrew

P.S
If it matters I'm using MySQL  PHP 4.0.6 on WinXP under Apache 1.3.22


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] sql query with join and same column twice...

2001-08-30 Thread Web Manager

Hello,

Here are 2 tables:

airport
-
airport_id
name
code
city_id


destination
---
destination_id
dest_name
airport_dep_id  // using airport.airport_id (departure)
airport_arr_id  // using airport.airport_id  has well (arrival)


I have 2 columns in the second table that uses the same name column in
the first table...

I dont know how to formulate my SQL query... I want to select the
destinations in the destination table with not the ID of each airport
but their names. I can do a join with one but with the second one, I get
no results... And this is confusing!

select dest.dest_name, air.name as airport1, air.name as airport2 from
destination, airport air where dest.airport_dep_id_id=air.airport_id and
dest.airport_arr_id=air.airport_id;

This is not good...

Any help?

Thanks!
--
Marc Andre Paquin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] sql query with join and same column twice...

2001-08-30 Thread ERISEN, Mehmet Kamil

Please try
select dest.dest_name, 
   air.name as airport1, 
  air2.name as airport2 
from destination, 
 airport air,
 airport air2
where dest.airport_dep_id_id=air.airport_id and
dest.airport_arr_id=air2.airport_id;

you can use the same table as manu times as you like in
sql. 
It's calld a self join if my memory  does not fail me.
--- Web Manager [EMAIL PROTECTED] wrote:
 Hello,
 
 Here are 2 tables:
 
 airport
 -
 airport_id
 name
 code
 city_id
 
 
 destination
 ---
 destination_id
 dest_name
 airport_dep_id  // using airport.airport_id (departure)
 airport_arr_id  // using airport.airport_id  has well
 (arrival)
 
 
 I have 2 columns in the second table that uses the same
 name column in
 the first table...
 
 I dont know how to formulate my SQL query... I want to
 select the
 destinations in the destination table with not the ID of
 each airport
 but their names. I can do a join with one but with the
 second one, I get
 no results... And this is confusing!
 
 select dest.dest_name, air.name as airport1, air.name as
 airport2 from
 destination, airport air where
 dest.airport_dep_id_id=air.airport_id and
 dest.airport_arr_id=air.airport_id;
 
 This is not good...
 
 Any help?
 
 Thanks!
 --
 Marc Andre Paquin
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 To contact the list administrators, e-mail:
 [EMAIL PROTECTED]
 


=
Mehmet Erisen
http://www.erisen.com

__
Do You Yahoo!?
Get email alerts  NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] sql query successful

2001-07-18 Thread Tyler Longren

Hello everyone,

I've been writing database enabled site for quite a while now.  One thing I
have never figured out it how to determine if a sql query is successful.

This works:
if ($connection = mysql_connect(host,username,password)) {
print Successful connection:
}
else {
print No connection;
}

But this won't work:

if ($sql = mysql_query(SELECT * FROM table ORDER BY rand())) {
print SQL executed successfully.;
}
else {
print SQL not executed successfully.;
}

Can anyone tell me how I can tell if the SQL executed successfully?  Is
there any method besides OR DIE?

Thanks,
Tyler


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] sql query successful

2001-07-18 Thread Mark Roedel

 -Original Message-
 From: Tyler Longren [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, July 18, 2001 1:25 PM
 To: php-general
 Subject: [PHP] sql query successful
 
 
 I've been writing database enabled site for quite a while 
 now.  One thing I have never figured out it how to determine
 if a sql query is successful.
 
 This works:
 if ($connection = mysql_connect(host,username,password)) {
 print Successful connection:
 }
 else {
 print No connection;
 }
 
 But this won't work:
 
 if ($sql = mysql_query(SELECT * FROM table ORDER BY rand())) {
 print SQL executed successfully.;
 }
 else {
 print SQL not executed successfully.;
 }

In what way doesn't this work?

The above code should tell you that the query was properly formed and
error-free, and was cheerfully accepted and processed by the database
server.  (You don't get much more successful than that...)

If what you're really looking for is whether there were any rows
returned by the query, then you'll want to look into the
mysql_num_rows() function.


---
Mark Roedel ([EMAIL PROTECTED])  ||  There cannot be a crisis next week.
Systems Programmer / WebMaster  ||   My schedule is already full.
 LeTourneau University  ||-- Henry Kissinger


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] sql query successful

2001-07-18 Thread Hoover, Josh

I believe you should use the error function for the database you're using to
check for failed queries.  If you're using MySQL (which it appears that you
are), you would do something like this:

$sql = mysql_query(SELECT * FROM table ORDER BY rand());

if(mysql_error())
echo SQL not executed successfully.;
else
print SQL executed successfully.;


Josh Hoover
KnowledgeStorm, Inc.
[EMAIL PROTECTED]

Searching for a new IT solution for your company? Need to improve your
product marketing? 
Visit KnowledgeStorm at www.knowledgestorm.com to learn how we can simplify
the process for you.
KnowledgeStorm - Your IT Search Starts Here 


 This works:
 if ($connection = mysql_connect(host,username,password)) {
 print Successful connection:
 }
 else {
 print No connection;
 }
 
 But this won't work:
 
 if ($sql = mysql_query(SELECT * FROM table ORDER BY rand())) {
 print SQL executed successfully.;
 }
 else {
 print SQL not executed successfully.;
 }
 
 Can anyone tell me how I can tell if the SQL executed 
 successfully?  Is
 there any method besides OR DIE? 



Re: [PHP] sql query successful

2001-07-18 Thread Tyler Longren

What about when DELETING from a table???  It always returns true.
Example...the highest ID in this table is 10:

?
if ($connection = mysql_connect(localhost,mysql,mysql)) {
print Connection established;
$db = mysql_select_db(aanr, $connection);
if ($sql = mysql_query(DELETE FROM bullitens WHERE id='1212')) {
print Successful;
}
else {
print Not successful.;
}
}
else {
print Connection NOT established.;
}
?

We try to delete the bulliten with id of 1212, but there is not bulliten
with that ID, and it says Successful.

I know I could use mysql_affected_rows(), but why doesn't this work???

Tyler

- Original Message -
From: Mark Roedel [EMAIL PROTECTED]
To: Tyler Longren [EMAIL PROTECTED]; php-general
[EMAIL PROTECTED]
Sent: Wednesday, July 18, 2001 1:30 PM
Subject: RE: [PHP] sql query successful


 -Original Message-
 From: Tyler Longren [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, July 18, 2001 1:25 PM
 To: php-general
 Subject: [PHP] sql query successful


 I've been writing database enabled site for quite a while
 now.  One thing I have never figured out it how to determine
 if a sql query is successful.

 This works:
 if ($connection = mysql_connect(host,username,password)) {
 print Successful connection:
 }
 else {
 print No connection;
 }

 But this won't work:

 if ($sql = mysql_query(SELECT * FROM table ORDER BY rand())) {
 print SQL executed successfully.;
 }
 else {
 print SQL not executed successfully.;
 }

In what way doesn't this work?

The above code should tell you that the query was properly formed and
error-free, and was cheerfully accepted and processed by the database
server.  (You don't get much more successful than that...)

If what you're really looking for is whether there were any rows
returned by the query, then you'll want to look into the
mysql_num_rows() function.


---
Mark Roedel ([EMAIL PROTECTED])  ||  There cannot be a crisis next week.
Systems Programmer / WebMaster  ||   My schedule is already full.
 LeTourneau University  ||-- Henry Kissinger



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] sql query successful

2001-07-18 Thread Christopher Ostmo

Tyler Longren pressed the little lettered thingies in this order...

 Hello everyone,
 
 I've been writing database enabled site for quite a while now.  One thing I
 have never figured out it how to determine if a sql query is successful.
 
 This works:
 if ($connection = mysql_connect(host,username,password)) {
 print Successful connection:
 }
 else {
 print No connection;
 }
 
 But this won't work:
 
 if ($sql = mysql_query(SELECT * FROM table ORDER BY rand())) {
 print SQL executed successfully.;
 }
 else {
 print SQL not executed successfully.;
 }
 
 Can anyone tell me how I can tell if the SQL executed successfully?  Is
 there any method besides OR DIE?
 

What's wrong with or die(... ? If you get no error, the query was 
successful.  If you take your $sql = out it *should* work.  mysql_query 
returns TRUE or FALSE depending on whether or not the query 
succeeded. This isn't tested, but it should work:
if (mysql_query(SELECT * FROM table ORDER BY rand())) {
echo Success!;
} else {
echo Failure!;
}

Your statement above is checking to see if the fact that $sql is equal to 
mysql_query(SELECT * FROM table ORDER BY rand()) is TRUE, but 
you're using an assignment operator (=) and not a comparison operator 
(==), so it should always return FALSE. (Can you use an assignment 
operator in an if() statement?)


Christopher Ostmo
a.k.a. [EMAIL PROTECTED]
AppIdeas.com
Innovative Application Ideas
Meeting cutting edge dynamic
web site needs since the 
dawn of Internet time (1995)

Business Applications:
http://www.AppIdeas.com/

Open Source Applications:
http://open.AppIdeas.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] sql query successful

2001-07-18 Thread Mark Roedel

 -Original Message-
 From: Christopher Ostmo [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, July 18, 2001 2:43 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] sql query successful
 
 
 Your statement above is checking to see if the fact that $sql 
 is equal to mysql_query(SELECT * FROM table ORDER BY rand())
 is TRUE, but you're using an assignment operator (=) and not a
 comparison operator (==), so it should always return FALSE. (Can
 you use an assignment operator in an if() statement?)

Actually, you can.  (See
http://www.php.net/manual/en/language.operators.assignment.php)

An assignment operation will return the value that was assigned.

Thus, if we have

if ($sql = mysql_query($query_string))

and the mysql_query call returns a non-false value, the entire
expression will evaluate to true.


---
Mark Roedel   | The most overlooked advantage to owning a
Systems Programmer|  computer is that if they foul up there's no
LeTourneau University |  law against whacking them around a little.
Longview, Texas, USA  |  -- Owen Porterfield 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] sql query successful

2001-07-18 Thread Christopher Ostmo

Tyler Longren pressed the little lettered thingies in this order...

 What about when DELETING from a table???  It always returns true.
 Example...the highest ID in this table is 10:
 
 ?
 if ($connection = mysql_connect(localhost,mysql,mysql)) {
 print Connection established;
 $db = mysql_select_db(aanr, $connection);
 if ($sql = mysql_query(DELETE FROM bullitens WHERE id='1212')) {
 print Successful;
 }
 else {
 print Not successful.;
 }
 }
 else {
 print Connection NOT established.;
 }
 ?
 
 We try to delete the bulliten with id of 1212, but there is not bulliten
 with that ID, and it says Successful.
 
 I know I could use mysql_affected_rows(), but why doesn't this work???
 

mysql_query() is not intended to be used as a means by which you can 
check the number of rows that are affected.  If it returned FALSE severy 
time your query was empty, you would have to rewrite all of your of code 
to eliminate errors.  It only checks for the validity of your query.

To ask why this doesn't work would be the same thing as asking why 
you can type this query from the command-line mysql client and the 
query succeeds without an error. It succeeds and says 0 rows.

It's a valid query with zero results.  A FALSE return from a programming 
function indicates an error condition, not the lack of results.

Christopher Ostmo
a.k.a. [EMAIL PROTECTED]
AppIdeas.com
Innovative Application Ideas
Meeting cutting edge dynamic
web site needs since the 
dawn of Internet time (1995)

For a good time,
http://www.AppIdeas.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] sql query successful

2001-07-18 Thread Christopher Ostmo

Mark Roedel pressed the little lettered thingies in this order...

  -Original Message-
  From: Christopher Ostmo [mailto:[EMAIL PROTECTED]]
  Sent: Wednesday, July 18, 2001 2:43 PM
  To: [EMAIL PROTECTED]
  Subject: Re: [PHP] sql query successful
  
  
  Your statement above is checking to see if the fact that $sql 
  is equal to mysql_query(SELECT * FROM table ORDER BY rand())
  is TRUE, but you're using an assignment operator (=) and not a
  comparison operator (==), so it should always return FALSE. (Can
  you use an assignment operator in an if() statement?)
 
 Actually, you can.  (See
 http://www.php.net/manual/en/language.operators.assignment.php)
 
 An assignment operation will return the value that was assigned.
 
 Thus, if we have
 
   if ($sql = mysql_query($query_string))
 
 and the mysql_query call returns a non-false value, the entire
 expression will evaluate to true.
 

Thank you.  I've never tried to assign within an if() clause.

You learn 13 or 14 new things every day...

Christopher Ostmo
a.k.a. [EMAIL PROTECTED]
AppIdeas.com
Innovative Application Ideas
Meeting cutting edge dynamic
web site needs since the 
dawn of Internet time (1995)

For a good time,
http://www.AppIdeas.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] sql query successful

2001-07-18 Thread Mark Roedel

 -Original Message-
 From: Tyler Longren [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, July 18, 2001 1:36 PM
 To: Mark Roedel; php-general
 Subject: Re: [PHP] sql query successful
 
 
 What about when DELETING from a table???  It always returns true.
 Example...the highest ID in this table is 10:
 
 ?
 if ($connection = mysql_connect(localhost,mysql,mysql)) {
 print Connection established;
 $db = mysql_select_db(aanr, $connection);
 if ($sql = mysql_query(DELETE FROM bullitens WHERE 
 id='1212')) {
 print Successful;
 }
 else {
 print Not successful.;
 }
 }
 else {
 print Connection NOT established.;
 }
 ?
 
 We try to delete the bulliten with id of 1212, but there is 
 not bulliten with that ID, and it says Successful.

 I know I could use mysql_affected_rows(), but why doesn't this work???

Because the query itself is still valid.  No syntax errors, no
connection errors, etc.  The fact that there wasn't any data that needed
to be deleted doesn't affect the validity of the query; just the results
of it.

Basically, what it boils down to is that There wasn't anything for me
to do is not an error.  It's a perfectly valid result.  :)


---
Mark Roedel ([EMAIL PROTECTED])  ||  There cannot be a crisis next week.
Systems Programmer / WebMaster  ||   My schedule is already full.
 LeTourneau University  ||-- Henry Kissinger


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] SQL Query time?

2001-05-02 Thread Anuradha Ratnaweera


I wonder if using microtime() gives _actual_ time spent for the query
while explain gives _processor_ time.

Anuradha

On Thu, 26 Apr 2001, Maxim Maletsky wrote:

 what about microtime() ?
 
 you can do it your self:
 
 $start = microtime();
 mysql_query()...
 $stop = microtime();
 
 $token = round($stop-$start, 3);
 echo Query took $token seconds;
 
 I mean this is not as precise as SQL would do itself, but will work
 approximately.
 
 
 Sincerely, 
 
  Maxim Maletsky
  Founder, Chief Developer
  PHPBeginner.com (Where PHP Begins)
  [EMAIL PROTECTED]
  www.phpbeginner.com
 
 
 
 
 -Original Message-
 From: James, Yz [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, April 26, 2001 5:17 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] SQL Query time?
 
 
 Hi all,
 
 I have seen a few pages that echo the time it's taken to execute an SQL
 query, like The results in the database were returned in 0.3 seconds.
 Anyone know if there's a built in function to display this, and if there is,
 what it is?  My more-than-useless-ISP seems to have taken an aversion to
 allowing me to surf tonight without disconnecting me.
 
 Thanks.
 James.
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] SQL Query time?

2001-04-25 Thread James, Yz

Hi all,

I have seen a few pages that echo the time it's taken to execute an SQL
query, like The results in the database were returned in 0.3 seconds.
Anyone know if there's a built in function to display this, and if there is,
what it is?  My more-than-useless-ISP seems to have taken an aversion to
allowing me to surf tonight without disconnecting me.

Thanks.
James.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query time?

2001-04-25 Thread Martín Marqués

On Mié 25 Abr 2001 23:17, James, Yz wrote:
 Hi all,

 I have seen a few pages that echo the time it's taken to execute an SQL
 query, like The results in the database were returned in 0.3 seconds.
 Anyone know if there's a built in function to display this, and if there
 is, what it is?  My more-than-useless-ISP seems to have taken an aversion
 to allowing me to surf tonight without disconnecting me.

That depends on the SQL server you are using (and I'm not talking about M$SQL 
Server! :-) ).
In postgreSQL you do that with an EXPLAIN query, but the results are given 
throught the warning output, and there is no function to grab it. But it 
wouldn't be difficult to build it. :-)

Saludos... :-)

-- 
El mejor sistema operativo es aquel que te da de comer.
Cuida tu dieta.
-
Martin Marques  |[EMAIL PROTECTED]
Programador, Administrador  |   Centro de Telematica
   Universidad Nacional
del Litoral
-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query time?

2001-04-25 Thread Steve Lawson

Sup,
Adding explain before the select query will show you how long it will
take, along with some other info, but it won't actually give you the
results.

I use a the function microtime (http://php.net/microtime) to figure
execution time.  When called, microtime will return a string with
miliiseconds then seconds seperated by a space.  So you have to do something
like this...

function sn_Msecs()
{
   $mt = microtime();
   $mt = explode(  , $mt);

   return ($mt[1] + $mt[0]);
}

That will return seconds.milliseconds or something like 13123141.1231, it is
not in proper math form.

 Just call it before a block of code or query, then call it after and
subtract the second one from the first.

SL.


- Original Message -
From: James, Yz [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, April 25, 2001 2:17 PM
Subject: [PHP] SQL Query time?


 Hi all,

 I have seen a few pages that echo the time it's taken to execute an SQL
 query, like The results in the database were returned in 0.3 seconds.
 Anyone know if there's a built in function to display this, and if there
is,
 what it is?  My more-than-useless-ISP seems to have taken an aversion to
 allowing me to surf tonight without disconnecting me.

 Thanks.
 James.



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] SQL Query syntax error... Help?

2001-04-15 Thread Scott VanCaster

I've only been trying to learn this stuff for a few days and thought I was
on a roll, but now have run into a problem I don't get at all.  In my script
I have the following sql query and am receiving the following error when it
executes "You have an error in your SQL syntax near '' at line 1."

Any idea what my problem is?  I removed the WHERE id=$id and it works, but
updates every record of course :(

I'm lost here.  Thanks for any help.

$sql ="UPDATE members SET ".
  "name='$name', ".
  "email='$email', ".
  "icq='$icq', ".
  "password='$password', ".
  "loginid='$loginid', ".
  "countryid='$countryid', ".
  "gtlogin='$gtlogin', ".
  "gtpass='$gtpass', ".
  "swirvelogin='$swirvelogin', ".
  "swirvepass='$swirvepass' ".
  "WHERE id=$id" ;



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Augusto Cesar Castoldi

What do you have in the id variable?

It's contents can be the problem.

regards,

Augusto Cesar Castoldi

On Sun, 15 Apr 2001, Scott VanCaster wrote:

 I've only been trying to learn this stuff for a few days and thought I was
 on a roll, but now have run into a problem I don't get at all.  In my script
 I have the following sql query and am receiving the following error when it
 executes "You have an error in your SQL syntax near '' at line 1."

 Any idea what my problem is?  I removed the WHERE id=$id and it works, but
 updates every record of course :(

 I'm lost here.  Thanks for any help.

 $sql ="UPDATE members SET ".
   "name='$name', ".
   "email='$email', ".
   "icq='$icq', ".
   "password='$password', ".
   "loginid='$loginid', ".
   "countryid='$countryid', ".
   "gtlogin='$gtlogin', ".
   "gtpass='$gtpass', ".
   "swirvelogin='$swirvelogin', ".
   "swirvepass='$swirvepass' ".
   "WHERE id=$id" ;



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Scott VanCaster

id is the primary key for the table.  If I add echo ($id); before the query
it echos a 15, which is correct.  Well, it's the right id for the test
person I'm logged into the site as anyway.  I'm missing something here :)


"Augusto Cesar Castoldi" [EMAIL PROTECTED] wrote in message
Pine.A41.4.32.0104151924060.11846-10@marte">news:Pine.A41.4.32.0104151924060.11846-10@marte...
 What do you have in the id variable?

 It's contents can be the problem.

 regards,

 Augusto Cesar Castoldi

 On Sun, 15 Apr 2001, Scott VanCaster wrote:

  I've only been trying to learn this stuff for a few days and thought I
was
  on a roll, but now have run into a problem I don't get at all.  In my
script
  I have the following sql query and am receiving the following error when
it
  executes "You have an error in your SQL syntax near '' at line 1."
 
  Any idea what my problem is?  I removed the WHERE id=$id and it works,
but
  updates every record of course :(
 
  I'm lost here.  Thanks for any help.
 
  $sql ="UPDATE members SET ".
"name='$name', ".
"email='$email', ".
"icq='$icq', ".
"password='$password', ".
"loginid='$loginid', ".
"countryid='$countryid', ".
"gtlogin='$gtlogin', ".
"gtpass='$gtpass', ".
"swirvelogin='$swirvelogin', ".
"swirvepass='$swirvepass' ".
"WHERE id=$id" ;
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Scott VanCaster

I "think" I tried that.  Let me go try that again to be sure.

Oh, and what's STDOUT ?  I'm just getting started here and haven't even seen
that yet :)

I can't believe how fast the responses are either.  Thanks to all for
helping others out so quickly :)

"Felix Kronlage" [EMAIL PROTECTED] wrote in message
20010415232649.A11407@mad">news:20010415232649.A11407@mad...
 On Sun, Apr 15, 2001 at 04:20:07PM -0500, Scott VanCaster wrote:

  Any idea what my problem is?  I removed the WHERE id=$id and it works,
but
  updates every record of course :(

 Have you tried putting the $id in quotes too?

 | WHERE = '$id'

 if that doesn't help, print the sql-statement to STDOUT (e.g. probably to
the
 browser) and take a look at it, that way it is easier to see where the
 error is.

 -fkr
 --
 gpg-fingerprint: 076E 1E87 3E05 1C7F B1A0  8A48 0D31 9BD3 D9AC 74D0
   |http://www.hazardous.org/ | whois -h whois.ripe.de FKR-RIPE  |
   |all your base are belong to us  |  shame on me  | fkr@IRCnet |


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Scott VanCaster

I changed $id to '$id'

No more error, but nothing updates.  Assuming it's because with the single
quotes nothing in the table matches?

"Felix Kronlage" [EMAIL PROTECTED] wrote in message
20010415232649.A11407@mad">news:20010415232649.A11407@mad...
 On Sun, Apr 15, 2001 at 04:20:07PM -0500, Scott VanCaster wrote:

  Any idea what my problem is?  I removed the WHERE id=$id and it works,
but
  updates every record of course :(

 Have you tried putting the $id in quotes too?

 | WHERE = '$id'

 if that doesn't help, print the sql-statement to STDOUT (e.g. probably to
the
 browser) and take a look at it, that way it is easier to see where the
 error is.

 -fkr
 --
 gpg-fingerprint: 076E 1E87 3E05 1C7F B1A0  8A48 0D31 9BD3 D9AC 74D0
   |http://www.hazardous.org/ | whois -h whois.ripe.de FKR-RIPE  |
   |all your base are belong to us  |  shame on me  | fkr@IRCnet |


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Scott VanCaster

Well, I added the echo($id); back in and am just getting $id printed, so it
looks like I have another problem :(

Now to see if I can find it and figure it out.


""Scott VanCaster"" [EMAIL PROTECTED] wrote in message
9bd3pv$qbd$[EMAIL PROTECTED]">news:9bd3pv$qbd$[EMAIL PROTECTED]...
 id is the primary key for the table.  If I add echo ($id); before the
query
 it echos a 15, which is correct.  Well, it's the right id for the test
 person I'm logged into the site as anyway.  I'm missing something here :)


 "Augusto Cesar Castoldi" [EMAIL PROTECTED] wrote in message
 Pine.A41.4.32.0104151924060.11846-10@marte">news:Pine.A41.4.32.0104151924060.11846-10@marte...
  What do you have in the id variable?
 
  It's contents can be the problem.
 
  regards,
 
  Augusto Cesar Castoldi
 
  On Sun, 15 Apr 2001, Scott VanCaster wrote:
 
   I've only been trying to learn this stuff for a few days and thought I
 was
   on a roll, but now have run into a problem I don't get at all.  In my
 script
   I have the following sql query and am receiving the following error
when
 it
   executes "You have an error in your SQL syntax near '' at line 1."
  
   Any idea what my problem is?  I removed the WHERE id=$id and it works,
 but
   updates every record of course :(
  
   I'm lost here.  Thanks for any help.
  
   $sql ="UPDATE members SET ".
 "name='$name', ".
 "email='$email', ".
 "icq='$icq', ".
 "password='$password', ".
 "loginid='$loginid', ".
 "countryid='$countryid', ".
 "gtlogin='$gtlogin', ".
 "gtpass='$gtpass', ".
 "swirvelogin='$swirvelogin', ".
 "swirvepass='$swirvepass' ".
 "WHERE id=$id" ;
  
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
   To contact the list administrators, e-mail: [EMAIL PROTECTED]
et
  
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Scott VanCaster

Nevermind everyone, I'm an idiot :)

I had the case wrong.  I needed $ID, not $id  !

Thanks for the assistance though.  Nice to know ya'll are here.

Scott


""Scott VanCaster"" [EMAIL PROTECTED] wrote in message
9bd394$ikn$[EMAIL PROTECTED]">news:9bd394$ikn$[EMAIL PROTECTED]...
 I've only been trying to learn this stuff for a few days and thought I was
 on a roll, but now have run into a problem I don't get at all.  In my
script
 I have the following sql query and am receiving the following error when
it
 executes "You have an error in your SQL syntax near '' at line 1."

 Any idea what my problem is?  I removed the WHERE id=$id and it works, but
 updates every record of course :(

 I'm lost here.  Thanks for any help.

 $sql ="UPDATE members SET ".
   "name='$name', ".
   "email='$email', ".
   "icq='$icq', ".
   "password='$password', ".
   "loginid='$loginid', ".
   "countryid='$countryid', ".
   "gtlogin='$gtlogin', ".
   "gtpass='$gtpass', ".
   "swirvelogin='$swirvelogin', ".
   "swirvepass='$swirvepass' ".
   "WHERE id=$id" ;



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Chris Cocuzzo

scott,

try the entire SQL statement without single quotes around those variables.
except for when your setting the WHERE part. Try:

$sql ="UPDATE members SET ".
  "name=$name, ".
  "email=$email, ".
  "icq=$icq, ".
  "password=$password, ".
  "loginid=$loginid, ".
  "countryid=$countryid, ".
  "gtlogin=$gtlogin, ".
  "gtpass=$gtpass, ".
  "swirvelogin=$swirvelogin, ".
  "swirvepass=$swirvepass ".
  "WHERE id='$id'" ;

I could be wrong though, but just my two cents.

chris
www.variancecreations.net



-Original Message-
From: Scott VanCaster [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 15, 2001 5:20 PM
To: [EMAIL PROTECTED]
Subject: [PHP] SQL Query syntax error... Help?


I've only been trying to learn this stuff for a few days and thought I was
on a roll, but now have run into a problem I don't get at all.  In my script
I have the following sql query and am receiving the following error when it
executes "You have an error in your SQL syntax near '' at line 1."

Any idea what my problem is?  I removed the WHERE id=$id and it works, but
updates every record of course :(

I'm lost here.  Thanks for any help.

$sql ="UPDATE members SET ".
  "name='$name', ".
  "email='$email', ".
  "icq='$icq', ".
  "password='$password', ".
  "loginid='$loginid', ".
  "countryid='$countryid', ".
  "gtlogin='$gtlogin', ".
  "gtpass='$gtpass', ".
  "swirvelogin='$swirvelogin', ".
  "swirvepass='$swirvepass' ".
  "WHERE id=$id" ;



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Chris Cocuzzo

NEVERMIND! :)



-Original Message-
From: Scott VanCaster [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 15, 2001 6:05 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] SQL Query syntax error... Help?


Nevermind everyone, I'm an idiot :)

I had the case wrong.  I needed $ID, not $id  !

Thanks for the assistance though.  Nice to know ya'll are here.

Scott


""Scott VanCaster"" [EMAIL PROTECTED] wrote in message
9bd394$ikn$[EMAIL PROTECTED]">news:9bd394$ikn$[EMAIL PROTECTED]...
 I've only been trying to learn this stuff for a few days and thought I was
 on a roll, but now have run into a problem I don't get at all.  In my
script
 I have the following sql query and am receiving the following error when
it
 executes "You have an error in your SQL syntax near '' at line 1."

 Any idea what my problem is?  I removed the WHERE id=$id and it works, but
 updates every record of course :(

 I'm lost here.  Thanks for any help.

 $sql ="UPDATE members SET ".
   "name='$name', ".
   "email='$email', ".
   "icq='$icq', ".
   "password='$password', ".
   "loginid='$loginid', ".
   "countryid='$countryid', ".
   "gtlogin='$gtlogin', ".
   "gtpass='$gtpass', ".
   "swirvelogin='$swirvelogin', ".
   "swirvepass='$swirvepass' ".
   "WHERE id=$id" ;



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] SQL Query syntax error... Help?

2001-04-15 Thread Plutarck

In the future, to make things easier on yourself, when you get a query
syntax error add an "echo $sql;" line right before your query.

Almost every time I have a query problem, that solves it.


--
Plutarck
Should be working on something...
...but forgot what it was.


""Scott VanCaster"" [EMAIL PROTECTED] wrote in message
9bd394$ikn$[EMAIL PROTECTED]">news:9bd394$ikn$[EMAIL PROTECTED]...
 I've only been trying to learn this stuff for a few days and thought I was
 on a roll, but now have run into a problem I don't get at all.  In my
script
 I have the following sql query and am receiving the following error when
it
 executes "You have an error in your SQL syntax near '' at line 1."

 Any idea what my problem is?  I removed the WHERE id=$id and it works, but
 updates every record of course :(

 I'm lost here.  Thanks for any help.

 $sql ="UPDATE members SET ".
   "name='$name', ".
   "email='$email', ".
   "icq='$icq', ".
   "password='$password', ".
   "loginid='$loginid', ".
   "countryid='$countryid', ".
   "gtlogin='$gtlogin', ".
   "gtpass='$gtpass', ".
   "swirvelogin='$swirvelogin', ".
   "swirvepass='$swirvepass' ".
   "WHERE id=$id" ;



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]