RE: [PHP-DB] Displaying results from a query properly.

2006-03-27 Thread Ford, Mike
On 24 March 2006 16:40, Alex Major wrote:

 Thanks, works like a charm (had to make is -2 instead of -1
 as it added a
 space after each result). Hadn't thought of something so simple.
 
 On 24/3/06 16:22, Bastien Koert [EMAIL PROTECTED] wrote:
 
  Build it up as a string and remove the trailing comma at the end of
  the loop 
  
  do { $sHTML .= ''.$administrators['username'].', ';}
  while ($administrators = mysql_fetch_assoc($administrators_result))
  
  $sHTML = substr($sHTML, 0, strlen($sHTML)-1);

You don't need a strlen() call here, as substr understands count from the 
right notation:

   $sHTML = substr($sHTML, 0, -1);

... or, with Alex's correction:

   $sHTML = substr($sHTML, 0, -2);

Cheers!

Mike

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


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



[PHP-DB] MySQLi Prepared Statements

2006-03-27 Thread Rob Hamilton
Hi

I am current trying to migrate an existing system using MySQLi to use 
PDO and I have a quick question with regards to Prepared Statements. 
Essentially I'd like to replicate the Prepared Statement functionality 
of PDO using MySQLi so that I can gradually update all the required 
pages to use similar function calls, and then swap everything over in 
one go rather than spending ages on a big rewrite.

Using PDO you can pass parameters as an array which are bound to the 
query. Something like:

$stmt = $pdo-prepare(SELECT * FROM Blah WHERE foo = ?);
$params = array(SomeValue);
$stmt-execute($params)

The PDO function execute takes 1 parameter which is an array.

There are similar functions in MySQLi such as bind_param and bind_result 
of which one of the parameters is of type mixed var1 [, mixed ...].

Is it possible to construct an array of this type and pass it to these 
functions, and if so how?

I know is's possible to call these functions with something like:

$stmt = $db-prepare(SELECT * FROM Blah WHERE foo = ?);
$paramTypes = s;
$params = array(SomeValue);
$stmt-bind_param($paramTypes, $params[0]);

But it seems you cannot pass the array itself using the '' operator.

Cheers

Rob Hamilton

-- 
___
Play 100s of games for FREE! http://games.mail.com/

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



Re: [PHP-DB] Displaying results from a query properly.

2006-03-27 Thread Greg Skouby
On Fri, Mar 24, 2006 at 04:19:10PM +, Alex Major wrote:
 Hi there. 
 This isn't a major problem, more of a matter of aesthetics.
 Basically, I have a query which pulls a list of usernames from the database
 (based on their user level).
 
 These users should then listed in this fashion.
 
 Administrators: allydm, alex, mike, dave
 Moderators: big 'd', frank, william
 
 However, the loop that I have returns the results like this...
 
 Administrators: allydm, alex, mike, dave,
 Moderators: big 'd', frank, william,


As an alternative to what the others have said you could use trim() also. 
Specifically the second, and optional, parameter.

http://www.us2.php.net/trim


--Greg

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



[PHP-DB] Session don't store after header(Location: ...)

2006-03-27 Thread Giacomo

Hi everybody, I have a problem with mysql session handler and redirect.

My situation:
- mysql session handler
- one page is posted to another page, that saves a session variable
and redirect to the first page again.

If I do the redirect the variable is not properly setted, otherwise it's
all ok.

My PHP version is 4.3.10-16

They said me I have to use cookies, but I use this.

I use this code before starting session:
@ini_set('session.use_cookies', true);
@ini_set('session.use_only_cookies', false);
@ini_set('url_rewriter.tags', '');
@ini_set('arg_separator.output', 'amp;');

Can you help me?

bye and thanks in advance

--
Giacomo

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



Re: [PHP-DB] Session don't store after header(Location: ...)

2006-03-27 Thread Philip Hallstrom

Hi everybody, I have a problem with mysql session handler and redirect.

My situation:
- mysql session handler
- one page is posted to another page, that saves a session variable
and redirect to the first page again.

If I do the redirect the variable is not properly setted, otherwise it's
all ok.

My PHP version is 4.3.10-16

They said me I have to use cookies, but I use this.

I use this code before starting session:
@ini_set('session.use_cookies', true);
@ini_set('session.use_only_cookies', false);
@ini_set('url_rewriter.tags', '');
@ini_set('arg_separator.output', 'amp;');

Can you help me?


Don't use Header(Location:...).  Instead spit back very minimal 
javascript that does something like:


script
document.location.href = '.';
/script

That way the cookies that get sent back in the header will take affect.

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



Re: [PHP-DB] Session don't store after header(Location: ...)

2006-03-27 Thread Giacomo

Philip Hallstrom ha scritto:
Don't use Header(Location:...).  Instead spit back very minimal 
javascript that does something like:


script
document.location.href = '.';
/script

That way the cookies that get sent back in the header will take affect.


I have to use header(Location...), cause I'm using Mojavi 
(http://www.mojavi.org/), an MVC framework.


Can I set cookie before calling header(Location) command?

Giacomo

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



Re: [PHP-DB] Session don't store after header(Location: ...)

2006-03-27 Thread Philip Hallstrom

Philip Hallstrom ha scritto:
Don't use Header(Location:...).  Instead spit back very minimal 
javascript that does something like:


script
document.location.href = '.';
/script

That way the cookies that get sent back in the header will take affect.


I have to use header(Location...), cause I'm using Mojavi 
(http://www.mojavi.org/), an MVC framework.


Can I set cookie before calling header(Location) command?


Don't know.  All I know is that whenever I've tried to use the Location 
header while setting a cookie, it never seems to take.


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



[PHP-DB] if() and else() help needed

2006-03-27 Thread JeRRy
Hi,
   
  I'll admit it, this is damned messy.  But I want to learn from the list in 
how to sort it out.  Than for future refrence I will know...
   
  Now I am running 2 different queries/statements here completely seperate. I 
have made the nickname field in the database UNIQUE.  So than when I have 
this sort of query setup no matter what their will only be one nickname entry 
for that user.  So when people update their profile a new nickname is not 
inserted but it is updated.  But I want it all in one PHP call.  How do I do 
this?
   
  Here is the code:
   
  ?
   if ($REQUEST_METHOD == POST) {
  $usr =  . $mysql_user . ;
$pwd =  . $mysql_password . ;
$db =  . $mysql_database . ;
$host =  . $mysql_hostname . ;
  $cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
  
// NOTE that form fields automatically become variables
$sql = update round . $round_number .  SET 
game1='$game1',game2='$game2',game3='$game3',game4='$game4',game5='$game5',game6='$game6',game7='$game7',game8='$game8',misc='y'
 
WHERE username='$username';
mysql_query($sql);
echo(Your tips have been 
savedbrbr$game1br$game2br$game3br$game4br$game5br$game6br$game7br$game8br.);
}
  else {echo(Ooops, something bad happened!  Please try again shortly.);}
?
  ?
   if ($REQUEST_METHOD == POST) {
  $usr =  . $mysql_user . ;
$pwd =  . $mysql_password . ;
$db =  . $mysql_database . ;
$host =  . $mysql_hostname . ;
  $cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
  
// NOTE that form fields automatically become variables
$sql = insert into round . $round_number .  SET 
game1='$game1',game2='$game2',game3='$game3',game4='$game4',game5='$game5',game6='$game6',game7='$game7',game8='$game8',misc='y',username='$username';
mysql_query($sql);
echo( );
}
  else {echo(Ooops, something bad happened!  Please try again shortly.);}
?

  As you can see 2 PHP calls.  What I want is to have it all in one PHP call.  
On the update one I deleted the echo statement text.  I want the insert one to 
have the text that appears and the update text output to say your tips have 
been updated...
   
  Of course if the DB is down or something output an error to try again like 
already in the else() statements.
   
  The help would be great.
   
  Thanks!
   
  J


Re: [PHP-DB] if() and else() help needed

2006-03-27 Thread Chris

JeRRy wrote:

Hi,
   
  I'll admit it, this is damned messy.  But I want to learn from the list in how to sort it out.  Than for future refrence I will know...
   
  Now I am running 2 different queries/statements here completely seperate. I have made the nickname field in the database UNIQUE.  So than when I have this sort of query setup no matter what their will only be one nickname entry for that user.  So when people update their profile a new nickname is not inserted but it is updated.  But I want it all in one PHP call.  How do I do this?


How are you differentiating between the statements?

eg they are logged in, or you check with a database query or  ?

You could do something like this:

// check for $_GET['tipid'] - if it's there, we're updating our tips.
// if it's not, then we're adding new tips.
if (isset($_GET['tipid'])) {
  $query = UPDATE  ..
  $success_message = Your tips have been updated;
} else {
  $query = INSERT INTO  .
  $success_message = Your tips have been saved;
}

$result = mysql_query($query);
if ($result) {
  echo $success_message;
} else {
  echo Problem!!br/;
}


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP-DB] if() and else() help needed

2006-03-27 Thread JeRRy
Hi,
   
  Yes the user is logged in.  The system knows who is tipping by their nickname 
and unique id system.  
   
  So if I put the update query in the else statement would this be the easy fix?
   
  I use something like a field called tipped in the table, so if they have 
tipped it goes to y and if never tipped it's blank.  I think it should show 
that in the query. Cant remember, I did the scripts 2 or 3 years ago.  Just 
want to tidy it up.
   
  J

Chris [EMAIL PROTECTED] wrote:
  JeRRy wrote:
 Hi,
 
 I'll admit it, this is damned messy. But I want to learn from the list in how 
 to sort it out. Than for future refrence I will know...
 
 Now I am running 2 different queries/statements here completely seperate. I 
 have made the nickname field in the database UNIQUE. So than when I have 
 this sort of query setup no matter what their will only be one nickname 
 entry for that user. So when people update their profile a new nickname is 
 not inserted but it is updated. But I want it all in one PHP call. How do I 
 do this?

How are you differentiating between the statements?

eg they are logged in, or you check with a database query or  ?

You could do something like this:

// check for $_GET['tipid'] - if it's there, we're updating our tips.
// if it's not, then we're adding new tips.
if (isset($_GET['tipid'])) {
$query = UPDATE  ..
$success_message = Your tips have been updated;
} else {
$query = INSERT INTO  .
$success_message = Your tips have been saved;
}

$result = mysql_query($query);
if ($result) {
echo $success_message;
} else {
echo Problem!!
;
}


-- 
Postgresql  php tutorials
http://www.designmagick.com/



Re: [PHP-DB] if() and else() help needed

2006-03-27 Thread Chris

JeRRy wrote:

Hi,
 
Yes the user is logged in.  The system knows who is tipping by their 
nickname and unique id system. 
 
So if I put the update query in the else statement would this be the 
easy fix?


Don't know - I was offering a suggestion only.

Without the full code we can't really help much (I doubt anyone will 
want the full code to help you clean it up, sorry).


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP-DB] MySQLi Prepared Statements

2006-03-27 Thread Georg Richter
Am Mo, den 27.03.2006 schrieb Rob Hamilton um 19:37:

Hello Rob,

 Is it possible to construct an array of this type and pass it to these 
 functions, and if so how?

For such cases you should use call_user_func_array.

/Georg

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



[PHP-DB] Using OR in a SELECT statement

2006-03-27 Thread Arno Kuhl
Newbie MySQL question...

I have a situation where if I don't have a custom value then I must use the
default value. There will always be a default value but there may also be a
custom value.

I could do this with:

select value where id and custom condition
if (EOF) {
  select value where id and default condition
  if (EOF) {
// no value found for this id - error, return false
  }
}
// return value


If I change this to:

select value where id and (custom condition or default condition)

... will I always get the custom value if there is one, or do I have to have
2 selects to be sure that I always get the custom value if there is one? IE
does MySQL consistently read and process the OR statement from left to right
or does it change depending on what's most optimal?

Cheers
Arno

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