You are here: Re: [PHP] Need help with array/foreach « PHP « IT news, forums, messages
Re: [PHP] Need help with array/foreach

Posted by Jochem Maas on 01/14/05 20:40

Collin Davis wrote:
> Hi,
> Long time reader, first time poster. I've been using Dreamweaver to
> generate my PHP (I know - but I'm a designer... most of this makes
> absolutely zero sense to me), but I've run into something that I know could
> be done better. If you look here: http://pastebin.com/228804 you can see
> that I have several MySQL queries. Now I know that surely these can be
> concatenated into an array or something, but I have no idea how to do that -

concatenation means sticking strings together, which is kind of what you
would do to an array if you used the join() function on it. but anyway I
grabbed this bit of code from you source file:

$db2->query("select pid,poster, ".
"date_format(posted, '%a %D %b %H:%i') as posted ".
"from pastebin where pid=".$db->f("parent_pid"));

you could do this with the sql:


$queries = array();

$queries['get_poster'] = '
select pid,poster,
date_format(posted, '%%a %%D %%b %%H:%%i') as posted
from pastebin where pid=%s';
$queries['get_poster_parents'] = '
select pid,poster,
date_format(posted, '%%a %%D %%b %%H:%%i') as posted

from pastebin where parent_pid=%s order by posted desc;"

(the double percentage signs are there for the benefit of sprintf())
the later on in the script:

$db2->query(sprintf( $queries['get_poster'],$db->f("parent_pid") ));

and

$db2->query(
sprintf( $queries['get_poster_parents'],$db->f("parent_pid")));


(sorry about the odd line wrapping)

to be honest it wasn't totally clear what you wanted to achieve (or why
- the why is often telling and will others to help with possibly
different solutions), but I hope this gives you something to go on.

> I've googled until I'm blue in the face, read tutorials about arrays and
> foreach loops but I just can't make sense of it. Any help anybody could

I feel like that everytime I try reading up on character
encoding/transcoding - my brain hurts and I feel the need to scream!



> give me would be greatly appreciated.
> Thanks,
> Collin Davis
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация