php-general Digest 3 Nov 2012 09:32:47 -0000 Issue 8029

Topics (messages 319650 through 319657):

Re: Creating an Advanced Form
        319650 by: Jay Blanchard
        319651 by: Matt Graham
        319655 by: tamouse mailing lists
        319656 by: Robert Stone

Differentiate Line breaks and Paragraphs
        319652 by: Simon Dániel
        319653 by: Stuart Dallas

Question
        319654 by: Silvio Siefke

Re: Multithreading for OOP PHP
        319657 by: Joe Watkins

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message --- [snip] Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11014928/public_html/search.php on line 261[/snip]

It would appear that your query is not returning a result. Echo out the query and try running it in MySQL to see what is happening.
--- End Message ---
--- Begin Message ---
Jonathan Davies <jonny1dav...@btinternet.com> wrote:
> I am attempting to create an advanced form with 9 different search
> fields.  I am [concatenating a bunch of bits together] so I don't
> have to [create] over 300,000 IF statements.
> mysql_fetch_assoc(): supplied argument is not a valid MySQL
> result resource on line 261
> I cannot seem to hit the nail on the [head] to why it [doesn't] work. 
[snip code]

When you see that particular error message, you should print the query you're
executing, or log it, or something.  If you have more than 1 field set, it
looks like you'd be doing something like:

$q =  "select stuff1 ... order by blah1";
$q += "select stuff2 ... order by blah2";

...which gives you "select stuff1 ... order by blah1select stuff2" , which is
bad SQL syntax, which explains the error you're getting.  I am not sure
whether putting another space at the end of each substring would help, but
that's the first thing I'd try.

(I'm sure other people will say "OMGPANIC procedural code!  OH NOES, using
mysql_* functions!  Unclean!  Unclean!  AAAAAH!", so be prepared for that
too....)

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see


--- End Message ---
--- Begin Message ---
I'm sorry. This code just makes me weep.

Let's just take a quick look at this line here:

> $rsSearch = mysql_query($sqlSearch);

You have not supplied a database connection, so mysql_query will fail.
Further, you have not even checked the result to *see* if it failed.

Once you fix those things, try echoing out the $sqlSearch string to
see how that ends up looking. You may be surprised.

Other than that, there is so much wrong here I don't quite know where to begin.

--- End Message ---
--- Begin Message ---
Hi Jonathan,

Haven't used MySql for ages. More used to Oracle and PostgreSql.
Your table nmc_cd contains foreign keys pointing to nmc_category and 
nmc_publisher. Create a view containing all the data from those three tables 
using implicit joins as the data in table nmc_cd should NOT contain any 
"dangling" foreign keys. (You can always write a test routine to verify the 
cleaniless of your data). 

Thus you have a single query "SELECT * FROM my_nmc_view WHERE ($x IS NOT NULL 
AND $x = some colum name in the view) AND ($y IS NOT NULL . . . etc.
You can append an ORDER BY clause at the end reflecting the desired display 
sequence.
If all of your search criteria is null, then the select should return every row 
in the view.


I don't understand code such as  "  if($searchCDID=1){  ". Comparing for 
equality requires "==" or "===". How does this work if the user enters "345" 
for example?

Apropos other comments, this select statement ought to be in the controller (or 
action controller) depending on how your application is structured. 


Hope this helps.
Cheers,
Rob

--- End Message ---
--- Begin Message ---
Hi,

Is there a way to make difference between line breaks and paragraphs, when
I save a text to a database from a user input? The new line characters (\n,
\r) are not too consequent to determine when did the user only one new line
or more new lines. (Some clients make only \n or \r, some others make \n\r
or \r\n, etc.)

What I would like to do is, to format the given text into paragraphs (with
<p> tag), not just insert a batch of break line (<br />) tags.
Of course, I want to retain <br /> tags as well, in case of the user wrote
only one new line character.

--- End Message ---
--- Begin Message ---
On 2 Nov 2012, at 19:32, Simon Dániel <simondan...@gmail.com> wrote:

> Is there a way to make difference between line breaks and paragraphs, when
> I save a text to a database from a user input? The new line characters (\n,
> \r) are not too consequent to determine when did the user only one new line
> or more new lines. (Some clients make only \n or \r, some others make \n\r
> or \r\n, etc.)
> 
> What I would like to do is, to format the given text into paragraphs (with
> <p> tag), not just insert a batch of break line (<br />) tags.
> Of course, I want to retain <br /> tags as well, in case of the user wrote
> only one new line character.


Something like this should work…

<?php
  // Let's say you have $str as the text, and
  // assuming that all line breaks are \r\n and
  // not just \n. If not I recommend replacing
  // \r\n with \n first and removing all \r's
  // from the code below.
  $new_str = nl2br('<p>'.str_replace($str, '\r\n\r\n', '</p><p>').'</p>');
?>

Untested but that should do what you're looking for.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
Hello,

i have compile PHP 5.4.8 on my Debian System. I have before Version 5.4.7. 
I delete before all old Files from PHP and then run the commands:

./configure --sysconfdir=/usr/local/etc --with-pear --enable-bcmath 
--with-bz2=/usr --disable-calendar --enable-ctype --without-curl 
--without-curlwrappers --enable-dom --without-enchant --enable-exif
--enable-fileinfo --enable-filter --disable-ftp --with-gettext=/usr 
--without-gmp --enable-hash --with-mhash=/usr --with-iconv --disable-intl 
--disable-ipv6 --enable-json --without-kerberos --enable-libxml 
--with-libxml-dir=/usr --enable-mbstring --with-mcrypt=/usr --without-mssql 
--with-onig=/usr --with-openssl=/usr --with-openssl-dir=/usr --disable-pcntl 
--enable-phar --enable-pdo --without-pgsql --enable-posix --with-pspell=/usr 
--without-recode --enable-simplexml --disable-shmop --without-snmp 
--enable-soap 
--enable-sockets --with-sqlite3=/usr --without-sybase-ct --disable-sysvmsg 
--disable-sysvsem --disable-sysvshm --without-tidy --enable-tokenizer 
--disable-wddx --enable-xml --disable-xmlreader --disable-xmlwriter 
--without-xmlrpc --without-xsl --enable-zip --with-zlib=/usr --disable-debug 
--without-cdb --disable-flatfile --disable-inifile --without-qdbm 
--with-freetype-dir=/usr --with-t1lib=/usr --disable-gd-jis-conv 
--with-jpeg-dir=/usr --with-png-dir=/usr --without-xpm-dir --with-gd 
--with-imap=/usr --with-imap-ssl=/usr --with-mysql=/usr 
--with-mysqli=/usr/bin/mysql_config --without-pdo-dblib --with-pdo-mysql=/usr 
--without-pdo-pgsql --with-pdo-sqlite=/usr --without-pdo-odbc 
--with-readline=/usr 
--without-libedit --without-mm --with-pcre-regex=/usr --with-pcre-dir=/usr 
--disable-embed --disable-cli --disable-cgi --enable-fpm --without-apxs2 
--with-kerberos

make -j3 ; make install

But when i look in the directorys i miss pear and the php-cgi.

root:/usr/local/src/php-5.4.8# ls /usr/local/bin
php-config  phpize

root:/usr/local/src/php-5.4.8# ls /usr/local/sbin
php-fpm

Must under bin not be php-cgi and pear, or is my thinking wrong?


Thank you for help and Greetings
Silvio

--- End Message ---
--- Begin Message ---
On 31/10/2012 13:46, Alex Nikitin wrote:
Hey guys (and/or gals),

I have heard this question entirely too many times, I think at some point
Rasmus just stopped responding to it. The real reason that PHP is not
threaded has nothing to do with PHP internal or extension thread safety,
the reason is more to the extent that it doesn't make sense to add
threading to PHP, it will only increase code and model complexity and
create more points of failure, but again the reason is not this, the reason
is that it doesn't make sense in PHP's native environment to add threading
in the first place. Natively PHP is summoned by a web server, yes you can
call PHP in CLI, but that's not it's point market, PHP is first and
foremost a server-side language for the web and it is ran by a web server
such as Apache or Nginx or IIS(i wouldn't know why you would use IIS, but
it could be). All of these web servers (maybe with exception of IIS, i
wouldn't know) work pretty much on the same principal, you have the main
process that spawns a bunch of worker threads (this is adjustable in
configuration, but is typically 1 per cpu thread). These threads are what
actually process the requests and call PHP, meaning that if multiple
threads are processing multiple requests, multiple instances of PHP will be
called. This is why adding threading to PHP makes absolutely no sense, why
would you spawn threads in something that is already being called by a
thread? Don't get me wrong, threads spawning other threads is a solution,
but it is a solution on massively parallel architectures, such as the
GPGPUs that can handle over a thousand threads, and it is a solution for an
entirely different problem, namely costly conditional statements; PHP on
the other hand runs on a general purpose processor that already cache
thrashes and runs into issues with instruction pipelines in parallel
execution, adding more threads to it would do nothing for performance (or
make it worse), make for more complex code and introduce new issues, like
for example how do you test threaded code, debugging, messaging, etc, which
will introduce new places where php apps fail, new security concerns, etc,
and I think we are far from having current issues fixed...

Want to parallelize your PHP execution? Learn to love curl_multi :)

In this case, fix the program, not the programming language. Just my $0.02


-- Alex
--
The trouble with programmers is that you can never tell what a programmer
is doing until it’s too late.  ~Seymour Cray

You're very wrong.

Adding threading doesn't increase complexity at all, the fact is, that people are coming up with horrible ways to execute what they should be executing in threads. It's 2012, my mobile phone has a dual core processor !! All that adding threading does is allow those people bending over backwards - using horrible hacks just to do two things at once - to do things properly.
--- End Message ---

Reply via email to